[MacRuby-devel] Bitfields and arrays in structures

Steven Canfield stevencanfield.macruby at gmail.com
Tue Jan 5 19:58:07 PST 2010


Does anyone have any thoughts on this?
The plan was to have a function returning a type like:
typedef struct arrayType {
	int values[4];
} arrayType;
give a Boxed object that has an array of values. Does that make sense?
Any idea on how to handle C bitfields?
I'm trudging ahead with a patch and some tests but I want some input ;)
-Steve


On Jan 4, 2010, at 9:58 AM, Steven Canfield wrote:

> Hello all,
> I'm new to MacRuby so please bear with me. Yesterday I was going  
> through the buglist and happened upon bug #280 (https://www.macruby.org/trac/ticket/280 
> ) "NSNumber#decimalValue cant convert to ruby object". I created an  
> objective c file to print out the method signature and I got this:
> {?=b8b4b1b1b18[8S]}16 at 0:8
> (The ? would be replaced by NSDecimal_ when in MacRuby)
>
> The initial problem is happening inside of  
> RoxorCompiler::convert_type (compiler.cpp) which doesn't handle the  
> _C_BFLD type. Upon some further testing, it also doesn't handle the  
> [8S] part (array of 8 short), which is also bug #178  (https://www.macruby.org/trac/ticket/178 
> ). So it seems like I need to add bitfield and structure array  
> support.
>
> My question is, how is all of this supposed to be represented. I  
> assume the arrays part can just be ArrayType, while we probably want  
> to treat a bitfield declaration as just a regular structure, i.e.
>
> typedef struct {
>    signed   int _exponent:8;
>    unsigned int _length:4;     // length == 0 && isNegative -> NaN
>    unsigned int _isNegative:1;
>    unsigned int _isCompact:1;
>    unsigned int _reserved:18;
>    unsigned short _mantissa[NSDecimalMaxSize];
> } NSDecimal;
>
> would be interpreted as
>
> typedef struct {
>    signed   int _exponent;
>    unsigned int _length;     // length == 0 && isNegative -> NaN
>    unsigned int _isNegative;
>    unsigned int _isCompact;
>    unsigned int _reserved;
>    unsigned short _mantissa[NSDecimalMaxSize];
> } NSDecimal;
>
> The only problem I see with this is that we have to convert back to  
> NSDecimal packing on return. Maybe it would be better to have a ruby  
> class that provides accessors to the NSDecimal similar to Boxed (or  
> modify Boxed to handle this situation).
>
> Just looking for a little bit of guidance,
> -Steve
>



More information about the MacRuby-devel mailing list