Subject: Re: [ruby-ffi] ffi-swig generating a :string instead of a :pointer ?? |
From: Andrea Fazzi |
Date: 12/13/09 2:58 AM |
To: ruby-ffi |
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.Looking more closely at ffi-swig it's type_spec.rb does expect: char *string; to be turned into a :string. I'm not much of a C programmer but is that correct? It seems in this case it should be a pointer.
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. Cheers,-- Andrea Fazzi @ alcacoop.it Follow me on http://twitter.com/remogatto