Giter Site home page Giter Site logo

claw's Introduction

CLAW

Still BETA quality. API is subject to change.

Common Lisp autowrapping facility for quickly creating clean&lean bindings to C/C++ libraries.

Usage for the brave

Building

To use claw you need:

Steps:

  • Clone claw, claw-utils and cl-resect into ~/quicklisp/local-projects
  • Build libresect.so by following instructions in libresect repo

Usage

claw (libclang actually) has known problems on SBCL, so CCL recommended. You only need CCL to generate bindings. After that, generated bindings can be used anywhere CFFI works.

In repl:

;; preload libresect.so
(pushnew :claw-regen-adapter *features*)
(ql:quickload :cffi)
(cffi:load-foreign-library "<path-to>/libresect/build/resect/libresect.so")

Now you can tinker with existing wrappers to play with claw beta version E.g. claw-olm

(ql:quickload :claw-olm/wrapper)
(claw:load-wrapper :claw-olm/wrapper)

claw's People

Contributors

borodust avatar fitzsim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

claw's Issues

Set environment variable LIBCLANG_DISABLE_CRASH_RECOVERY=1 as possible fix for sbcl crashing.

Reference:
https://reviews.llvm.org/D23662

Before setting this environment variable sbcl crashes nearly every time I run claw (as per the warning on the project front page). After setting this, sbcl has successfully run on some fairly large bindings (aw-skia). Note that while libclang has the exported function: clang_toggleCrashRecovery, this is not sufficient because libclang will destructively install its own signal handlers in clang_createIndex unless this environment variable is set.

:const is not recognized at compile time if quoted

