From 8d05ef3022aa91c629e3cc0582e141180639f44e Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 3 Jun 2016 22:23:42 +0200 Subject: [PATCH] Assorted fixes --- dtool/src/dtoolbase/pdtoa.cxx | 2 +- .../interfaceMakerPythonNative.cxx | 2 +- dtool/src/interrogatedb/py_panda.cxx | 2 -- makepanda/makepandacore.py | 11 +++++--- panda/src/egg/eggCompositePrimitive.h | 2 +- panda/src/express/pointerTo.I | 4 +-- panda/src/express/pointerTo.h | 6 +++-- panda/src/express/pointerToBase.I | 26 ++++++++++++++++--- panda/src/express/pointerToBase.h | 1 + panda/src/pnmimagetypes/pnmFileTypeStbImage.h | 2 -- panda/src/putil/buttonHandle.I | 10 ------- panda/src/putil/buttonHandle.h | 6 ++++- panda/src/putil/pythonCallbackObject.cxx | 6 +++-- panda/src/putil/pythonCallbackObject.h | 2 ++ panda/src/recorder/mouseRecorder.h | 1 + panda/src/recorder/recorderBase.h | 1 + panda/src/recorder/socketStreamRecorder.h | 1 + 17 files changed, 55 insertions(+), 30 deletions(-) diff --git a/dtool/src/dtoolbase/pdtoa.cxx b/dtool/src/dtoolbase/pdtoa.cxx index a2778dc962..47aa2db50a 100644 --- a/dtool/src/dtoolbase/pdtoa.cxx +++ b/dtool/src/dtoolbase/pdtoa.cxx @@ -250,7 +250,7 @@ inline static unsigned CountDecimalDigit32(uint32_t n) { } inline static void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) { - static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; + static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 0, 0, 0, 0, 0 }; const DiyFp one(uint64_t(1) << -Mp.e, Mp.e); const DiyFp wp_w = Mp - W; uint32_t p1 = static_cast(Mp.f >> -one.e); diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index e6bcf05d14..d6860f5d23 100644 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -6262,7 +6262,7 @@ write_getset(ostream &out, Object *obj, Property *property) { out << " " << cClassName << " *local_this = NULL;\n" " if (!Dtool_Call_ExtractThisPointer(self, Dtool_" << ClassName << ", (void **)&local_this)) {\n" - " return NULL;\n" + " return -1;\n" " }\n" " return (Py_ssize_t)" << len_remap->get_call_str("local_this", pexprs) << ";\n"; } else { diff --git a/dtool/src/interrogatedb/py_panda.cxx b/dtool/src/interrogatedb/py_panda.cxx index c12734813f..a25a5c614b 100644 --- a/dtool/src/interrogatedb/py_panda.cxx +++ b/dtool/src/interrogatedb/py_panda.cxx @@ -172,7 +172,6 @@ void *DTOOL_Call_GetPointerThis(PyObject *self) { return NULL; } -#ifndef NDEBUG /** * This is similar to a PyErr_Occurred() check, except that it also checks * Notify to see if an assertion has occurred. If that is the case, then it @@ -193,7 +192,6 @@ bool _Dtool_CheckErrorOccurred() { } return false; } -#endif // NDEBUG /** * Raises an AssertionError containing the last thrown assert message, and diff --git a/makepanda/makepandacore.py b/makepanda/makepandacore.py index 6ee5748d38..1b87ed7c9d 100644 --- a/makepanda/makepandacore.py +++ b/makepanda/makepandacore.py @@ -16,10 +16,10 @@ else: import cPickle as pickle import thread -SUFFIX_INC = [".cxx",".c",".h",".I",".yxx",".lxx",".mm",".rc",".r"] +SUFFIX_INC = [".cxx",".cpp",".c",".h",".I",".yxx",".lxx",".mm",".rc",".r"] SUFFIX_DLL = [".dll",".dlo",".dle",".dli",".dlm",".mll",".exe",".pyd",".ocx"] SUFFIX_LIB = [".lib",".ilb"] -VCS_DIRS = set(["CVS", "CVSROOT", ".git", ".hg"]) +VCS_DIRS = set(["CVS", "CVSROOT", ".git", ".hg", "__pycache__"]) VCS_FILES = set([".cvsignore", ".gitignore", ".gitmodules", ".hgignore"]) STARTTIME = time.time() MAINTHREAD = threading.currentThread() @@ -1392,7 +1392,12 @@ def PkgConfigGetDefSymbols(pkgname, tool = "pkg-config"): for l in result.split(" "): if (l.startswith("-D")): d = l.replace("-D", "").replace("\"", "").strip().split("=") - if (len(d) == 1): + + if d[0] in ('NDEBUG', '_DEBUG'): + # Setting one of these flags by accident could cause serious harm. + if GetVerbose(): + print("Ignoring %s flag provided by %s" % (l, tool)) + elif len(d) == 1: defs[d[0]] = "" else: defs[d[0]] = d[1] diff --git a/panda/src/egg/eggCompositePrimitive.h b/panda/src/egg/eggCompositePrimitive.h index 43d25052ea..b816d816c7 100644 --- a/panda/src/egg/eggCompositePrimitive.h +++ b/panda/src/egg/eggCompositePrimitive.h @@ -38,7 +38,7 @@ PUBLISHED: MAKE_SEQ(get_components, get_num_components, get_component); INLINE void set_component(int i, const EggAttributes *attrib); - MAKE_PROPERTY(components, get_num_components, get_component, set_component); + MAKE_SEQ_PROPERTY(components, get_num_components, get_component, set_component); INLINE bool triangulate_into(EggGroupNode *container) const; PT(EggCompositePrimitive) triangulate_in_place(); diff --git a/panda/src/express/pointerTo.I b/panda/src/express/pointerTo.I index b44f4f4ded..a3d842e374 100644 --- a/panda/src/express/pointerTo.I +++ b/panda/src/express/pointerTo.I @@ -15,7 +15,7 @@ * */ template -INLINE PointerTo:: +ALWAYS_INLINE PointerTo:: PointerTo(To *ptr) : PointerToBase(ptr) { } @@ -136,7 +136,7 @@ operator = (const PointerTo ©) { * */ template -INLINE ConstPointerTo:: +ALWAYS_INLINE ConstPointerTo:: ConstPointerTo(const TYPENAME ConstPointerTo::To *ptr) : PointerToBase((TYPENAME ConstPointerTo::To *)ptr) { diff --git a/panda/src/express/pointerTo.h b/panda/src/express/pointerTo.h index 315cdaf2ca..50634f6473 100644 --- a/panda/src/express/pointerTo.h +++ b/panda/src/express/pointerTo.h @@ -58,7 +58,8 @@ class PointerTo : public PointerToBase { public: typedef TYPENAME PointerToBase::To To; PUBLISHED: - INLINE PointerTo(To *ptr = (To *)NULL); + ALWAYS_INLINE PointerTo() DEFAULT_CTOR; + ALWAYS_INLINE PointerTo(To *ptr); INLINE PointerTo(const PointerTo ©); INLINE ~PointerTo(); @@ -119,7 +120,8 @@ class ConstPointerTo : public PointerToBase { public: typedef TYPENAME PointerToBase::To To; PUBLISHED: - INLINE ConstPointerTo(const To *ptr = (const To *)NULL); + ALWAYS_INLINE ConstPointerTo() DEFAULT_CTOR; + ALWAYS_INLINE ConstPointerTo(const To *ptr); INLINE ConstPointerTo(const PointerTo ©); INLINE ConstPointerTo(const ConstPointerTo ©); INLINE ~ConstPointerTo(); diff --git a/panda/src/express/pointerToBase.I b/panda/src/express/pointerToBase.I index 20cac87718..296dc5d3bb 100644 --- a/panda/src/express/pointerToBase.I +++ b/panda/src/express/pointerToBase.I @@ -17,7 +17,15 @@ template INLINE PointerToBase:: PointerToBase(To *ptr) { - reassign(ptr); + _void_ptr = (void *)ptr; + if (ptr != (To *)NULL) { + ptr->ref(); +#ifdef DO_MEMORY_USAGE + if (MemoryUsage::get_track_memory_usage()) { + update_type(ptr); + } +#endif + } } /** @@ -26,7 +34,16 @@ PointerToBase(To *ptr) { template INLINE PointerToBase:: PointerToBase(const PointerToBase ©) { - reassign(copy); + _void_ptr = copy._void_ptr; + if (_void_ptr != NULL) { + To *ptr = (To *)_void_ptr; + ptr->ref(); +#ifdef DO_MEMORY_USAGE + if (MemoryUsage::get_track_memory_usage()) { + update_type(ptr); + } +#endif + } } /** @@ -35,7 +52,10 @@ PointerToBase(const PointerToBase ©) { template INLINE PointerToBase:: ~PointerToBase() { - reassign((To *)NULL); + if (_void_ptr != NULL) { + unref_delete((To *)_void_ptr); + _void_ptr = NULL; + } } #ifdef USE_MOVE_SEMANTICS diff --git a/panda/src/express/pointerToBase.h b/panda/src/express/pointerToBase.h index 3380322e4a..cbafa5587b 100644 --- a/panda/src/express/pointerToBase.h +++ b/panda/src/express/pointerToBase.h @@ -31,6 +31,7 @@ public: typedef T To; protected: + ALWAYS_INLINE PointerToBase() DEFAULT_CTOR; INLINE PointerToBase(To *ptr); INLINE PointerToBase(const PointerToBase ©); INLINE ~PointerToBase(); diff --git a/panda/src/pnmimagetypes/pnmFileTypeStbImage.h b/panda/src/pnmimagetypes/pnmFileTypeStbImage.h index 8d53921064..08cf62e247 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeStbImage.h +++ b/panda/src/pnmimagetypes/pnmFileTypeStbImage.h @@ -22,8 +22,6 @@ #include "pnmReader.h" #include "pnmWriter.h" -#include "stb_image.h" - /** * For reading images via the public domain stb_image.h library. This is used * when compiling without support for more specific libraries that are more diff --git a/panda/src/putil/buttonHandle.I b/panda/src/putil/buttonHandle.I index 40e157baa8..5701ccb395 100644 --- a/panda/src/putil/buttonHandle.I +++ b/panda/src/putil/buttonHandle.I @@ -11,16 +11,6 @@ * @date 2000-03-01 */ -/** - * The default constructor must do nothing, because we can't guarantee - * ordering of static initializers. If the constructor tried to initialize - * its value, it might happen after the value had already been set previously - * by another static initializer! - */ -INLINE ButtonHandle:: -ButtonHandle() { -} - /** * Constructs a ButtonHandle with the corresponding index number, which may * have been returned by an earlier call to ButtonHandle::get_index(). diff --git a/panda/src/putil/buttonHandle.h b/panda/src/putil/buttonHandle.h index d4961f8b50..d2b97be36a 100644 --- a/panda/src/putil/buttonHandle.h +++ b/panda/src/putil/buttonHandle.h @@ -25,7 +25,11 @@ */ class EXPCL_PANDA_PUTIL ButtonHandle FINAL { PUBLISHED: - INLINE ButtonHandle(); + // The default constructor must do nothing, because we can't guarantee + // ordering of static initializers. If the constructor tried to initialize + // its value, it might happen after the value had already been set + // previously by another static initializer! + INLINE ButtonHandle() DEFAULT_CTOR; CONSTEXPR ButtonHandle(int index); INLINE ButtonHandle(const ButtonHandle ©); ButtonHandle(const string &name); diff --git a/panda/src/putil/pythonCallbackObject.cxx b/panda/src/putil/pythonCallbackObject.cxx index f78121630f..0679a4c473 100644 --- a/panda/src/putil/pythonCallbackObject.cxx +++ b/panda/src/putil/pythonCallbackObject.cxx @@ -126,8 +126,10 @@ do_python_callback(CallbackData *cbdata) { Py_DECREF(args); if (result == (PyObject *)NULL) { - util_cat.error() - << "Exception occurred in " << *this << "\n"; + if (PyErr_Occurred() != PyExc_SystemExit) { + util_cat.error() + << "Exception occurred in " << *this << "\n"; + } } else { Py_DECREF(result); } diff --git a/panda/src/putil/pythonCallbackObject.h b/panda/src/putil/pythonCallbackObject.h index a34b1ceecb..d7757813db 100644 --- a/panda/src/putil/pythonCallbackObject.h +++ b/panda/src/putil/pythonCallbackObject.h @@ -34,6 +34,8 @@ PUBLISHED: void set_function(PyObject *function); PyObject *get_function(); + MAKE_PROPERTY(function, get_function, set_function); + public: virtual void do_callback(CallbackData *cbdata); diff --git a/panda/src/recorder/mouseRecorder.h b/panda/src/recorder/mouseRecorder.h index b26b9e76a6..b97df0b7ed 100644 --- a/panda/src/recorder/mouseRecorder.h +++ b/panda/src/recorder/mouseRecorder.h @@ -77,6 +77,7 @@ public: virtual void write_datagram(BamWriter *manager, Datagram &dg); virtual void write_recorder(BamWriter *manager, Datagram &dg); + INLINE virtual int get_ref_count() const FINAL { return ReferenceCount::get_ref_count(); }; INLINE virtual void ref() const FINAL { ReferenceCount::ref(); }; INLINE virtual bool unref() const FINAL { return ReferenceCount::unref(); }; diff --git a/panda/src/recorder/recorderBase.h b/panda/src/recorder/recorderBase.h index 816f74030d..65044424d5 100644 --- a/panda/src/recorder/recorderBase.h +++ b/panda/src/recorder/recorderBase.h @@ -61,6 +61,7 @@ public: // We can't let RecorderBase inherit from ReferenceCount, so we define these // so we can still manage the reference count. + virtual int get_ref_count() const=0; virtual void ref() const=0; virtual bool unref() const=0; diff --git a/panda/src/recorder/socketStreamRecorder.h b/panda/src/recorder/socketStreamRecorder.h index 09513a0c54..26f39047c4 100644 --- a/panda/src/recorder/socketStreamRecorder.h +++ b/panda/src/recorder/socketStreamRecorder.h @@ -74,6 +74,7 @@ public: static void register_with_read_factory(); virtual void write_recorder(BamWriter *manager, Datagram &dg); + INLINE virtual int get_ref_count() const FINAL { return ReferenceCount::get_ref_count(); }; INLINE virtual void ref() const FINAL { ReferenceCount::ref(); }; INLINE virtual bool unref() const FINAL { return ReferenceCount::unref(); };