-
Notifications
You must be signed in to change notification settings - Fork 15
Conversation
This should probably do reference counting in the initializer, and generate a finalizer. It also doesn't support 100% everything yet, but it's pretty good for the few services I used it on. |
scripts/gencode.py
Outdated
@@ -185,6 +185,9 @@ def gen_init(): | |||
args = "void" if cmd is None else formatArgs(cmd['outputs'], cmd['inputs']) | |||
|
|||
print "result_t %s_init(%s) {" % (c_ifacename, args) | |||
print "\tif(%s_initializations++ > 0) {" % c_ifacename | |||
print "\t\treturn RESULT_OK;" | |||
print "\t}" | |||
print "\tresult_t res;" | |||
print "\tres = sm_get_service(&%s_object, \"%s\");" % (c_ifacename, ifacename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPC modules should initialize sm
before calling sm_get_service
so as to hide their dependency on it, and make sure to also close it afterwards. You also need to decrease initializations
on failure. See https://github.com/reswitched/libtransistor/blob/master/lib/ipc/vi.c#L42
I normally don't nitpick on this, but I'd like autogenerated code to follow our coding style, so it should look more like this:
result_t %s_init(%s) {
if(%s_initializations++ > 0) {
return RESULT_OK;
}
result_t r;
r = sm_init();
if(r) {
goto fail;
}
r = sm_get_service(&%s_object, "%s");
if(r) {
goto fail_sm;
}
sm_finalize();
return RESULT_OK;
fail_sm:
sm_finalize();
fail:
%s_initializations--;
return r;
}
Thx for the review. This should fix it. |
scripts/gencode.py
Outdated
print "fail_sm:" | ||
print "\tsm_finalize();" | ||
print "fail:" | ||
print "\treturn res;" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget to decrease references here
So erm, this now also contains the other branch that contains struct because I wanted to generate structs in here. Woops. Also had a conversation about hthh. Turns out, there are alignment issues and stuff, which makes my current method of dealing with data tricky. A better method would be to generate anonymous structs and let the C compiler figure it out. A log of a conversation with hthh:
|
The IPC generator should live as a libtransistor tool, like megaton-hammer does. |
No description provided.