Jonathan deWerd
jjoon****@gmail*****
Tue Dec 25 07:42:02 JST 2007
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) and here is the diff file of libffi.m that patches it so it works: Sorry if this isn't the Right Way to submit a patch, but as I said, I am new here :) -------------- next part -------------- An HTML attachment was scrubbed... Download -------------- next part -------------- A non-text attachment was scrubbed... Name: RCStructBug.zip Type: application/zip Size: 43985 bytes Desc: not available Url : http://lists.sourceforge.jp/mailman/archives/rubycocoa-devel/attachments/20071224/8f1d933e/attachment.zip -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.sourceforge.jp/mailman/archives/rubycocoa-devel/attachments/20071224/8f1d933e/attachment-0001.htm -------------- next part -------------- A non-text attachment was scrubbed... Name: libffi.m.diff Type: application/octet-stream Size: 931 bytes Desc: not available Url : http://lists.sourceforge.jp/mailman/archives/rubycocoa-devel/attachments/20071224/8f1d933e/attachment.obj -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.sourceforge.jp/mailman/archives/rubycocoa-devel/attachments/20071224/8f1d933e/attachment-0002.htm -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 1646 bytes Desc: not available Url : http://lists.sourceforge.jp/mailman/archives/rubycocoa-devel/attachments/20071224/8f1d933e/attachment.bin