Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some definitions are ignored #7

Closed
ingeniarius opened this issue Jun 22, 2012 · 7 comments
Closed

Some definitions are ignored #7

ingeniarius opened this issue Jun 22, 2012 · 7 comments

Comments

@ingeniarius
Copy link

I tried to generate .rb from libssh2.h (http://libssh2.org/download/libssh2-1.4.2.tar.gz)

But some definitions and macros are ignored.

Configuration for generation:

FFI::Gen.generate(
  module_name: "LibSSH2",
  ffi_lib:     "libssh2",
  headers:     ["libssh2/include/libssh2.h"],
  cflags:      `llvm-config --cflags`.split(" "),
  prefixes:    ["libssh2_", "LIBSSH2"],
  output:      "libssh2/libssh2.rb"
)

For example the following definitions were ignored:

#define LIBSSH2_CHANNEL_WINDOW_DEFAULT  (256*1024)

#define libssh2_channel_open_session(session) \
    libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \
                      LIBSSH2_CHANNEL_WINDOW_DEFAULT, \
                      LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
@neelance
Copy link
Owner

Hi, thanks for using ffi-gen.

The first define should be easy to fix, I just need to parse more
arithmetic expressions. I'll look into that soon.

The second one is more difficult. Maybe ffi-gen could detect that this is
only a call to another function and generate a wrapper function for that.
But the arguments are also difficult to handle (using sizeof, etc.). So I
think the better solution is to write these wrappers by hand. Just reopen
the generated module after including it and add the methods. Are you okay
with that?

@ingeniarius
Copy link
Author

Yes, it's ok!

But, is it possible to collect code which cannot be processed?
Thus, we have a chance to know what could be lost.

Thanks for this magic tool!

@neelance
Copy link
Owner

Good idea! I will add warnings on the console.

@neelance
Copy link
Owner

I've added support for more defines in 85abca7 and warnings for unsupported values in 7f4ef20. I think I will also add support for defines like "libssh2_channel_open_session" soon, because I noticed that they are quite common in many libraries.

@ingeniarius
Copy link
Author

Good progress! Tnx!

@neelance
Copy link
Owner

I've added first processing of method-like defines in 329fda9. It is still quite rudimentary, but it does the job for most of libssh2's defines. I will close this issue now. Feel free to open new ones if you find problems concerning the generated methods.

@ingeniarius
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants