Plaster
New
List
Login
text
apl
aspx
asterisk
brainfuck
c
c++hdr
c++src
cassandra
ceylon
clojure
clojurescript
cmake
cobol
coffeescript
common-lisp
crystal
csharp
css
cypher-query
cython
d
dart
diff
django
dockerfile
dylan
ebnf
ecl
ecmascript
edn
eiffel
ejs
elm
erb
erlang
ez80
factor
fcl
feature
forth
fortran
fragment
gfm
go
gql
groovy
gss
haml
handlebars-template
haskell
haxe
hive
html
http
httpd-php
httpd-php-open
hxml
ini
java
javascript
json
jsp
jsx
julia
kotlin
latex
less
literate-haskell
lua
mariadb
markdown
mbox
mirc
mscgen
msgenny
mssql
mumps
mysql
n-triples
nesc
nginx-conf
nsis
objectivec
octave
oz
pascal
perl
pgp
pgp-keys
pgp-signature
pgsql
php
pig
plsql
properties
protobuf
puppet
python
q
rpm-changes
rpm-spec
rsrc
ruby
rustsrc
sas
sass
scala
scheme
scss
sieve
slim
smarty
solr
soy
sparql-query
spreadsheet
sql
squirrel
stex
styl
swift
systemverilog
tcl
textile
tiddlywiki
tiki
tlv
tornado
ttcn-asn
ttcn-cfg
turtle
twig
typescript
typescript-jsx
vb
vbscript
velocity
verilog
vertex
vhdl
vue
webidl
xml
xml-dtd
xquery
xu
yaml
z80
default
Visibility:
public
unlisted
private
I am having some trouble with what I think is defining C structs via libffi. Below are two tests; the first one works and just demonstrates correctly using libffi. The second test is almost identical to the first but the function passes a struct. Right below the tests I included the struct definitions for SBCL and libffi. (defun test3 () (let* ((*readtable* (copy-readtable objc:*objc-readtable*)) (method-name "characterAtIndex:") (method-info (find "GSCString" (gethash method-name objc:*methods*) :key (lambda (x) (slot-value x 'objc::class-name)) :test #'equal)) (num-args (+ 2 (objc::num-args method-info))) (cif (sb-alien:make-alien (sb-alien:struct ffi::ffi-cif))) (args (sb-alien:make-alien (* (sb-alien:struct ffi::ffi-type)) num-args)) (vals (ffi:malloc (* num-args ffi:*word-size*))) (rc (ffi:malloc ffi:*word-size*)) (ns-str (#/initWithCString: (#/alloc 'gs-base::ns-string) (sb-alien:alien-sap (sb-alien:make-alien-string "abc")))) (ns-str-ptr (ffi:malloc ffi:*word-size*)) (sel (objc:selector method-name)) (sel-ptr (ffi:malloc ffi:*word-size*)) (idx-ptr (ffi:malloc ffi:*word-size*))) (setf (sb-sys:sap-ref-sap ns-str-ptr 0) ns-str) (setf (sb-sys:sap-ref-sap sel-ptr 0) sel) (setf (sb-sys:sap-ref-64 idx-ptr 0) 1) (setf (sb-alien:deref args 0) (sb-alien:addr ffi::ffi-type-pointer)) (setf (sb-alien:deref args 1) (sb-alien:addr ffi::ffi-type-pointer)) (setf (sb-alien:deref args 2) (sb-alien:addr ffi::ffi-type-uint64)) (setf (sb-sys:sap-ref-sap vals 0) ns-str-ptr) (setf (sb-sys:sap-ref-sap vals 8) sel-ptr) (setf (sb-sys:sap-ref-sap vals 16) idx-ptr) (when (= ffi:ffi-ok (ffi:ffi-prep-cif cif ffi:ffi-default-abi num-args (sb-alien:addr ffi::ffi-type-uint16) args)) (format t "prepped cif!~%") (ffi:ffi-call cif (objc::method-getimplementation (objc::method-ptr method-info)) rc vals) (format t "called!~%") rc))) Here are the struct definitions for SBCL and then libffi (SB-ALIEN:DEFINE-ALIEN-TYPE NIL (SB-ALIEN:STRUCT NS-RANGE (LOCATION SB-ALIEN:UNSIGNED-LONG) (LENGTH SB-ALIEN:UNSIGNED-LONG))) (defparameter *ns-range-type* (sb-alien:make-alien (sb-alien:struct ffi:ffi-type))) (defun define-ns-range-type () (setf (sb-alien:slot (sb-alien:deref *ns-range-type*) 'ffi::size) 0) (setf (sb-alien:slot (sb-alien:deref *ns-range-type*) 'ffi::alignment) 0) (setf (sb-alien:slot (sb-alien:deref *ns-range-type*) 'ffi::type) ffi:ffi-type-struct) (setf (sb-alien:slot (sb-alien:deref *ns-range-type*) 'ffi::elements) (ffi:malloc (* 3 ffi:*word-size*))) (setf (sb-sys:sap-ref-sap (sb-alien:slot (sb-alien:deref *ns-range-type*) 'ffi::elements) 0) (sb-alien:alien-sap ffi::ffi-type-uint64)) (setf (sb-sys:sap-ref-sap (sb-alien:slot (sb-alien:deref *ns-range-type*) 'ffi::elements) 8) (sb-alien:alien-sap ffi::ffi-type-uint64)) (setf (sb-sys:sap-ref-sap (sb-alien:slot (sb-alien:deref *ns-range-type*) 'ffi::elements) 16) (ffi:null-pointer)))