[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-hackers] [PATCH(5)] Add allocation size helpers C_SIZEOF_STRUCT
[Chicken-hackers] [PATCH(5)] Add allocation size helpers C_SIZEOF_STRUCT and C_SIZEOF_CLOSURE
Sat, 13 Sep 2014 20:43:51 +0200
While working on the "numbers" egg, I noticed we don't have a size
calculation macro for record types and closures. Attached is a patch
to add these. Please note that the size calculation of the closure
in C_call_with_cthulhu was wrong, as well as the allocation in
handle_interrupt (including misleading comment), unless I completely
misunderstand what it's doing.
The patch *could* also be applied to master, but I don't really see a
reason to do that; any egg using the macros would only work with 4.10.0.
I am a little unsure what the correct "length" argument for closures and
structures should be: naturally one would assume it's the number of slots.
However, the C_closure() function accepts a "number of cells", which
includes the cell for the function pointer, and C_structure() accepts
the number of cells, which includes the "slot" for the struct type tag.
This is a little confusing, as you would expect these to accept the
number of user slots, excluding structure type tag or function pointer
(so, if a record type has no slots, it's 0 and not 1 like it is now).
I tried to change this, but I ended up in a quagmire: there's a
specialization rewrite which assumes that the number of arguments to,
say, C_a_i_record2 is 2. Anyway, it would be too much of a breaking
change (bootstrapping issues and whatnot).
So in the end I decided that it's probably the simplest to just keep
things the way they are, and use the "low level" slot size as the
interface everywhere. I've added this to the "C interface" document.
More confusing things: It's called STRUCT(URE) everywhere, but the
constructors are called C_a_i_record[N]. The C_closure() function
accepts the slot count, including the function pointer but it has
the function pointer as a separate argument. The C_record()/C_structure
only accept a count and have the tag as part of the rest arg. The
C_make_structure() function, however, has the type as an explicit
argument with only the slots as varargs.
Not sure if we should fix these now, but they sure are confusing.
Description: Text document
- [Chicken-hackers] [PATCH(5)] Add allocation size helpers C_SIZEOF_STRUCT and C_SIZEOF_CLOSURE,
Peter Bex <=