Added objcl/gnu swig ffi interface to libobjc.

Pascal J. Bourguignon [2014-02-09 17:17]
Added objcl/gnu swig ffi interface to libobjc.
Filename
objcl/gnu/Makefile
objcl/gnu/com.ogamita.swig.asd
objcl/gnu/gnu.lisp
objcl/gnu/objc.i
objcl/gnu/objc.lisp
diff --git a/objcl/gnu/Makefile b/objcl/gnu/Makefile
new file mode 100644
index 0000000..c81910b
--- /dev/null
+++ b/objcl/gnu/Makefile
@@ -0,0 +1,32 @@
+all:
+	@echo "# choose:"
+	@echo "make linux"
+
+linux:objc.lisp
+
+INCLUDES= -I. -I/usr/lib/gcc/x86_64-linux-gnu/4.7/include/
+OPTS=-fPIC -g -c
+
+
+objc.lisp:objc.i Makefile
+	swig $(INCLUDES) -Dobjc_EXPORT=extern -cffi -generate-typedef -swig-lisp objc.i
+	( sed \
+	 	-e 1i\\ -e '(in-package "COM.INFORMATIMAGO.OBJC.GNU")' \
+		-e 's/&body/cl:&/g' \
+	 	-e 's/#oL/0/g' \
+	 	-e 's/\([0-9]\+\)U\?L\+/\1/g' \
+	 	-e 's/(cl:- \([0-9]\+\) 1)/(cl:- -\1 1)/g' \
+		-e '/(cl:defconstant _C_/d' \
+	 	< objc.lisp  ;\
+	sed \
+		-n \
+		-e 's/#define \(_C_[^ ]*\) *'\''\(.\)'\'' *$$/(cl:defconstant \1 #\\\2)/p' \
+		< /usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/runtime.h \
+	) > objc.new && mv objc.new objc.lisp
+
+# objc_wrap.o:objc_wrap.c
+
+
+
+#### THE END ####
+
diff --git a/objcl/gnu/com.ogamita.swig.asd b/objcl/gnu/com.ogamita.swig.asd
new file mode 100644
index 0000000..2f068d9
--- /dev/null
+++ b/objcl/gnu/com.ogamita.swig.asd
@@ -0,0 +1,29 @@
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+
+#+(or (and ccl darwin) (and clisp macos))
+(eval-when (:execute :compile-toplevel :load-toplevel)
+  (pushnew :macosx *features*))
+
+(asdf:defsystem :com.ogamita.swig
+    :name "Swig generated packages."
+    :description  "This systems gathers all the CFFI packages generated by Swig."
+    :author "<PJB> Pascal Bourguignon <pjb@ogamita.com"
+    :version "0.0.3"
+    :licence "Proprietary"
+    :properties ((#:author-email                   . "pjb@ogamita.com")
+                 (#:date                           . "Spring 2011")
+                 ((#:albert #:output-dir)          . "../documentation/com.ogamita.swig/")
+                 ((#:albert #:formats)             . ("docbook"))
+                 ((#:albert #:docbook #:template)  . "book")
+                 ((#:albert #:docbook #:bgcolor)   . "white")
+                 ((#:albert #:docbook #:textcolor) . "black"))
+    :depends-on ("cffi")
+    :components ((:file "packages")
+                 #-(and)
+                 (:file "xcb"              :depends-on ("packages"))
+                 #+macosx
+                 (:file "coregraphics"     :depends-on ("packages"))
+                 (:file "packages-exports" :depends-on (#-(and)  "xcb"
+                                                        #+macosx "coregraphics"))))
+
+;;;; THE END ;;;;
diff --git a/objcl/gnu/gnu.lisp b/objcl/gnu/gnu.lisp
new file mode 100644
index 0000000..d7094b2
--- /dev/null
+++ b/objcl/gnu/gnu.lisp
@@ -0,0 +1,262 @@
+;;;; -*- mode:lisp;coding:utf-8 -*-
+;;;;**************************************************************************
+;;;;FILE:               gnu.lisp
+;;;;LANGUAGE:           Common-Lisp
+;;;;SYSTEM:             Common-Lisp
+;;;;USER-INTERFACE:     NONE
+;;;;DESCRIPTION
+;;;;
+;;;;    CFFI interface to GNU libobjc.
+;;;;
+;;;;AUTHORS
+;;;;    <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
+;;;;MODIFICATIONS
+;;;;    2013-12-31 <PJB> Created.
+;;;;BUGS
+;;;;LEGAL
+;;;;    AGPL3
+;;;;
+;;;;    Copyright Pascal J. Bourguignon 2013 - 2013
+;;;;
+;;;;    This program is free software: you can redistribute it and/or modify
+;;;;    it under the terms of the GNU Affero General Public License as published by
+;;;;    the Free Software Foundation, either version 3 of the License, or
+;;;;    (at your option) any later version.
+;;;;
+;;;;    This program is distributed in the hope that it will be useful,
+;;;;    but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;;;    GNU Affero General Public License for more details.
+;;;;
+;;;;    You should have received a copy of the GNU Affero General Public License
+;;;;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+;;;;**************************************************************************
+
+(in-package "COMMON-LISP-USER")
+
+(defpackage "COM.INFORMATIMAGO.OBJC.GNU"
+  (:use)
+  (:export
+
+   "BACKEND" "BOOL" "CATEGORY" "CLASS" "CLASS_ADDIVAR"
+   "CLASS_ADDMETHOD" "CLASS_ADDPROTOCOL" "CLASS_CONFORMSTOPROTOCOL"
+   "CLASS_COPYIVARLIST" "CLASS_COPYMETHODLIST"
+   "CLASS_COPYPROPERTYLIST" "CLASS_COPYPROTOCOLLIST"
+   "CLASS_CREATEINSTANCE" "CLASS_GETCLASSMETHOD"
+   "CLASS_GETCLASSVARIABLE" "CLASS_GETINSTANCEMETHOD"
+   "CLASS_GETINSTANCESIZE" "CLASS_GETINSTANCEVARIABLE"
+   "CLASS_GETIVARLAYOUT" "CLASS_GETMETHODIMPLEMENTATION"
+   "CLASS_GETNAME" "CLASS_GETPROPERTY" "CLASS_GETSUPERCLASS"
+   "CLASS_GETVERSION" "CLASS_GETWEAKIVARLAYOUT" "CLASS_ISMETACLASS"
+   "CLASS_IVAR_SET_GCINVISIBLE" "CLASS_POINTER" "CLASS_REPLACEMETHOD"
+   "CLASS_RESPONDSTOSELECTOR" "CLASS_SETIVARLAYOUT" "CLASS_SETVERSION"
+   "CLASS_SETWEAKIVARLAYOUT" "DEPTH" "ID" "IMP" "IVAR" "IVAR_GETNAME"
+   "IVAR_GETOFFSET" "IVAR_GETTYPEENCODING" "METHOD"
+   "METHOD_COPYARGUMENTTYPE" "METHOD_COPYRETURNTYPE"
+   "METHOD_EXCHANGEIMPLEMENTATIONS" "METHOD_GETARGUMENTTYPE"
+   "METHOD_GETDESCRIPTION" "METHOD_GETIMPLEMENTATION" "METHOD_GETNAME"
+   "METHOD_GETNUMBEROFARGUMENTS" "METHOD_GETRETURNTYPE"
+   "METHOD_GETTYPEENCODING" "METHOD_SETIMPLEMENTATION" "NAME"
+   "OBJC_ALIGNED_SIZE" "OBJC_ALIGNOF_TYPE" "OBJC_ALLOCATECLASSPAIR"
+   "OBJC_ATOMIC_MALLOC" "OBJC_CALLOC" "OBJC_CONDITION"
+   "OBJC_CONDITION_ALLOCATE" "OBJC_CONDITION_BROADCAST"
+   "OBJC_CONDITION_DEALLOCATE" "OBJC_CONDITION_SIGNAL"
+   "OBJC_CONDITION_T" "OBJC_CONDITION_WAIT" "OBJC_COPYPROTOCOLLIST"
+   "OBJC_DISPOSECLASSPAIR" "OBJC_ENUMERATIONMUTATION"
+   "OBJC_EXCEPTION_MATCHER" "OBJC_EXCEPTION_THROW" "OBJC_FREE"
+   "OBJC_GETCLASS" "OBJC_GETCLASSLIST" "OBJC_GETMETACLASS"
+   "OBJC_GETPROTOCOL" "OBJC_GETREQUIREDCLASS"
+   "OBJC_GET_TYPE_QUALIFIERS" "OBJC_GET_UNKNOWN_CLASS_HANDLER"
+   "OBJC_LAYOUT_FINISH_STRUCTURE" "OBJC_LAYOUT_STRUCTURE"
+   "OBJC_LAYOUT_STRUCTURE_GET_INFO"
+   "OBJC_LAYOUT_STRUCTURE_NEXT_MEMBER" "OBJC_LOOKUPCLASS"
+   "OBJC_MALLOC" "OBJC_METHOD_DESCRIPTION" "OBJC_MSG_LOOKUP"
+   "OBJC_MSG_LOOKUP_SUPER" "OBJC_MUTEX" "OBJC_MUTEX_ALLOCATE"
+   "OBJC_MUTEX_DEALLOCATE" "OBJC_MUTEX_LOCK" "OBJC_MUTEX_T"
+   "OBJC_MUTEX_TRYLOCK" "OBJC_MUTEX_UNLOCK" "OBJC_OBJECT"
+   "OBJC_PROMOTED_SIZE" "OBJC_PROPERTY_T" "OBJC_REALLOC"
+   "OBJC_REGISTERCLASSPAIR" "OBJC_SETENUMERATIONMUTATIONHANDLER"
+   "OBJC_SETEXCEPTIONMATCHER" "OBJC_SETGETUNKNOWNCLASSHANDLER"
+   "OBJC_SETUNCAUGHTEXCEPTIONHANDLER" "OBJC_SET_THREAD_CALLBACK"
+   "OBJC_SIZEOF_TYPE" "OBJC_SKIP_ARGSPEC" "OBJC_SKIP_OFFSET"
+   "OBJC_SKIP_TYPESPEC" "OBJC_SKIP_TYPE_QUALIFIERS"
+   "OBJC_STRUCT_LAYOUT" "OBJC_SUPER" "OBJC_SYNC_ENTER"
+   "OBJC_SYNC_EXIT" "OBJC_SYNC_NOT_INITIALIZED"
+   "OBJC_SYNC_NOT_OWNING_THREAD_ERROR" "OBJC_SYNC_SUCCESS"
+   "OBJC_SYNC_TIMED_OUT" "OBJC_THREAD_ADD"
+   "OBJC_THREAD_BACKGROUND_PRIORITY" "OBJC_THREAD_CALLBACK"
+   "OBJC_THREAD_DETACH" "OBJC_THREAD_EXIT" "OBJC_THREAD_GET_DATA"
+   "OBJC_THREAD_GET_PRIORITY" "OBJC_THREAD_ID"
+   "OBJC_THREAD_INTERACTIVE_PRIORITY" "OBJC_THREAD_LOW_PRIORITY"
+   "OBJC_THREAD_REMOVE" "OBJC_THREAD_SET_DATA"
+   "OBJC_THREAD_SET_PRIORITY" "OBJC_THREAD_T" "OBJC_THREAD_YIELD"
+   "OBJC_UNCAUGHT_EXCEPTION_HANDLER" "OBJECT_COPY" "OBJECT_DISPOSE"
+   "OBJECT_GETCLASS" "OBJECT_GETCLASSNAME" "OBJECT_GETINDEXEDIVARS"
+   "OBJECT_GETINSTANCEVARIABLE" "OBJECT_GETIVAR" "OBJECT_SETCLASS"
+   "OBJECT_SETINSTANCEVARIABLE" "OBJECT_SETIVAR" "ORIGINAL_TYPE"
+   "OWNER" "PREV_TYPE" "PROPERTY" "PROPERTY_GETATTRIBUTES"
+   "PROPERTY_GETNAME" "PROTOCOL" "PROTOCOL_CONFORMSTOPROTOCOL"
+   "PROTOCOL_COPYMETHODDESCRIPTIONLIST" "PROTOCOL_COPYPROPERTYLIST"
+   "PROTOCOL_COPYPROTOCOLLIST" "PROTOCOL_GETMETHODDESCRIPTION"
+   "PROTOCOL_GETNAME" "PROTOCOL_GETPROPERTY" "PROTOCOL_ISEQUAL"
+   "RECORD_ALIGN" "RECORD_SIZE" "SEL" "SELF"
+   "SEL_COPYTYPEDSELECTORLIST" "SEL_GETNAME" "SEL_GETTYPEDSELECTOR"
+   "SEL_GETTYPEENCODING" "SEL_GETUID" "SEL_ISEQUAL" "SEL_REGISTERNAME"
+   "SEL_REGISTERTYPEDNAME" "SUPER_CLASS" "TYPE" "TYPES" "_C_ARY_B"
+   "_C_ARY_E" "_C_ATOM" "_C_BFLD" "_C_BOOL" "_C_BYCOPY" "_C_BYREF"
+   "_C_CHARPTR" "_C_CHR" "_C_CLASS" "_C_COMPLEX" "_C_CONST" "_C_DBL"
+   "_C_FLT" "_C_GCINVISIBLE" "_C_ID" "_C_IN" "_C_INOUT" "_C_INT"
+   "_C_LNG" "_C_LNG_DBL" "_C_LNG_LNG" "_C_ONEWAY" "_C_PTR" "_C_SEL"
+   "_C_SHT" "_C_STRUCT_B" "_C_STRUCT_E" "_C_UCHR" "_C_UINT" "_C_ULNG"
+   "_C_ULNG_LNG" "_C_UNDEF" "_C_UNION_B" "_C_UNION_E" "_C_USHT"
+   "_C_VECTOR" "_C_VOID" "_F_BYCOPY" "_F_BYREF" "_F_CONST"
+   "_F_GCINVISIBLE" "_F_IN" "_F_INOUT" "_F_ONEWAY" "_F_OUT"
+   "_OBJC_LOAD_CALLBACK" "__GNU_LIBOBJC__" "__OBJC_INIT_THREAD_SYSTEM"
+   "__OBJC_MSG_FORWARD" "__OBJC_MSG_FORWARD2"
+   "__OBJC_THREAD_EXIT_STATUS"))
+
+
+(defpackage "COM.INFORMATIMAGO.OBJC"
+  (:use "COMMON-LISP"
+        "COM.INFORMATIMAGO.OBJC.GNU")
+  (:shadowing-import-from "COM.INFORMATIMAGO.OBJC.GNU"
+                          "CLASS" "METHOD" "TYPE")
+  (:export))
+
+(in-package "COM.INFORMATIMAGO.OBJC")
+
+
+(ql:quickload :cffi)
+(pushnew #P"/usr/lib/gcc/x86_64-linux-gnu/4.7/" cffi:*foreign-library-directories* :test (function equalp))
+(cffi:use-foreign-library "libobjc.so")
+(load "objc.lisp")
+
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+
+  (defparameter *type-map*
+    '((:id . :pointer)
+      (:class . :pointer)
+      (:sel . :pointer)
+      (:imp . :pointer)))
+
+  (defun objc-to-cffi-type (type)
+    (or (cdr (assoc type *type-map*)) type))
+
+  (deftype name () '(or string symbol))
+
+  (defun namep (name)
+    (typecase name
+      (string    name)
+      (symbol    (symbol-name name))
+      (otherwise nil)))
+
+  (defun lisp-to-objc-classname (name)
+    (namep name))
+
+  );eval-when
+
+
+(defmacro define-objc-class (name superclass ivars &rest options)
+  (declare (ignore options))
+  (check-type name name)
+  (check-type superclass name)
+  `(create-objc-class ,(namep name) ,(namep superclass)
+                      ',(mapcar (lambda (ivar)
+                                  (etypecase ivar
+                                    (name
+                                     (list (namep ivar) :pointer))
+                                    (cons
+                                     (check-type (first ivar) name)
+                                     (check-type (second ivar) (or keyword cons))
+                                     (list (namep (first ivar)) (objc-to-cffi-type (second ivar))))))
+                                ivars)))
+
+;; (macroexpand '(define-objc-class |Test| "Object"
+;;    ((i :int)
+;;     (name :string))))
+;; (create-objc-class "Test" "Object" '(("I" :int) ("NAME" :string)))
+
+
+;; (cffi:foreign-type-size :id)
+
+
+(defparameter *nil* (cffi-sys:null-pointer))
+
+(defun get-class-names ()
+  (let ((max (* 128 1024)))
+    (cffi:with-foreign-objects
+     ((classes 'com.informatimago.objc.gnu:class max))
+     (let ((nclasses (com.informatimago.objc.gnu:objc_getclasslist classes max)))
+       (loop :for i :below (min max nclasses)
+             :collect (com.informatimago.objc.gnu:class_getname
+                      (cffi:mem-aref classes 'com.informatimago.objc.gnu:class i)))))))
+
+(defun get-class (name)
+  (com.informatimago.objc.gnu:objc_getclass name))
+
+
+(let ((test1 (com.informatimago.objc.gnu:objc_allocateclasspair *nil* "Test1" 0)))
+  (com.informatimago.objc.gnu:objc_registerclasspair test1)
+  test1)
+
+(get-class "Test1")
+
+
+
+
+;; (get-class "Object") ; #<A Foreign Pointer #x7F1C270E0DC0>
+;; (get-class-names) ; ("NXConstantString" "Object" "Protocol")
+
+;; (objc_allocateClassPair)
+
+
+#-(and)
+(let ((exports '()))
+  (dolist (form (com.informatimago.common-lisp.cesarum.file:sexp-list-file-contents
+                 #P"~/src/public/lisp/objcl/gnu/objc.lisp"))
+    (case (first form)
+      ((in-package defmacro eval-when))
+      ((cffi:defcfun)
+       (destructuring-bind (d (cn ln) &rest r) form
+         (declare (ignore d cn r))
+         (push (symbol-name ln) exports)))
+      ((cffi:defcvar)
+       (destructuring-bind (d (cn ln) &rest r) form
+         (declare (ignore d cn r))
+         (push (symbol-name ln) exports)))
+      ((cffi:defcstruct)
+       (destructuring-bind (d n &rest slots) form
+         (declare (ignore d))
+         (push (symbol-name n) exports)
+         (loop :for (n type) :in slots
+               :do (push (symbol-name n) exports))))
+      ((defconstant cffi:defctype)
+       (push (symbol-name (second form)) exports))
+      (otherwise
+       (if (string= 'defanonenum (first form))
+         (loop :for value :in (rest form)
+               :do (push (symbol-name (if (listp value)
+                                        (first value)
+                                        value)) exports))
+         (print form)))))
+  (sort (remove-duplicates exports :test (function string=))
+        (function string<)))
+
+
+;; (find-package "COM.INFORMATIMAGO.OBJC.GNU")
+
+#||
+
+(cffi:foreign-library-name  *libobjc*)
+(dolist (dir cffi:*FOREIGN-LIBRARY-DIRECTORIES*)
+  (print (merge-pathnames (cffi:foreign-library-pathname *libobjc*) dir)))
+(truename (cffi:foreign-library-pathname *libobjc*))
+
+(dolist (lib (cffi:list-foreign-libraries))
+  (princ-to-string lib))
+(length "LIBOBJC\\.SO.4-8900")
+
+
+||#
+
diff --git a/objcl/gnu/objc.i b/objcl/gnu/objc.i
new file mode 100644
index 0000000..0972591
--- /dev/null
+++ b/objcl/gnu/objc.i
@@ -0,0 +1,11 @@
+%module objc
+// %include </usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/NXConstStr.h>
+// %include </usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/Object.h>
+// %include </usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/Protocol.h>
+%include </usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/message.h>
+%include </usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/objc-decls.h>
+%include </usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/objc-exception.h>
+%include </usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/objc-sync.h>
+%include </usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/objc.h>
+%include </usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/runtime.h>
+%include </usr/lib/gcc/x86_64-linux-gnu/4.7/include/objc/thr.h>
diff --git a/objcl/gnu/objc.lisp b/objcl/gnu/objc.lisp
new file mode 100644
index 0000000..8cede3f
--- /dev/null
+++ b/objcl/gnu/objc.lisp
@@ -0,0 +1,697 @@
+(in-package "COM.INFORMATIMAGO.OBJC.GNU")
+;;; This file was automatically generated by SWIG (http://www.swig.org).
+;;; Version 2.0.7
+;;;
+;;; Do not make changes to this file unless you know what you are doing--modify
+;;; the SWIG interface file instead.
+
+
+;;;SWIG wrapper code starts here
+
+(cl:defmacro defanonenum (cl:&body enums)
+   "Converts anonymous enums to defconstants."
+  `(cl:progn ,@(cl:loop for value in enums
+                        for index = 0 then (cl:1+ index)
+                        when (cl:listp value) do (cl:setf index (cl:second value)
+                                                          value (cl:first value))
+                        collect `(cl:defconstant ,value ,index))))
+
+(cl:eval-when (:compile-toplevel :load-toplevel)
+  (cl:unless (cl:fboundp 'swig-lispify)
+    (cl:defun swig-lispify (name flag cl:&optional (package cl:*package*))
+      (cl:labels ((helper (lst last rest cl:&aux (c (cl:car lst)))
+                    (cl:cond
+                      ((cl:null lst)
+                       rest)
+                      ((cl:upper-case-p c)
+                       (helper (cl:cdr lst) 'upper
+                               (cl:case last
+                                 ((lower digit) (cl:list* c #\- rest))
+                                 (cl:t (cl:cons c rest)))))
+                      ((cl:lower-case-p c)
+                       (helper (cl:cdr lst) 'lower (cl:cons (cl:char-upcase c) rest)))
+                      ((cl:digit-char-p c)
+                       (helper (cl:cdr lst) 'digit
+                               (cl:case last
+                                 ((upper lower) (cl:list* c #\- rest))
+                                 (cl:t (cl:cons c rest)))))
+                      ((cl:char-equal c #\_)
+                       (helper (cl:cdr lst) '_ (cl:cons #\- rest)))
+                      (cl:t
+                       (cl:error "Invalid character: ~A" c)))))
+        (cl:let ((fix (cl:case flag
+                        ((constant enumvalue) "+")
+                        (variable "*")
+                        (cl:t ""))))
+          (cl:intern
+           (cl:concatenate
+            'cl:string
+            fix
+            (cl:nreverse (helper (cl:concatenate 'cl:list name) cl:nil cl:nil))
+            fix)
+           package))))))
+
+;;;SWIG wrapper code ends here
+
+
+(cffi:defcfun ("objc_msg_lookup" objc_msg_lookup) :pointer
+  (receiver :pointer)
+  (op :pointer))
+
+(cffi:defcstruct objc_super
+	(self :pointer)
+	(super_class :pointer))
+
+(cffi:defcfun ("objc_msg_lookup_super" objc_msg_lookup_super) :pointer
+  (super :pointer)
+  (sel :pointer))
+
+(cffi:defcvar ("__objc_msg_forward" __objc_msg_forward)
+ :pointer)
+
+(cffi:defcvar ("__objc_msg_forward2" __objc_msg_forward2)
+ :pointer)
+
+(cffi:defcfun ("objc_exception_throw" objc_exception_throw) :void
+  (exception :pointer))
+
+(cffi:defctype objc_exception_matcher :pointer)
+
+(cffi:defcfun ("objc_setExceptionMatcher" objc_setExceptionMatcher) :pointer
+  (new_matcher :pointer))
+
+(cffi:defctype objc_uncaught_exception_handler :pointer)
+
+(cffi:defcfun ("objc_setUncaughtExceptionHandler" objc_setUncaughtExceptionHandler) :pointer
+  (new_handler :pointer))
+
+(cffi:defcfun ("objc_sync_enter" objc_sync_enter) :int
+  (object :pointer))
+
+(cffi:defcfun ("objc_sync_exit" objc_sync_exit) :int
+  (object :pointer))
+
+(defanonenum
+	(OBJC_SYNC_SUCCESS #.0)
+	(OBJC_SYNC_NOT_OWNING_THREAD_ERROR #.-1)
+	(OBJC_SYNC_TIMED_OUT #.-2)
+	(OBJC_SYNC_NOT_INITIALIZED #.-3))
+
+(cl:defconstant __GNU_LIBOBJC__ 20110608)
+
+(cffi:defctype BOOL :unsigned-char)
+
+(cffi:defctype SEL :pointer)
+
+(cffi:defctype Class :pointer)
+
+(cffi:defcstruct objc_object
+	(class_pointer :pointer))
+
+(cffi:defctype id :pointer)
+
+(cffi:defctype IMP :pointer)
+
+(cffi:defctype Protocol (:struct objc_object))
+
+(cffi:defctype Ivar :pointer)
+
+(cffi:defctype Property :pointer)
+
+(cffi:defctype objc_property_t :pointer)
+
+(cffi:defctype Method :pointer)
+
+(cffi:defctype Category :pointer)
+
+(cffi:defcstruct objc_method_description
+	(name :pointer)
+	(types :string))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+(cl:defconstant _F_CONST #x01)
+
+(cl:defconstant _F_IN #x01)
+
+(cl:defconstant _F_OUT #x02)
+
+(cl:defconstant _F_INOUT #x03)
+
+(cl:defconstant _F_BYCOPY #x04)
+
+(cl:defconstant _F_BYREF #x08)
+
+(cl:defconstant _F_ONEWAY #x10)
+
+(cl:defconstant _F_GCINVISIBLE #x20)
+
+(cffi:defcfun ("object_getClass" object_getClass) :pointer
+  (object :pointer))
+
+(cffi:defcfun ("sel_getName" sel_getName) :string
+  (selector :pointer))
+
+(cffi:defcfun ("sel_getTypeEncoding" sel_getTypeEncoding) :string
+  (selector :pointer))
+
+(cffi:defcfun ("sel_getUid" sel_getUid) :pointer
+  (name :string))
+
+(cffi:defcfun ("sel_registerName" sel_registerName) :pointer
+  (name :string))
+
+(cffi:defcfun ("sel_registerTypedName" sel_registerTypedName) :pointer
+  (name :string)
+  (type :string))
+
+(cffi:defcfun ("sel_isEqual" sel_isEqual) :unsigned-char
+  (first_selector :pointer)
+  (second_selector :pointer))
+
+(cffi:defcfun ("sel_copyTypedSelectorList" sel_copyTypedSelectorList) :pointer
+  (name :string)
+  (numberOfReturnedSelectors :pointer))
+
+(cffi:defcfun ("sel_getTypedSelector" sel_getTypedSelector) :pointer
+  (name :string))
+
+(cffi:defcfun ("class_createInstance" class_createInstance) :pointer
+  (class_ :pointer)
+  (extraBytes :pointer))
+
+(cffi:defcfun ("object_copy" object_copy) :pointer
+  (object :pointer)
+  (extraBytes :pointer))
+
+(cffi:defcfun ("object_dispose" object_dispose) :pointer
+  (object :pointer))
+
+(cffi:defcfun ("object_getClassName" object_getClassName) :string
+  (object :pointer))
+
+(cffi:defcfun ("object_setClass" object_setClass) :pointer
+  (object :pointer)
+  (class_ :pointer))
+
+(cffi:defcfun ("class_getInstanceVariable" class_getInstanceVariable) :pointer
+  (class_ :pointer)
+  (name :string))
+
+(cffi:defcfun ("class_getClassVariable" class_getClassVariable) :pointer
+  (class_ :pointer)
+  (name :string))
+
+(cffi:defcfun ("object_getIndexedIvars" object_getIndexedIvars) :pointer
+  (object :pointer))
+
+(cffi:defcfun ("object_getInstanceVariable" object_getInstanceVariable) :pointer
+  (object :pointer)
+  (name :string)
+  (returnValue :pointer))
+
+(cffi:defcfun ("object_setInstanceVariable" object_setInstanceVariable) :pointer
+  (object :pointer)
+  (name :string)
+  (newValue :pointer))
+
+(cffi:defcfun ("object_getIvar" object_getIvar) :pointer
+  (object :pointer)
+  (variable :pointer))
+
+(cffi:defcfun ("object_setIvar" object_setIvar) :void
+  (object :pointer)
+  (variable :pointer)
+  (value :pointer))
+
+(cffi:defcfun ("ivar_getName" ivar_getName) :string
+  (variable :pointer))
+
+(cffi:defcfun ("ivar_getOffset" ivar_getOffset) :pointer
+  (variable :pointer))
+
+(cffi:defcfun ("ivar_getTypeEncoding" ivar_getTypeEncoding) :string
+  (variable :pointer))
+
+(cffi:defcfun ("class_copyIvarList" class_copyIvarList) :pointer
+  (class_ :pointer)
+  (numberOfReturnedIvars :pointer))
+
+(cffi:defcfun ("class_addIvar" class_addIvar) :unsigned-char
+  (class_ :pointer)
+  (ivar_name :string)
+  (size :pointer)
+  (log_2_of_alignment :unsigned-char)
+  (type :string))
+
+(cffi:defcfun ("property_getName" property_getName) :string
+  (property :pointer))
+
+(cffi:defcfun ("property_getAttributes" property_getAttributes) :string
+  (property :pointer))
+
+(cffi:defcfun ("class_getProperty" class_getProperty) :pointer
+  (class_ :pointer)
+  (propertyName :string))
+
+(cffi:defcfun ("class_copyPropertyList" class_copyPropertyList) :pointer
+  (class_ :pointer)
+  (numberOfReturnedProperties :pointer))
+
+(cffi:defcfun ("class_getIvarLayout" class_getIvarLayout) :string
+  (class_ :pointer))
+
+(cffi:defcfun ("class_getWeakIvarLayout" class_getWeakIvarLayout) :string
+  (class_ :pointer))
+
+(cffi:defcfun ("class_setIvarLayout" class_setIvarLayout) :void
+  (class_ :pointer)
+  (layout :string))
+
+(cffi:defcfun ("class_setWeakIvarLayout" class_setWeakIvarLayout) :void
+  (class_ :pointer)
+  (layout :string))
+
+(cffi:defctype objc_get_unknown_class_handler :pointer)
+
+(cffi:defcfun ("objc_setGetUnknownClassHandler" objc_setGetUnknownClassHandler) :pointer
+  (new_handler :pointer))
+
+(cffi:defcfun ("objc_getClass" objc_getClass) :pointer
+  (name :string))
+
+(cffi:defcfun ("objc_lookUpClass" objc_lookUpClass) :pointer
+  (name :string))
+
+(cffi:defcfun ("objc_getMetaClass" objc_getMetaClass) :pointer
+  (name :string))
+
+(cffi:defcfun ("objc_getRequiredClass" objc_getRequiredClass) :pointer
+  (name :string))
+
+(cffi:defcfun ("objc_getClassList" objc_getClassList) :int
+  (returnValue :pointer)
+  (maxNumberOfClassesToReturn :int))
+
+(cffi:defcfun ("class_getName" class_getName) :string
+  (class_ :pointer))
+
+(cffi:defcfun ("class_isMetaClass" class_isMetaClass) :unsigned-char
+  (class_ :pointer))
+
+(cffi:defcfun ("class_getSuperclass" class_getSuperclass) :pointer
+  (class_ :pointer))
+
+(cffi:defcfun ("class_getVersion" class_getVersion) :int
+  (class_ :pointer))
+
+(cffi:defcfun ("class_setVersion" class_setVersion) :void
+  (class_ :pointer)
+  (version :int))
+
+(cffi:defcfun ("class_getInstanceSize" class_getInstanceSize) :pointer
+  (class_ :pointer))
+
+(cffi:defcfun ("method_setImplementation" method_setImplementation) :pointer
+  (method :pointer)
+  (implementation :pointer))
+
+(cffi:defcfun ("method_exchangeImplementations" method_exchangeImplementations) :void
+  (method_a :pointer)
+  (method_b :pointer))
+
+(cffi:defcfun ("objc_allocateClassPair" objc_allocateClassPair) :pointer
+  (super_class :pointer)
+  (class_name :string)
+  (extraBytes :int))
+
+(cffi:defcfun ("objc_registerClassPair" objc_registerClassPair) :void
+  (class_ :pointer))
+
+(cffi:defcfun ("objc_disposeClassPair" objc_disposeClassPair) :void
+  (class_ :pointer))
+
+(cffi:defcfun ("class_getInstanceMethod" class_getInstanceMethod) :pointer
+  (class_ :pointer)
+  (selector :pointer))
+
+(cffi:defcfun ("class_getClassMethod" class_getClassMethod) :pointer
+  (class_ :pointer)
+  (selector :pointer))
+
+(cffi:defcfun ("class_getMethodImplementation" class_getMethodImplementation) :pointer
+  (class_ :pointer)
+  (selector :pointer))
+
+(cffi:defcfun ("class_respondsToSelector" class_respondsToSelector) :unsigned-char
+  (class_ :pointer)
+  (selector :pointer))
+
+(cffi:defcfun ("class_addMethod" class_addMethod) :unsigned-char
+  (class_ :pointer)
+  (selector :pointer)
+  (implementation :pointer)
+  (method_types :string))
+
+(cffi:defcfun ("class_replaceMethod" class_replaceMethod) :pointer
+  (class_ :pointer)
+  (selector :pointer)
+  (implementation :pointer)
+  (method_types :string))
+
+(cffi:defcfun ("method_getName" method_getName) :pointer
+  (method :pointer))
+
+(cffi:defcfun ("method_getImplementation" method_getImplementation) :pointer
+  (method :pointer))
+
+(cffi:defcfun ("method_getTypeEncoding" method_getTypeEncoding) :string
+  (method :pointer))
+
+(cffi:defcfun ("method_getDescription" method_getDescription) :pointer
+  (method :pointer))
+
+(cffi:defcfun ("class_copyMethodList" class_copyMethodList) :pointer
+  (class_ :pointer)
+  (numberOfReturnedMethods :pointer))
+
+(cffi:defcfun ("method_getNumberOfArguments" method_getNumberOfArguments) :unsigned-int
+  (method :pointer))
+
+(cffi:defcfun ("method_copyReturnType" method_copyReturnType) :string
+  (method :pointer))
+
+(cffi:defcfun ("method_copyArgumentType" method_copyArgumentType) :string
+  (method :pointer)
+  (argumentNumber :unsigned-int))
+
+(cffi:defcfun ("method_getReturnType" method_getReturnType) :void
+  (method :pointer)
+  (returnValue :string)
+  (returnValueSize :pointer))
+
+(cffi:defcfun ("method_getArgumentType" method_getArgumentType) :void
+  (method :pointer)
+  (argumentNumber :unsigned-int)
+  (returnValue :string)
+  (returnValueSize :pointer))
+
+(cffi:defcfun ("objc_getProtocol" objc_getProtocol) :pointer
+  (name :string))
+
+(cffi:defcfun ("objc_copyProtocolList" objc_copyProtocolList) :pointer
+  (numberOfReturnedProtocols :pointer))
+
+(cffi:defcfun ("class_addProtocol" class_addProtocol) :unsigned-char
+  (class_ :pointer)
+  (protocol :pointer))
+
+(cffi:defcfun ("class_conformsToProtocol" class_conformsToProtocol) :unsigned-char
+  (class_ :pointer)
+  (protocol :pointer))
+
+(cffi:defcfun ("class_copyProtocolList" class_copyProtocolList) :pointer
+  (class_ :pointer)
+  (numberOfReturnedProtocols :pointer))
+
+(cffi:defcfun ("protocol_conformsToProtocol" protocol_conformsToProtocol) :unsigned-char
+  (protocol :pointer)
+  (anotherProtocol :pointer))
+
+(cffi:defcfun ("protocol_isEqual" protocol_isEqual) :unsigned-char
+  (protocol :pointer)
+  (anotherProtocol :pointer))
+
+(cffi:defcfun ("protocol_getName" protocol_getName) :string
+  (protocol :pointer))
+
+(cffi:defcfun ("protocol_getMethodDescription" protocol_getMethodDescription)
+              (:pointer (:struct objc_method_description))
+  (protocol :pointer)
+  (selector :pointer)
+  (requiredMethod :unsigned-char)
+  (instanceMethod :unsigned-char))
+
+(cffi:defcfun ("protocol_copyMethodDescriptionList" protocol_copyMethodDescriptionList) :pointer
+  (protocol :pointer)
+  (requiredMethod :unsigned-char)
+  (instanceMethod :unsigned-char)
+  (numberOfReturnedMethods :pointer))
+
+(cffi:defcfun ("protocol_getProperty" protocol_getProperty) :pointer
+  (protocol :pointer)
+  (propertyName :string)
+  (requiredProperty :unsigned-char)
+  (instanceProperty :unsigned-char))
+
+(cffi:defcfun ("protocol_copyPropertyList" protocol_copyPropertyList) :pointer
+  (protocol :pointer)
+  (numberOfReturnedProperties :pointer))
+
+(cffi:defcfun ("protocol_copyProtocolList" protocol_copyProtocolList) :pointer
+  (protocol :pointer)
+  (numberOfReturnedProtocols :pointer))
+
+(cffi:defcvar ("_objc_load_callback" _objc_load_callback)
+ :pointer)
+
+(cffi:defcfun ("objc_enumerationMutation" objc_enumerationMutation) :void
+  (collection :pointer))
+
+(cffi:defcfun ("objc_setEnumerationMutationHandler" objc_setEnumerationMutationHandler) :void
+  (handler :pointer))
+
+(cffi:defcfun ("objc_malloc" objc_malloc) :pointer
+  (size :pointer))
+
+(cffi:defcfun ("objc_atomic_malloc" objc_atomic_malloc) :pointer
+  (size :pointer))
+
+(cffi:defcfun ("objc_realloc" objc_realloc) :pointer
+  (mem :pointer)
+  (size :pointer))
+
+(cffi:defcfun ("objc_calloc" objc_calloc) :pointer
+  (nelem :pointer)
+  (size :pointer))
+
+(cffi:defcfun ("objc_free" objc_free) :void
+  (mem :pointer))
+
+(cffi:defcfun ("class_ivar_set_gcinvisible" class_ivar_set_gcinvisible) :void
+  (_class :pointer)
+  (ivarname :string)
+  (gcInvisible :unsigned-char))
+
+(cffi:defcfun ("objc_sizeof_type" objc_sizeof_type) :int
+  (type :string))
+
+(cffi:defcfun ("objc_alignof_type" objc_alignof_type) :int
+  (type :string))
+
+(cffi:defcfun ("objc_aligned_size" objc_aligned_size) :int
+  (type :string))
+
+(cffi:defcfun ("objc_promoted_size" objc_promoted_size) :int
+  (type :string))
+
+(cffi:defcfun ("objc_skip_type_qualifiers" objc_skip_type_qualifiers) :string
+  (type :string))
+
+(cffi:defcfun ("objc_skip_typespec" objc_skip_typespec) :string
+  (type :string))
+
+(cffi:defcfun ("objc_skip_offset" objc_skip_offset) :string
+  (type :string))
+
+(cffi:defcfun ("objc_skip_argspec" objc_skip_argspec) :string
+  (type :string))
+
+(cffi:defcfun ("objc_get_type_qualifiers" objc_get_type_qualifiers) :unsigned-int
+  (type :string))
+
+(cffi:defcstruct objc_struct_layout
+	(original_type :string)
+	(type :string)
+	(prev_type :string)
+	(record_size :unsigned-int)
+	(record_align :unsigned-int))
+
+(cffi:defcfun ("objc_layout_structure" objc_layout_structure) :void
+  (type :string)
+  (layout :pointer))
+
+(cffi:defcfun ("objc_layout_structure_next_member" objc_layout_structure_next_member) :unsigned-char
+  (layout :pointer))
+
+(cffi:defcfun ("objc_layout_finish_structure" objc_layout_finish_structure) :void
+  (layout :pointer)
+  (size :pointer)
+  (align :pointer))
+
+(cffi:defcfun ("objc_layout_structure_get_info" objc_layout_structure_get_info) :void
+  (layout :pointer)
+  (offset :pointer)
+  (align :pointer)
+  (type :pointer))
+
+(cffi:defcvar ("__objc_thread_exit_status" __objc_thread_exit_status)
+ :int)
+
+(cl:defconstant OBJC_THREAD_INTERACTIVE_PRIORITY 2)
+
+(cl:defconstant OBJC_THREAD_BACKGROUND_PRIORITY 1)
+
+(cl:defconstant OBJC_THREAD_LOW_PRIORITY 0)
+
+(cffi:defctype objc_thread_t :pointer)
+
+(cffi:defcstruct objc_mutex
+	(owner :pointer)
+	(depth :int)
+	(backend :pointer))
+
+(cffi:defctype objc_mutex_t :pointer)
+
+(cffi:defcstruct objc_condition
+	(backend :pointer))
+
+(cffi:defctype objc_condition_t :pointer)
+
+(cffi:defcfun ("objc_mutex_allocate" objc_mutex_allocate) :pointer)
+
+(cffi:defcfun ("objc_mutex_deallocate" objc_mutex_deallocate) :int
+  (mutex :pointer))
+
+(cffi:defcfun ("objc_mutex_lock" objc_mutex_lock) :int
+  (mutex :pointer))
+
+(cffi:defcfun ("objc_mutex_unlock" objc_mutex_unlock) :int
+  (mutex :pointer))
+
+(cffi:defcfun ("objc_mutex_trylock" objc_mutex_trylock) :int
+  (mutex :pointer))
+
+(cffi:defcfun ("objc_condition_allocate" objc_condition_allocate) :pointer)
+
+(cffi:defcfun ("objc_condition_deallocate" objc_condition_deallocate) :int
+  (condition :pointer))
+
+(cffi:defcfun ("objc_condition_wait" objc_condition_wait) :int
+  (condition :pointer)
+  (mutex :pointer))
+
+(cffi:defcfun ("objc_condition_signal" objc_condition_signal) :int
+  (condition :pointer))
+
+(cffi:defcfun ("objc_condition_broadcast" objc_condition_broadcast) :int
+  (condition :pointer))
+
+(cffi:defcfun ("objc_thread_detach" objc_thread_detach) :pointer
+  (selector :pointer)
+  (object :pointer)
+  (argument :pointer))
+
+(cffi:defcfun ("objc_thread_yield" objc_thread_yield) :void)
+
+(cffi:defcfun ("objc_thread_exit" objc_thread_exit) :int)
+
+(cffi:defcfun ("objc_thread_set_priority" objc_thread_set_priority) :int
+  (priority :int))
+
+(cffi:defcfun ("objc_thread_get_priority" objc_thread_get_priority) :int)
+
+(cffi:defcfun ("objc_thread_get_data" objc_thread_get_data) :pointer)
+
+(cffi:defcfun ("objc_thread_set_data" objc_thread_set_data) :int
+  (value :pointer))
+
+(cffi:defcfun ("objc_thread_id" objc_thread_id) :pointer)
+
+(cffi:defcfun ("objc_thread_add" objc_thread_add) :void)
+
+(cffi:defcfun ("objc_thread_remove" objc_thread_remove) :void)
+
+(cffi:defctype objc_thread_callback :pointer)
+
+(cffi:defcfun ("objc_set_thread_callback" objc_set_thread_callback) :pointer
+  (func :pointer))
+
+(cffi:defcfun ("__objc_init_thread_system" __objc_init_thread_system) :int)
+
+
+(cl:defconstant _C_ID #\@)
+(cl:defconstant _C_CLASS #\#)
+(cl:defconstant _C_SEL #\:)
+(cl:defconstant _C_CHR #\c)
+(cl:defconstant _C_UCHR #\C)
+(cl:defconstant _C_SHT #\s)
+(cl:defconstant _C_USHT #\S)
+(cl:defconstant _C_INT #\i)
+(cl:defconstant _C_UINT #\I)
+(cl:defconstant _C_LNG #\l)
+(cl:defconstant _C_ULNG #\L)
+(cl:defconstant _C_LNG_LNG #\q)
+(cl:defconstant _C_ULNG_LNG #\Q)
+(cl:defconstant _C_FLT #\f)
+(cl:defconstant _C_DBL #\d)
+(cl:defconstant _C_LNG_DBL #\D)
+(cl:defconstant _C_BFLD #\b)
+(cl:defconstant _C_BOOL #\B)
+(cl:defconstant _C_VOID #\v)
+(cl:defconstant _C_UNDEF #\?)
+(cl:defconstant _C_PTR #\^)
+(cl:defconstant _C_CHARPTR #\*)
+(cl:defconstant _C_ARY_B #\[)
+(cl:defconstant _C_ARY_E #\])
+(cl:defconstant _C_UNION_B #\()
+(cl:defconstant _C_UNION_E #\))
+(cl:defconstant _C_STRUCT_B #\{)
+(cl:defconstant _C_STRUCT_E #\})
+(cl:defconstant _C_VECTOR #\!)
+(cl:defconstant _C_COMPLEX #\j)
+(cl:defconstant _C_ATOM #\%)
+(cl:defconstant _C_CONST	 #\r)
+(cl:defconstant _C_IN		 #\n)
+(cl:defconstant _C_INOUT	 #\N)
+(cl:defconstant _C_BYCOPY	 #\O)
+(cl:defconstant _C_BYREF	 #\R)
+(cl:defconstant _C_ONEWAY	 #\V)
+(cl:defconstant _C_GCINVISIBLE	 #\|)
ViewGit