I’m aiming to get a first cut out this week (just the very basics) to
get things moving, but it will take a while to get it all done,
especially the fiddly bits. I’m going to concentrate on the core
ncurses functionality. I’m not interested in panels or forms (better
done in Ruby IMHO).
Is it possible for you to document the procedure, how you go about doing
it, so one can follow that for another port, rather than be totally
lost.
Sure, as long as you don’t mind long-winded stream of consciousness
I’m aiming to get a first cut out this week (just the very basics) to
get things moving, but it will take a while to get it all done,
especially the fiddly bits. I’m going to concentrate on the core
ncurses functionality. I’m not interested in panels or forms (better
done in Ruby IMHO).
I am using panels and forms - heavily. I understand your last
statement to mean implementing p & f’s in ruby itself, avoiding what
ncurses provides. Has anyone actually done that – i would like to see
it and see how its better and if it can be reused.
Sorry if you see this twice, posting difficulties.
I’m having a bash at wrapping freetds. This library
has a Context struct which contains three callback
function pointers. POLS says these should look like
this:
There’s no support at the moment for callbacks-in-structs, but it’s just
a bug report (and ideally a patch) away http://kenai.com/projects/ruby-ffi
Thanks Charlie. I registered at Kenai.com and can log in there
though only by emaill address, username login doesn’t work), but
the Bugzilla instalce doesn’t recognise the login details at all.
I’ll try again later, in case there’s a delayed processing step.
I can’t see any separate registration for Bugzilla…
There’s no support at the moment for callbacks-in-structs, but it’s
just a bug report (and ideally a patch) away http://kenai.com/projects/ruby-ffi
Thanks Charlie. I registered at Kenai.com and can log in there
though only by emaill address, username login doesn’t work), but
the Bugzilla instalce doesn’t recognise the login details at all.
I’ll try again later, in case there’s a delayed processing step.
I can’t see any separate registration for Bugzilla…
I’ll make sure the Kenai guys know about the problem. Thanks for giving
it a shot. If nothing else, email the dev mailing list.
callback :handle_message, [ :pointer, :pointer, :pointer ], :in #
TDSSOCKET, TDSMESSAGE)
:int_handler, :handle_int, 16 # callback(void*)
end
Am I on the right track, or is this not possible yet?
There’s no support at the moment for callbacks-in-structs, but it’s just
a bug report (and ideally a patch) away
callback :handle_message, [ :poi…
class Context < FFI:Struct
layout
:msg_handler, :handle_message, 8,
There’s no support at the moment for callbacks-in-structs
While I’m on a roll, my example above creates a new type
(handle_message),
and the ability to define other kinds of types similarly would be
excellent.
For example, FreeTDS also has a string struct that contains a char* and
a
length, and it uses that type liberally. A typedef would rock, and the
above
example would just create a function-pointer typedef.
In a previous life, we implemented a generic structure pack/unpack
subsystem.
It had a table for every type containing the alignment and size of that
type.
Some architectures need more than one table depending on compile
options, but
we supported 30 different architectures using tables whose values were
filled
in by the C compiler. The rule of C don’t allow re-ordering structure
elements,
or at least, the require that two structures that start with the same
elements
use the same alignment for those elements.
You can discover the alignment of a type by declaring a struct z { char
x; TYPE y; }
and asking for offsetof(struct z, y); Mere byte-counting and padding
suffices
to calculate alignment for the members of any structure. Nested
structures are
padded to the largest of either the maximum alignment of the members, or
some
size specific to the architecture. This can also be populated into the
alignment
tables by the C compiler.
If FFI could include such a facility for Struct definitions, that would
be magic,
as the current system is almost impossible to use for cross-platform
support.
Unless you use the awkward templating system, of course… That requires
that
you have the development versions of the target libraries when you want
to gem
install a wrapper.
Just some random thoughts, anyhow. I might have time to contribute code
to this
effort in December.
C:\ffi>gem install ffi-0.1.0.gem
Building native extensions. This could take a while…
ERROR: Error installing ffi-0.1.0.gem:
ERROR: Failed to build gem native extension.
makefile(182) : fatal error U1052: file ‘$(srcdir)/ffi.mk’ not found
Stop.
Gem files will remain installed in C:/ruby/lib/ruby/gems/1.8/gems/
ffi-0.1.0 for inspection.
Results logged to C:/ruby/lib/ruby/gems/1.8/gems/ffi-0.1.0/ext/
gem_make.out
I don’t know how I missed this before, somehow slipped past my mental
filter (and now everything you were talking about at RubyConf starts to
make a lot more sense… :).
One question: a complaint I’ve had with DL is that it requires that I
specify the dynamic library that contains symbols I’m interested in. Is
this necessary with FFI? Can FFI be used to call functions in the Ruby
standard library when Ruby is not build with --enable-shared?
If so, I’d be interested in using this for Ludicrous to avoid having to
hard-code all the function pointers to the Ruby API functions I want to
call. That would mean, though, I would need FFI to be able to give me a
real function pointer (so I can pass the pointer to libjit… I can
imagine this being useful for other cases as well).
to access stdscr, use the return value from NCurses.initscr
I have not implemented any variadic functions (not supported by libffi
AFAIK)
there’s also a wrapper for libdl called dlfcn.rb
there’s an experimental script (ex01-ffi-dl-stdscr.rb) which uses
dlfcn.rb to access the exported variables from the ncurses shared lib
(stdscr, curscr, etc.). This also shows how to access values returned
through pointers (see NCurses.wattr_get).
There are some rambling notes on implementation in notes-on-ffi-curses.org. I’ll tidy these up when I get some spare
time. Basically, I wrote a script
(generate-ffi-ncurses-function-signatures.rb) that mechanically
recovered the function signatures from the ncurses.h on my machine and
added some constants. I wasted a lot of time figuring out how to
access exported variables.
I’ve only just done a final test on OS X Tiger - haven’t checked Linux
yet (should work but…)
I have not set up a project for this yet so please send any bug
reports, questions, etc. directly to me for the moment.
There are no tests - I wonder if anyone has any ideas how best to
write specs/tests for checking this kind of output?
I tried to run all examples but no one worked. It prints tons of:
/usr/lib/ruby/gems/1.8/gems/ffi-0.1.1/lib/ffi/ffi.rb:232: warning:
instance variable @ffi_convention not initialized
and last line:
example-printw-variadic.rb:7: undefined method `printw’ for
NCurses:Module (NoMethodError)
my wrapper requires ffi-0.2.0 which you’ll need to install from
source. You can get the source from the kenai project site at http://kenai.com/projects/ruby-ffi (though you’ll need to install
mercurial to get it).
The example ex01-ffi-dl-stdscr.rb does not currently work under Linux
I’m looking into that. The only platform I know it works on is Mac
OS X Tiger. The other examples work on both OS X and Linux (with
ffi-0.2.0).