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

Parse constants like luajit-ffi #2

Open
mingodad opened this issue Aug 27, 2020 · 3 comments
Open

Parse constants like luajit-ffi #2

mingodad opened this issue Aug 27, 2020 · 3 comments

Comments

@mingodad
Copy link

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
Copy link
Author

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
Copy link
Owner

q66 commented Aug 27, 2020

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
Copy link

/* 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

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

3 participants