Thu Jul 2 21:37:42 CEST 2009 Tobias Rautenkranz * Fix potential lisp-object ID generation overflow for excessive lisp-object creation. diff -rN -u old-qt.gui/src/lib/lisp-object.cpp new-qt.gui/src/lib/lisp-object.cpp --- old-qt.gui/src/lib/lisp-object.cpp 2014-10-30 07:45:45.000000000 +0100 +++ new-qt.gui/src/lib/lisp-object.cpp 2014-10-30 07:45:45.000000000 +0100 @@ -29,7 +29,7 @@ /** Constructor. * @param id The ID. */ -lisp_object::data::data(int id) +lisp_object::data::data(unsigned int id) : id(id), is_set(true) { } @@ -61,7 +61,7 @@ /** Constructor. * @param id the ID */ -lisp_object::lisp_object(int id) +lisp_object::lisp_object(unsigned int id) : d(new data(id)) { } @@ -88,7 +88,7 @@ * @param id the ID */ void -lisp_object::set_id(int id) +lisp_object::set_id(unsigned int id) { Q_ASSERT(this->set() ? id != this->id() : true); @@ -121,7 +121,7 @@ * * @return the ID */ -int +unsigned int qt_smoke_lisp_object_id(const void* object) { return static_cast(object)->id(); @@ -135,7 +135,7 @@ * @return @c true when the ID is set and @c false otherwise. */ int -qt_smoke_lisp_object_set(const void* object) +qt_smoke_lisp_object_is_set(const void* object) { return static_cast(object)->set(); } @@ -147,7 +147,7 @@ * @return A new lisp_object instance. */ void* -qt_smoke_make_lisp_object(int id) +qt_smoke_make_lisp_object(unsigned int id) { return new lisp_object(id); } diff -rN -u old-qt.gui/src/lib/lisp-object.h new-qt.gui/src/lib/lisp-object.h --- old-qt.gui/src/lib/lisp-object.h 2014-10-30 07:45:45.000000000 +0100 +++ new-qt.gui/src/lib/lisp-object.h 2014-10-30 07:45:45.000000000 +0100 @@ -13,14 +13,14 @@ CL_SMOKE_QT_EXPORT int qt_smoke_setup_lisp_object(void* destruct); - CL_SMOKE_QT_EXPORT int + CL_SMOKE_QT_EXPORT unsigned int qt_smoke_lisp_object_id(const void* object); CL_SMOKE_QT_EXPORT int - qt_smoke_lisp_object_set(const void* object); + qt_smoke_lisp_object_is_set(const void* object); CL_SMOKE_QT_EXPORT void* - qt_smoke_make_lisp_object(int id); + qt_smoke_make_lisp_object(unsigned int id); CL_SMOKE_QT_EXPORT void* qt_smoke_free_lisp_object(void* object); @@ -35,20 +35,20 @@ class lisp_object { public: - typedef void (*destructor)(int id); + typedef void (*destructor)(unsigned int id); lisp_object(); - lisp_object(int id); + lisp_object(unsigned int id); lisp_object(const lisp_object& other); - inline int + inline unsigned int id() const { Q_ASSERT(this->set()); return d->id; } void - set_id(int id); + set_id(unsigned int id); inline bool set() const @@ -61,9 +61,9 @@ struct data : public QSharedData { data(); - data(int id); + data(unsigned int id); ~data(); - int id; + unsigned int id; bool is_set; private: diff -rN -u old-qt.gui/src/lisp-object.lisp new-qt.gui/src/lisp-object.lisp --- old-qt.gui/src/lisp-object.lisp 2014-10-30 07:45:45.000000000 +0100 +++ new-qt.gui/src/lisp-object.lisp 2014-10-30 07:45:45.000000000 +0100 @@ -4,27 +4,33 @@ "Objects that are currently passed in a C++ class.") (let ((id 0)) + (declare (type (smoke::c-integer :unsigned-int) id)) (defun gen-cxx-lisp-object-id () "Returns a new unique ID." - (incf id))) - + (loop do + (setf id + (logand (1- (expt 2 (* 8 (foreign-type-size :unsigned-int) ))) + (1+ id))) + while (nth-value 1 (gethash id *cxx-lisp-objects*))) + id)) + (defcfun qt-smoke-setup-lisp-object :int (destruct :pointer)) -(defcfun qt-smoke-lisp-object-id :int +(defcfun qt-smoke-lisp-object-id :unsigned-int (object :pointer)) -(defcfun qt-smoke-lisp-object-set :int +(defcfun qt-smoke-lisp-object-is-set :int (object :pointer)) (defcfun qt-smoke-make-lisp-object :pointer - (id :int)) + (id :unsigned-int)) (defcfun qt-smoke-free-lisp-object :void (object :pointer)) (defcallback destruct-cxx-lisp-object :void - ((id :int)) + ((id :unsigned-int)) (remhash id *cxx-lisp-objects*)) (defvar *cxx-lisp-object-metatype* "Metatype ID of the C++ lisp_object.")