(%skia:get-family-name
     ':const
     '(claw-utils:claw-pointer %skia:sk-typeface) typeface
     '(claw-utils:claw-pointer %skia:sk-string) sk-str)

vs

(%skia:get-family-name
     :const
     '(claw-utils:claw-pointer %skia:sk-typeface) typeface
     '(claw-utils:claw-pointer %skia:sk-string) sk-str)

c2ffi fails due to '-F' flag

On my machine, claw is attempting to run c2ffi like this:

c2ffi /tmp/sometmpfile -D null -M /tmp/anothertmpfile --lang c -A x86_64-pc-linux-gnu [-i lots of includes ...] -F wrapper-pathname 

However the latest c2ffi (version 14) barfs on the -F flag and does not seem to support it, or at least it is not documented. What is the purpose of that flag?

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!

Installation via Quicklisp for SBCL causes `SB-KERNEL::CONTROL-STACK-EXHAUSTED`

Hello, I was attempting to install your other package, bodge-nuklear and I ran into this interesting issue.

INFO: Control stack guard page unprotected
[1/3] System 'bodge-nuklear' found. Loading the system..Control stack guard page temporarily disabled: proceed with caution
Unhandled SB-KERNEL::CONTROL-STACK-EXHAUSTED in thread #<SB-THREAD:THREAD "main thread" RUNNING
                                                          {1001548173}>:
  Control stack exhausted (no more space for function call frames).
This is probably due to heavily nested or infinitely recursive function
calls, or a tail call that SBCL cannot or has not optimized away.

PROCEED WITH CAUTION.

Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {1001548173}>
0: (SB-DEBUG::DEBUGGER-DISABLED-HOOK #<SB-KERNEL::CONTROL-STACK-EXHAUSTED {10056A6253}> #<unused argument> :QUIT T)
1: (SB-DEBUG::RUN-HOOK SB-EXT:*INVOKE-DEBUGGER-HOOK* #<SB-KERNEL::CONTROL-STACK-EXHAUSTED {10056A6253}>)
2: (INVOKE-DEBUGGER #<SB-KERNEL::CONTROL-STACK-EXHAUSTED {10056A6253}>)
3: (ERROR SB-KERNEL::CONTROL-STACK-EXHAUSTED)
4: (SB-KERNEL::CONTROL-STACK-EXHAUSTED-ERROR)
5: ("foreign function: call_into_lisp")
6: ("foreign function: post_signal_tramp")
7: ("foreign function: #x7FCAA500D161")
8: (SB-UNIX:UNIX-REALPATH "/home/my_user/.roswell/lisp/quicklisp/dists/quicklisp/software/cffi_0.24.1/cffi.asd")
9: (SB-IMPL::%QUERY-FILE-SYSTEM #P"/home/my_user/.roswell/lisp/quicklisp/dists/quicklisp/software/cffi_0.24.1/cffi.asd" :TRUENAME NIL)
10: (SB-IMPL::QUERY-FILE-SYSTEM #P"/home/my_user/.roswell/lisp/quicklisp/dists/quicklisp/software/cffi_0.24.1/cffi.asd" :TRUENAME NIL)
11: (PROBE-FILE #P"/home/my_user/.roswell/lisp/quicklisp/dists/quicklisp/software/cffi_0.24.1/cffi.asd")
12: (UIOP/FILESYSTEM:PROBE-FILE* #P"/home/my_user/.roswell/lisp/quicklisp/dists/quicklisp/software/cffi_0.24.1/cffi.asd" :TRUENAME T)
13: (UIOP/FILESYSTEM:TRUENAMIZE #P"/home/my_user/.roswell/lisp/quicklisp/dists/quicklisp/software/cffi_0.24.1/cffi.asd")
14: (ASDF/SESSION:NORMALIZE-NAMESTRING #P"/home/my_user/.roswell/lisp/quicklisp/dists/quicklisp/software/cffi_0.24.1/cffi.asd")
15: (ASDF/SESSION:GET-FILE-STAMP #P"/home/my_user/.roswell/lisp/quicklisp/dists/quicklisp/software/cffi_0.24.1/cffi.asd")
16: ((:METHOD ASDF/ACTION:COMPUTE-ACTION-STAMP (T ASDF/OPERATION:OPERATION ASDF/COMPONENT:COMPONENT)) #<ASDF/PLAN:SEQUENTIAL-PLAN {10056A5CF3}> #<ASDF/FIND-SYSTEM:DEFINE-OP > #<ASDF/SYSTEM:SYSTEM "cffi"> :JUST-DONE NIL) [fast-method]
17: (ASDF/FIND-SYSTEM::DEFINITION-DEPENDENCIES-UP-TO-DATE-P #<ASDF/SYSTEM:SYSTEM "cffi">)
18: ((LAMBDA NIL :IN ASDF/SYSTEM:FIND-SYSTEM))
19: (ASDF/SESSION:CONSULT-ASDF-CACHE (ASDF/SYSTEM:FIND-SYSTEM "cffi") #<FUNCTION (LAMBDA NIL :IN ASDF/SYSTEM:FIND-SYSTEM) {100569D64B}>)
20: (ASDF/SESSION:CALL-WITH-ASDF-SESSION #<FUNCTION (LAMBDA NIL :IN ASDF/SYSTEM:FIND-SYSTEM) {100569D64B}> :OVERRIDE NIL :KEY (ASDF/SYSTEM:FIND-SYSTEM "cffi") :OVERRIDE-CACHE NIL :OVERRIDE-FORCING NIL)
21: ((LABELS QUICKLISP-CLIENT::RECURSE :IN QUICKLISP-CLIENT::COMPUTE-LOAD-STRATEGY) "cffi")
22: ((LABELS QUICKLISP-CLIENT::RECURSE :IN QUICKLISP-CLIENT::COMPUTE-LOAD-STRATEGY) "claw")
23: ((LABELS QUICKLISP-CLIENT::RECURSE :IN QUICKLISP-CLIENT::COMPUTE-LOAD-STRATEGY) "claw-utils")
24: ((LABELS QUICKLISP-CLIENT::RECURSE :IN QUICKLISP-CLIENT::COMPUTE-LOAD-STRATEGY) "claw/util")
25: ((LABELS QUICKLISP-CLIENT::RECURSE :IN QUICKLISP-CLIENT::COMPUTE-LOAD-STRATEGY) "claw/wrapper")

It seems there's something in relation to claw. Or maybe CFFI.

I'm using SBCL, version 2.1.9.

Add vararg support

We can't somehow pass ... arguments further onto wrapped function (in case of C++ wrapping) unless there's an equivalent function accepting va_list. We either can get smart or maybe for C++ we should just ignore vararg functions (...) completely.

Error compiling iffi

Compiling iffi fails with the message:

;;; Error:
;;;   in file iffi.lisp, position 295
;;;   at (INITIALIZE-IFFI)
;;;   * The macro form (CFFI:DEFCFUN ("aligned_alloc" ALIGNED-ALLOC) :POINTER (BYTE-ALIGNMENT :SIZE) (BYTE-SIZE :SIZE)) was not expanded successfully.
;;; Error detected:
;;; Unknown CFFI type :SIZE
Condition of type: COMPILE-FILE-ERROR

As :SIZE is a foreign type built into CFFI, I'm not sure why this is happening, although - having said that - I'm not too experienced in these matters.

This is on ECL, (the only other implementation that I currently have installed that isn't SBCL).

Add ppc64 and ppc64le support

Can you please add support for the powerpc64-pc-linux-gnu and powerpc64le-pc-linux-gnu platforms? I can help test them, and I have some preliminary patches, but I don't know which branch or tag to start from (master appears to be ahead of the version available in Quicklisp). Thanks! (I noticed the support was missing when I attempted (ql:quickload :trivial-gamekit) on Debian ppc64le.)

Undefined Function Error

I get the following when running (ql:quickload :claw-olm/wrapper) and (claw:load-wrapper :claw-olm/wrapper)

The alien function "resect_options_enforce_definition" is undefined.
[Condition of type SB-KERNEL::UNDEFINED-ALIEN-FUNCTION-ERROR]\

I get the same error when trying to load claw-torch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.