Fri Feb 19 22:10:24 CET 2010 Tobias Rautenkranz * No need to construct a SmokeBinding per Smoke module. diff -rN -u old-smoke/src/bindings.lisp new-smoke/src/bindings.lisp --- old-smoke/src/bindings.lisp 2014-10-18 03:30:01.000000000 +0200 +++ new-smoke/src/bindings.lisp 2014-10-18 03:30:01.000000000 +0200 @@ -5,11 +5,8 @@ (pointer (null-pointer) :type foreign-pointer) (length 0 :type (smoke-index 0))) - (defstruct smoke-module (pointer (null-pointer) :type foreign-pointer) - (binding (null-pointer) :type foreign-pointer) - (no-dispatch-binding (null-pointer) :type foreign-pointer) (classes (make-smoke-array) :type smoke-array) (methods (make-smoke-array) :type smoke-array) diff -rN -u old-smoke/src/clos.lisp new-smoke/src/clos.lisp --- old-smoke/src/clos.lisp 2014-10-18 03:30:01.000000000 +0200 +++ new-smoke/src/clos.lisp 2014-10-18 03:30:01.000000000 +0200 @@ -337,8 +337,7 @@ ;; Receive virtual function calls. (defcallback dispatch-method :boolean - ((binding :pointer) - (method smoke-index) + ((method smoke-index) (object-ptr :pointer) (stack smoke-stack) (abstract :boolean)) @@ -349,9 +348,7 @@ ;; the finalizer. Thus OBJECT might be NIL. (unless (null object) (let* ((method (make-smoke-method - :smoke (gethash (pointer-address - (smoke-get-smoke binding)) - *smoke-modules*) + :smoke (smoke (class-of object)) :id method))) (loop (restart-case diff -rN -u old-smoke/src/libsmoke/smoke.cpp new-smoke/src/libsmoke/smoke.cpp --- old-smoke/src/libsmoke/smoke.cpp 2014-10-18 03:30:01.000000000 +0200 +++ new-smoke/src/libsmoke/smoke.cpp 2014-10-18 03:30:01.000000000 +0200 @@ -12,18 +12,6 @@ extern "C" { -/** Returns the Smoke module of a Smoke binding. - * @related cl_smoke::Binding - * @param binding the Binding - * - * @return the Smoke module - */ -CL_SMOKE_EXPORT void* -cl_smoke_get_smoke(smoke_binding binding) -{ - return static_cast(binding)->get_smoke(); -} - /** Creates a new Smoke binding. * The binding is allocated on the heap an can be freed with smoke_destruct(). * When method dispatching is not needed, a null pointer can be passed for @a dispatch. @@ -37,14 +25,12 @@ * @return a pointer to a new Smoke binding. */ CL_SMOKE_EXPORT smoke_binding -cl_smoke_construct_binding(void* smoke, void* destruct, void* dispatch) +cl_smoke_construct_binding(void* destruct, void* dispatch) { if (NULL == dispatch) - return new NoDispatchBinding(static_cast(smoke), - reinterpret_cast(destruct)); + return new NoDispatchBinding(reinterpret_cast(destruct)); else - return new Binding(static_cast(smoke), - reinterpret_cast(destruct), + return new Binding(reinterpret_cast(destruct), reinterpret_cast(dispatch)); } @@ -198,7 +184,7 @@ /** Finds a method of a class. * @param m pointer to write the result to - * @param smoke the smoke binding + * @param smoke the smoke module * @param class_index index of the class * @param method_name method name */ diff -rN -u old-smoke/src/libsmoke/smoke.lisp new-smoke/src/libsmoke/smoke.lisp --- old-smoke/src/libsmoke/smoke.lisp 2014-10-18 03:30:01.000000000 +0200 +++ new-smoke/src/libsmoke/smoke.lisp 2014-10-18 03:30:01.000000000 +0200 @@ -38,7 +38,6 @@ `(integer ,lower ,upper)) (defcfun (smoke-construct-binding "cl_smoke_construct_binding") smoke-binding - (smoke :pointer) (destruct :pointer) (dispatch :pointer)) @@ -51,10 +50,6 @@ (smoke :pointer) (index smoke-index)) -(declaim (inline smoke-get-smoke)) -(defcfun (smoke-get-smoke "cl_smoke_get_smoke") :pointer - (smoke-binding smoke-binding)) - (defcfun (smoke-get-module-name "cl_smoke_get_module_name") :string (smoke :pointer)) diff -rN -u old-smoke/src/libsmoke/smokebinding.cpp new-smoke/src/libsmoke/smokebinding.cpp --- old-smoke/src/libsmoke/smokebinding.cpp 2014-10-18 03:30:01.000000000 +0200 +++ new-smoke/src/libsmoke/smokebinding.cpp 2014-10-18 03:30:01.000000000 +0200 @@ -23,11 +23,10 @@ */ /** Constructor. - * @param smoke the Smoke module * @param destruct destruct callback */ -NoDispatchBinding::NoDispatchBinding(Smoke *smoke, destructed destruct) - : SmokeBinding(smoke), +NoDispatchBinding::NoDispatchBinding(destructed destruct) + : SmokeBinding(NULL), destruct(destruct) { Q_ASSERT(destruct); @@ -55,8 +54,7 @@ char* NoDispatchBinding::className(Smoke::Index classId) { - Q_ASSERT(classId >= 0 && classId <= smoke->numClasses); - return const_cast(smoke->classes[classId].className); + qFatal("className() Not implemented"); } /** @function NoDispatchBinding::get_smoke() @@ -82,13 +80,11 @@ */ /** Constructor. - * @param smoke the Smoke module * @param destruct destruct callback * @param dispatch method dispatch callback */ -Binding::Binding(Smoke *smoke, destructed destruct, - dispatch_method dispatch) - : NoDispatchBinding(smoke, destruct), +Binding::Binding(destructed destruct, dispatch_method dispatch) + : NoDispatchBinding(destruct), dispatch(dispatch) { Q_ASSERT(dispatch); @@ -100,7 +96,7 @@ Binding::callMethod(Smoke::Index method, void* object, Smoke::Stack stack, bool abstract) { - int ret = dispatch(this, method, object, stack, abstract); + int ret = dispatch(method, object, stack, abstract); Q_ASSERT( !abstract || ret ); return ret; diff -rN -u old-smoke/src/libsmoke/smokebinding.h new-smoke/src/libsmoke/smokebinding.h --- old-smoke/src/libsmoke/smokebinding.h 2014-10-18 03:30:01.000000000 +0200 +++ new-smoke/src/libsmoke/smokebinding.h 2014-10-18 03:30:01.000000000 +0200 @@ -11,7 +11,7 @@ public: typedef void (*destructed)(void* object); - NoDispatchBinding(Smoke *smoke, destructed destruct); + NoDispatchBinding(destructed destruct); virtual void deleted(Smoke::Index classId, void *object); @@ -23,10 +23,6 @@ virtual char* className(Smoke::Index classId); - Smoke* - get_smoke() const - { return smoke; } - private: const destructed destruct; }; @@ -34,10 +30,10 @@ class Binding : public NoDispatchBinding { public: - typedef int (*dispatch_method)(Binding* binding, Smoke::Index method, + typedef int (*dispatch_method)(Smoke::Index method, void* object, Smoke::Stack args, int abstract); - Binding(Smoke *smoke, destructed destruct, dispatch_method dispatch); + Binding(destructed destruct, dispatch_method dispatch); virtual bool diff -rN -u old-smoke/src/smoke.lisp new-smoke/src/smoke.lisp --- old-smoke/src/smoke.lisp 2014-10-18 03:30:01.000000000 +0200 +++ new-smoke/src/smoke.lisp 2014-10-18 03:30:01.000000000 +0200 @@ -79,6 +79,14 @@ (pointer object))) (setf (slot-value object 'pointer) (null-pointer))) +(eval-startup (:load-toplevel :execute) + (defparameter *binding* (smoke-construct-binding + (callback destructed) + (callback dispatch-method))) + (defparameter *no-dispatch-binding* (smoke-construct-binding + (callback destructed) + (null-pointer)))) + (defun set-binding (object) "Sets the Smoke binding for OBJECT, that receives its callbacks." (declare (optimize (speed 3))) @@ -87,8 +95,8 @@ (setf (foreign-slot-value (mem-aref stack 'smoke-stack-item 1) 'smoke-stack-item 'voidp) (if (typep class 'cxx:class) - (smoke-module-binding (smoke class)) - (smoke-module-no-dispatch-binding (smoke class)))) + *binding* + *no-dispatch-binding*)) (foreign-funcall-pointer (foreign-slot-value (smoke-class-pointer class) 'smoke-class 'class-function) @@ -101,16 +109,10 @@ (defun init (smoke module) "Returns the a new Smoke binding for the Smoke module SMOKE." (use-foreign-library libclsmoke) - (let ((no-dispatch-binding - (smoke-construct-binding smoke (callback destructed) (null-pointer))) - (binding (smoke-construct-binding smoke (callback destructed) - (callback dispatch-method)))) - (setf (smoke-module-pointer module) smoke - (smoke-module-no-dispatch-binding module) no-dispatch-binding - (smoke-module-binding module) binding) - (init-smoke-module module) - (setf (gethash (pointer-address smoke) *smoke-modules*) module) - module)) + (setf (smoke-module-pointer module) smoke) + (init-smoke-module module) + (setf (gethash (pointer-address smoke) *smoke-modules*) module) + module) (let ((pointer-symbol-map (make-hash-table))) ;; Used by make-load-form for enums to reference the smoke module.