Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

doc: suggestion: clarify how much structs should live #2253

Open
cmarcelo opened this issue Jul 18, 2016 · 0 comments
Open

doc: suggestion: clarify how much structs should live #2253

cmarcelo opened this issue Jul 18, 2016 · 0 comments
Milestone

Comments

@cmarcelo
Copy link
Contributor

I suggest the documentation makes explicitly clear what a functions expects from a struct we are passing it: does it expect the parameter and its contents to be valid after the function returns? will it take ownership?

Looking at the implementation is not always safe, because since it's not documented, a different implementation could be made that change my assumption. It's important this is documented at the level of Soletta API.

Two examples I've stumbled upon recently:

  1. http://solettaproject.github.io/docs/c-api/group__HTTP__CLIENT.html#ga8cd4dc21acf75f83d251cf4865961e2a

The documentation for sol_http_client_request() doesn't say whether it will be done with params (and its contents) after the function returns or not. On one hand the example just uses it in the stack, on the other hand there's a way to "copy strings when adding params", which make me confused what I can and can't do.

  1. http://solettaproject.github.io/docs/c-api/group__GPIO.html#gaf420d923e534968d329166aecef7ea9a

The documentation for sol_gpio_open() doesn't say whether it holds a reference to sol_gpio_config or not. Can I change the callback inside the config to something else? Does it copy the data pointer?

If there's a general way Soletta handles this (e.g. "function always use/copy what's needed before returning"), I still think is still relevant to make clear in the local function documentation. When not actively working on the API, we usually go for the documentation of the function we want to use and start from there. Having that information handy saves time.

This is a spin off from my comment here: #2249 (comment)

Side note: by far, most of my questions when reading the documentation were like the above. I wasn't sure whether was OK to create some parameter struct on the stack or not.

@bdilly bdilly added this to the v2 milestone Jul 19, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants