diff options
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_utildefines.h | 35 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 11 |
3 files changed, 51 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ccfb12b7ff..03a61a1a316 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,9 @@ option(WITH_PYTHON_INSTALL "Copy system python into the blender install fo option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking" OFF) mark_as_advanced(WITH_CXX_GUARDEDALLOC) +option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BKE_assert()" OFF) +mark_as_advanced(WITH_ASSERT_ABORT) + if(APPLE) option(WITH_COCOA "Use Cocoa framework instead of deprecated Carbon" ON) option(USE_QTKIT "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF) @@ -1011,6 +1014,10 @@ if(WITH_CXX_GUARDEDALLOC) set(CMAKE_CXX_FLAGS " -DWITH_CXX_GUARDEDALLOC -I${CMAKE_SOURCE_DIR}/intern/guardedalloc ${CMAKE_CXX_FLAGS}") endif() +if(WITH_ASSERT_ABORT) + add_definitions(-DWITH_ASSERT_ABORT) +endif() + #----------------------------------------------------------------------------- # Libraries diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h index a1968459fd6..605a50e078b 100644 --- a/source/blender/blenkernel/BKE_utildefines.h +++ b/source/blender/blenkernel/BKE_utildefines.h @@ -54,6 +54,41 @@ # define UNUSED(x) UNUSED_ ## x #endif + +/* BKE_assert(), default only to print + * for aborting need to define WITH_ASSERT_ABORT */ +#if !defined NDEBUG +# ifdef WITH_ASSERT_ABORT +# define _dummy_abort abort +# else +# define _dummy_abort() (void)0 +# endif +# ifdef __GNUC__ /* just want to check if __func__ is available */ +# define BKE_assert(a) \ +do { \ + if (0 == (a)) { \ + fprintf(stderr, \ + "BKE_assert failed: %s, %s(), %d at \'%s\'\n", \ + __FILE__, __func__, __LINE__, STRINGIFY(a)); \ + _dummy_abort(); \ + } \ +} while (0) +# else +# define BKE_assert(a) \ +do { \ + if (0 == (a)) { \ + fprintf(stderr, \ + "BKE_assert failed: %s, %d at \'%s\'\n", \ + __FILE__, __LINE__, STRINGIFY(a)); \ + _dummy_abort(); \ + } \ +} while (0) +# endif +#else +# define BKE_assert(a) (void)0 +#endif + + /* these values need to be hardcoded in structs, dna does not recognize defines */ /* also defined in DNA_space_types.h */ #ifndef FILE_MAXDIR diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index c1bd2d87d7f..2463041cda8 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -72,7 +72,7 @@ static int rna_id_write_error(PointerRNA *ptr, PyObject *key) else pyname= "<UNKNOWN>"; /* make a nice string error */ - assert(idtype != NULL); + BKE_assert(idtype != NULL); PyErr_Format(PyExc_RuntimeError, "Writing to ID classes in this context is not allowed: %.200s, %.200s datablock, error setting %.200s.%.200s", id->name+2, idtype, RNA_struct_identifier(ptr->type), pyname); return TRUE; @@ -1544,7 +1544,8 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po break; } default: - /* probably will never happen */ + BKE_assert(!"Invalid array type"); + PyErr_SetString(PyExc_TypeError, "not an array type"); Py_DECREF(list); list= NULL; @@ -2678,6 +2679,8 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname ) break; default: /* should never happen */ + BKE_assert(!"Invalid context type"); + PyErr_Format(PyExc_AttributeError, "bpy_struct: Context type invalid %d, can't get \"%.200s\" from context", newtype, name); ret= NULL; } @@ -3306,6 +3309,7 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) break; case PROP_RAW_UNSET: /* should never happen */ + BKE_assert(!"Invalid array type - set"); break; } @@ -3360,6 +3364,7 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) break; case PROP_RAW_UNSET: /* should never happen */ + BKE_assert(!"Invalid array type - get"); break; } @@ -3717,6 +3722,8 @@ static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw) void *retdata_single= NULL; /* Should never happen but it does in rare cases */ + BKE_assert(self_ptr != NULL); + if(self_ptr==NULL) { PyErr_SetString(PyExc_RuntimeError, "rna functions internal rna pointer is NULL, this is a bug. aborting"); return NULL; |