[Rubycocoa-devel 1282] Re: C array in struct return type bug

Back to archive index

Laurent Sansonetti lsans****@apple*****
Wed Dec 26 22:04:19 JST 2007


Hi Jonathan,

Thanks for the patch. I just applied it to trunk, and I also put your  
test project logic in the current tests suite.

This area was definitely not tested a lot, so thanks for your attention!

Laurent

On Dec 24, 2007, at 11:42 PM, Jonathan deWerd wrote:

> Some code I had that returned a struct was crashing, and I managed  
> to reduce the crash to anything that returned a struct with a C  
> array in it. For instance, this in main.m:
>
>> struct ttype1 {float a; float b;};
>> struct ttype2 {float a[2];};
>>
>> @implementation NSObject (FooTests)
>> - (struct ttype1)test1 {
>> 	struct ttype1 r = {1., 2.};
>> 	return r;
>> }
>> - (struct ttype2)test2 {
>> 	struct ttype2 r;
>> 	r.a[0] = 1.;
>> 	r.a[1] = 2.;
>> 	return r;
>> }
>> @end
>>
>> int main(int argc, const char *argv[])
>> {
>>     return RBApplicationMain("rb_main.rb", argc, argv);
>> }
>
> would cause this in rb_man.rb to crash on the second test:
>> r = OSX::NSObject.alloc.init
>> puts r.test1 #works just fine
>> puts r.test2 #crashed before patch, doesn't after
>
> I managed to track the problem down to a 0 alignment being assumed  
> for array types in structs. This caused the padded size of such  
> struct types to be 0 and made the bridge crash and burn whenever an  
> unfortunately typed objc method was called across the bridge.
>
> Here is the test project: (email me if attachments don't work, I am  
> a newbie so I don't know)
> <RCStructBug.zip>
>
> and here is the diff file of libffi.m that patches it so it works:
> <libffi.m.diff>
>
>
> Sorry if this isn't the Right Way to submit a patch, but as I said,  
> I am new here :)
> _______________________________________________
> Rubycocoa-devel mailing list
> Rubyc****@lists*****
> http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel




More information about the Rubycocoa-devel mailing list
Back to archive index