{"action":"created","issue":{"url":"https://api.github.com/repos/ARMmbed/yotta/issues/309","labels_url":"https://api.github.com/repos/ARMmbed/yotta/issues/309/labels{/name}","comments_url":"https://api.github.com/repos/ARMmbed/yotta/issues/309/comments","events_url":"https://api.github.com/repos/ARMmbed/yotta/issues/309/events","html_url":"https://github.com/ARMmbed/yotta/issues/309","id":94769851,"number":309,"title":"module initialisation functions","user":{"login":"autopulated","id":3456211,"avatar_url":"https://avatars.githubusercontent.com/u/3456211?v=3","gravatar_id":"","url":"https://api.github.com/users/autopulated","html_url":"https://github.com/autopulated","followers_url":"https://api.github.com/users/autopulated/followers","following_url":"https://api.github.com/users/autopulated/following{/other_user}","gists_url":"https://api.github.com/users/autopulated/gists{/gist_id}","starred_url":"https://api.github.com/users/autopulated/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/autopulated/subscriptions","organizations_url":"https://api.github.com/users/autopulated/orgs","repos_url":"https://api.github.com/users/autopulated/repos","events_url":"https://api.github.com/users/autopulated/events{/privacy}","received_events_url":"https://api.github.com/users/autopulated/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ARMmbed/yotta/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-07-13T17:23:21Z","updated_at":"2015-10-23T09:28:03Z","closed_at":null,"body":"yotta should provide a way for each module to have an initialisation function called.\r\n\r\npreferred method:\r\n\r\n  * `__yotta_module_init` or `__yotta_module_<modulename>_init` which you add  `__attribute__((constructor))` to, (toolchains possibly provide a nice abstraction for this attribute). when creating your library yotta adds the right -Wl,-u etc. options to pull in this symbol if it's undefined, and to suppress errors if the symbol isn't defined.\r\n\r\nI've been experimenting, but haven't figured out if this is uniformly possibly yet.\r\n\r\nIf the preferred method isn't possible, other implementations might include:\r\n\r\n  2. add method name(s) to module.json that you must have defined\r\n  3. instead of using the constructor attribute and c library startup code to run the init function, a yotta-init module could collect them all with custom CMake, and provide a idempotent initialisation API that any module can call to ensure initialisers have been called.\r\n  4. system libraries (like mbed) that define startup code may hide the use of this initialisation library from the user by calling it at startup.\r\n\r\nPreferably whatever mechanism is used to call the init function should support calling de-init functions (at least in theory), so that the possibility of dynamically loading and unloading yotta modules is not precluded.\r\n\r\ncc @bremoran @hugovincent \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ARMmbed/yotta/issues/comments/150527322","html_url":"https://github.com/ARMmbed/yotta/issues/309#issuecomment-150527322","issue_url":"https://api.github.com/repos/ARMmbed/yotta/issues/309","id":150527322,"user":{"login":"bremoran","id":2636227,"avatar_url":"https://avatars.githubusercontent.com/u/2636227?v=3","gravatar_id":"","url":"https://api.github.com/users/bremoran","html_url":"https://github.com/bremoran","followers_url":"https://api.github.com/users/bremoran/followers","following_url":"https://api.github.com/users/bremoran/following{/other_user}","gists_url":"https://api.github.com/users/bremoran/gists{/gist_id}","starred_url":"https://api.github.com/users/bremoran/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bremoran/subscriptions","organizations_url":"https://api.github.com/users/bremoran/orgs","repos_url":"https://api.github.com/users/bremoran/repos","events_url":"https://api.github.com/users/bremoran/events{/privacy}","received_events_url":"https://api.github.com/users/bremoran/received_events","type":"User","site_admin":false},"created_at":"2015-10-23T09:28:03Z","updated_at":"2015-10-23T09:28:03Z","body":"As demonstrated in https://github.com/ARMmbed/mbed-example-network/issues/31, the lack of module initialization functions forces network objects to be created on the heap.  It is not possible to statically allocate a network object, since it must be initialized after the stack registration (e.g. ```lwipv4_init()```)."}}