diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-12-15 13:22:26 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-12-15 13:22:26 +0300 |
commit | 35fa581403dc056528968234f608c4a7d68da26a (patch) | |
tree | 272e43d74a10b9ed9ddf43351c4407ad5d74e19e /source | |
parent | eac46088e5a63991d2894197bbe14971864541ed (diff) |
BKE_assert(), only prints the error unless cmake define WITH_ASSERT_ABORT is enabled and it will call abort().
made this option advanced so people don't enable along with other features.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_utildefines.h | 35 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 11 |
2 files changed, 44 insertions, 2 deletions
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; |