neelance / ffi_gen

A generator for Ruby FFI bindings, directly from header files via LLVM's Clang compiler
MIT License
88 stars 26 forks source link

can't tokenize last macro in file #21

Closed ghazel closed 9 years ago

ghazel commented 10 years ago

foo.h

#define FOO 123
#define BAR 456
require "ffi/gen"

FFI::Gen.generate(
  module_name: "foo",
  ffi_lib:     "foo",
  headers:     ["foo.h"],
  cflags:      `/usr/local/Cellar/llvm/3.4.1/bin/llvm-config --cflags`.split(" "),
  prefixes:    [],
  output:      "foo.rb"

Result:

# Generated by ffi-gen. Please do not change this file by hand.

require 'ffi'

module foo
  extend FFI::Library
  ffi_lib 'foo'

  def self.attach_function(name, *_)
    begin; super; rescue FFI::NotFoundError => e
      (class << self; self; end).class_eval { define_method(name) { |*_| raise e } }
    end
  end

  FOO = 123

end

BAR is nowhere to be found.

Maybe related: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-January/012983.html

ghazel commented 10 years ago

http://llvm.org/bugs/show_bug.cgi?id=9069

sheerun commented 9 years ago

@ghazel Can ffi_gen do something about it? If no, please close :)

whitequark commented 9 years ago

Closing as upstream issue.