q66 / cffi-lua

A portable C FFI for Lua 5.1+
MIT License
176 stars 24 forks source link

Parse constants like luajit-ffi #2

Open mingodad opened 4 years ago

mingodad commented 4 years ago

Hello ! Nice work ! While doing some tests with existing luajit-ffi files I noticed that cffi do not understand this declarations as constants like enums:

/* kind of structural variable: */
static const int GLP_CV=  1;  /* continuous variable */
static const int GLP_IV = 2;  /* integer variable */
static const int GLP_BV=  3;  /* binary variable */

Cheers !

mingodad commented 4 years ago

Also on linux to eliminate the dependency on libstdc++ I've added this to src/util.cc

#include <cstdlib>
#include <cstdio>

#include "util.hh"

// MSVC uses __cdecl calling convention for new/delete :-O
#ifdef _MSC_VER
#  define NEWDEL_CALL __cdecl
#else
#  define NEWDEL_CALL
#endif

void *NEWDEL_CALL operator new(size_t n) {
    void *p = malloc(n);
    if (!p) {
        abort(); /* FIXME: do not abort */
    }
    return p;
}

void *NEWDEL_CALL operator new[](size_t n) {
    void *p = malloc(n);
    if (!p) {
        abort();
    }
    return p;
}

void NEWDEL_CALL operator delete(void *p) {
    free(p);
}

void NEWDEL_CALL operator delete[](void *p) {
    free(p);
}

void NEWDEL_CALL operator delete(void *p, size_t) {
    free(p);
}

void NEWDEL_CALL operator delete[](void *p, size_t) {
    free(p);
}

extern "C" void __cxa_pure_virtual ()
{
    puts("__cxa_pure_virtual called\n");
    abort ();
}

extern "C" int __cxa_thread_atexit(void (*func)(), void *obj,
                                   void *dso_symbol) {
  int __cxa_thread_atexit_impl(void (*)(), void *, void *);
  return __cxa_thread_atexit_impl(func, obj, dso_symbol);
}
q66 commented 4 years ago

constants parsing is a rough work in progress right now, as is eliminating libstdc++ (the ultimate goal is to not have any C runtime dependency on windows, on unix-likes it'll use libc as libc is the standard runtime)

MagicD3VIL commented 2 months ago
/* kind of structural variable: */
static const int GLP_CV=  1;  /* continuous variable */
static const int GLP_IV = 2;  /* integer variable */
static const int GLP_BV=  3;  /* binary variable */

I just crashed into this while trying to use the xlib library with cffi. Is the constant parsing still a planned feature? Any ETA on when it could get implemented?

Cheers