cffi-lua icon indicating copy to clipboard operation
cffi-lua copied to clipboard

Parse constants like luajit-ffi

Open mingodad opened this issue 4 years ago • 3 comments

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 avatar Aug 27 '20 17:08 mingodad

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);
}

mingodad avatar Aug 27 '20 17:08 mingodad

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)

q66 avatar Aug 27 '20 22:08 q66