Well I have sit down and wrote an Addon for Io. Which in fact does not
much but handling a structure in C (not even all functions have been
wrapped) I just wonder if someone could have a look and bail out the
big faults.
I then would try to write some lines about how to write an Addon.
During that course I found some questions:
1) how does the normal C allocation play togehter with the GC from Io?
1.1)I have come up to the following "conclusion"
You do hand the C part separatly and you provide a Struct_fee function
in which you clean the parts which were allocated on the C side
1.2) If one keeps Io datastructures in the Struct_struct then you have
to write Struct_mark function
Is that a correct conclusion?
Here's some code I hope I wrote correctly
IoTestStruct *IoTestStruct_rawClone(IoTestStruct *proto)
{
IoObject *self = IoObject_rawClonePrimitive(proto);
IoObject_setDataPointer_(self, calloc(1, sizeof(IoTestStructData)));
/* test on NULL pointer ? */
DATA(self)->ts = newTestStruct(DATA(proto)->ts->dv,
DATA(proto)->ts->iv);
return self;
}
void IoTestStruct_free(IoTestStruct *self)
{
if (DATA(self)->ts) free(DATA(self)->ts);
free(IoObject_dataPointer(self));
}
In this part the free in the xxx_free function is needed because a
calloc is used above so it has to beclined. the othe free is the C
side which I introduced here:
IoTestStruct *IoTestStruct_rawClone(IoTestStruct *proto)
{
IoObject *self = IoObject_rawClonePrimitive(proto);
IoObject_setDataPointer_(self, calloc(1, sizeof(IoTestStructData)));
/* test on NULL pointer ? */
DATA(self)->ts = newTestStruct(DATA(proto)->ts->dv,
DATA(proto)->ts->iv);
return self;
}
and here:
IoTestStruct *IoTestStruct_proto(void *state)
{
IoObject *self = IoObject_new(state);
IoObject_tag_(self, IoTestStruct_newTag(state));
IoObject_setDataPointer_(self, calloc(1, sizeof(IoTestStructData)));
DATA(self)->ts = newTestStruct(0.0, 0);
Now what happens in the following case
foo := TestStruct clone
and not far later
foo := TestStruct clone
Is the memory proper released? What do I have to do to assure that?
I'm not fully sure about the complete initializaton objects also
so how to the xxxx_proto and xxx_newTag play togethter and what
function must I introdice in the xxx_newTag function?
I append a zip file with all the sources. I tried my luck on a Debian
64-bit box (unstable) and have used the latest Io I could git.
As written, comments, explanations etc are very welcome.
Regards
Friedrich
.