Subject: Re: [ruby-ffi] ffi-swig generating a :string instead of a :pointer ?? |
From: Stephen Bannasch |
Date: 12/13/09 5:30 PM |
To: ruby-ffi@googlegroups.com |
Excerpts from Stephen Bannasch's message of dom dic 13 05:23:50 +0100 2009:
I have a C++ function that takes a pointer to a buffer where the function stores a C-string. This is what I wrote and got working. attach_function :GoIO_GetNthAvailableDeviceName, [:pointer, :int, :int, :int, :int], :int However if I use ffi-swig it generates a :string as the first parameter. attach_function :GoIO_GetNthAvailableDeviceName, [ :string, :int, :int, :int, :int ], :int Is there anyway this could work? The function needs an address to a location to store a C-string.
Using char* rather than const char* for string it's not strictly incorrect IMHO. I'd say it's a bad practice so, in this case, the generator is favoring a bad practice. I was troubled about the behaviour to impose in cases like this since so many libraries I processed with the generator follow the bad practice. And I ended up with the conversion char* -> :string. That said, you need a different behaviour now so I should reconsider my choice. BTW, I'd like to read the opinion of the ML about this.
How about a command-line option to turn the behavior on or off? Are there more translation patterns that people might also expect to have different outcomes?