claw
claw copied to clipboard
Unable to emit constant values from sqlite3.h
I'm wrapping SQLite and at first glance everything went well except for:
// The typedef is necessary to work around problems in certain C++ compilers.
typedef void (*sqlite3_destructor_type)(void*);
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
They were translated to nil
instead of a value:
(defparameter %sqlite::+static+ nil)
(defparameter %sqlite::+transient+ nil)
Is it possible to set this up so the values are computed?
Wrapper definition (from https://github.com/Hickory-DMTools/Hickory-SQLite):
(claw:defwrapper (:hickory-sqlite
(:system :hickory-sqlite/wrapper)
(:headers "sqlite3.h")
(:includes :sqlite-includes)
(:targets ((:and :x86-64 :linux) "x86_64-pc-linux-gnu")
((:and :x86-64 :windows) "x86_64-w64-mingw32")
((:and :x86-64 :darwin) "x86_64-apple-darwin-gnu"))
(:include-extra-values)
(:include-definitions "^SQLITE\\w+" "^sqlite3_\\w+")
(:persistent t :depends-on ()))
:in-package :%sqlite
:recognize-strings t
:inline-functions nil
:symbolicate-names (:in-pipeline
(:by-removing-prefixes "SQLITE_" "sqlite3_")))
I'm using SBCL 2.2.2
on a Mac. Tried with CCL 1.12.1
and got the same results.
Thanks for the awesome work, by the way!
I've looked into the problem. Unfortunately, to enable this specific edge-case with define that is actually a pointer (to a function) libresect
requires a very hairy code. The main reason being that clang_Cursor_Evaluate
(what libresect
uses for parsing defines internally) can't handle pointers at the moment (clang v13).
You have two ways for a workaround:
- (Less desirable, but simple) Define those variables yourself in CL
- (More desirable, portable and future proof) Create your own
.h
file with a new defines- Include
sqlite3.h
into your new header file - Put a new define there, smth lke
#define ANOTHER_SQLITE_STATIC ((int)SQLITE_STATIC)
or smth better - Add
"^ANOTHER_"
intoclaw
'sdefwrapper
includes
- Include
For the latter approach, it will look smth like this example