Revision: 33682
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33682
Author:   campbellbarton
Date:     2010-12-15 11:22:26 +0100 (Wed, 15 Dec 2010)

Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/CMakeLists.txt
    trunk/blender/source/blender/blenkernel/BKE_utildefines.h
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/CMakeLists.txt
===================================================================
--- trunk/blender/CMakeLists.txt        2010-12-15 08:42:37 UTC (rev 33681)
+++ trunk/blender/CMakeLists.txt        2010-12-15 10:22:26 UTC (rev 33682)
@@ -128,6 +128,9 @@
 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 @@
        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
 

Modified: trunk/blender/source/blender/blenkernel/BKE_utildefines.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_utildefines.h   2010-12-15 
08:42:37 UTC (rev 33681)
+++ trunk/blender/source/blender/blenkernel/BKE_utildefines.h   2010-12-15 
10:22:26 UTC (rev 33682)
@@ -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

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c        2010-12-15 
08:42:37 UTC (rev 33681)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c        2010-12-15 
10:22:26 UTC (rev 33682)
@@ -72,7 +72,7 @@
                        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 @@
                                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 @@
                                        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 @@
                                        break;
                                case PROP_RAW_UNSET:
                                        /* should never happen */
+                                       BKE_assert(!"Invalid array type - set");
                                        break;
                                }
 
@@ -3360,6 +3364,7 @@
                                        break;
                                case PROP_RAW_UNSET:
                                        /* should never happen */
+                                       BKE_assert(!"Invalid array type - get");
                                        break;
                                }
 
@@ -3717,6 +3722,8 @@
        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;


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to