- rna bugfix where ints were not clamped and would overflow, now raise an error and...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 3 Oct 2010 01:44:00 +0000 (01:44 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 3 Oct 2010 01:44:00 +0000 (01:44 +0000)
- fixed WM_OT_context_cycle_int was causing problems with int overflow, now it cycles properly.
- rename QUOTE macro to STRINGIFY_ARG, and added STRINGIFY, which is used more often since it gives the value as a string.

release/scripts/op/wm.py
source/blender/blenkernel/BKE_utildefines.h
source/blender/editors/space_view3d/view3d_view.c
source/blender/makesrna/intern/rna_nodetree.c
source/blender/python/intern/bpy_props.c
source/blender/python/intern/bpy_rna.c
source/blender/windowmanager/intern/wm_operators.c
source/creator/buildinfo.c
source/creator/creator.c

index 958fdeb3df62ad71832881301012f383908ebeba..60a963804a681a86d3aa9824cdd3201c824a534e 100644 (file)
@@ -266,9 +266,9 @@ class WM_OT_context_cycle_int(bpy.types.Operator):
         if value != eval("context.%s" % data_path):
             # relies on rna clamping int's out of the range
             if self.reverse:
-                value = (1 << 32)
+                value = (1 << 31) - 1
             else:
-                value = - (1 << 32)
+                value = -1 << 31
 
             exec("context.%s=value" % data_path)
 
index 925b1d7171af817d59a5ed66788d6cc876f4a4d3..5a6a151afee7cbcca3a4a588a5f0d1b27e9b7e6f 100644 (file)
 #define TRUE 1
 #endif
 
-/* Macro to convert a value to string in the preprocessor */
-#define QUOTE(x) #x
+/* Macro to convert a value to string in the preprocessor
+ * STRINGIFY_ARG: gives the defined name in the string
+ * STRINGIFY: gives the defined value. */
+#define STRINGIFY_ARG(x) #x
+#define STRINGIFY(x) STRINGIFY_ARG(x)
 
 /* these values need to be hardcoded in structs, dna does not recognize defines */
 /* also defined in DNA_space_types.h */
index ebfa77a4a15a4de440a542f9d24e9e9332ebc320..d66144b2c30afe83a2b9659d6bb80f349535c20d 100644 (file)
@@ -2177,15 +2177,6 @@ static int flyEnd(bContext *C, FlyInfo *fly)
                        object_mat3_to_rot(v3d->camera, mat3, TRUE);
                        DAG_id_flush_update(&v3d->camera->id, OB_RECALC_OB);
                }
-
-#if 0 //XXX2.5
-               if (IS_AUTOKEY_MODE(NORMAL)) {
-                       allqueue(REDRAWIPO, 0);
-                       allspace(REMAKEIPO, 0);
-                       allqueue(REDRAWNLA, 0);
-                       allqueue(REDRAWTIME, 0);
-               }
-#endif
        }
        else { /* not camera */
                /* Apply the fly mode view */
index 36385759c5a21405123657a98a544351689683d6..a97033200de78650d56a6ec13a80852329009b01 100644 (file)
@@ -515,15 +515,12 @@ static void init(void)
 {
        memset(nodes, 0, sizeof nodes);
        
-       #define Str(x) #x
-       
        #define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
-               reg_node(ID, Category_##Category, EnumName, Str(Category##StructName), #Category, UIName, UIDesc);
+               reg_node(ID, Category_##Category, EnumName, STRINGIFY_ARG(Category##StructName), #Category, UIName, UIDesc);
                
        #include "rna_nodetree_types.h"
        
        #undef DefNode
-       #undef Str
        
        reg_node(NODE_GROUP, Category_GroupNode, "GROUP", "NodeGroup", "Node", "Group", "");
 }
index 104027c099767f1d71ebf525d716fa24a5203c2e..ec5bb595810eeed9a77212ba25eac0a6b1769df3 100644 (file)
@@ -246,7 +246,7 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
                }
 
                if(size < 1 || size > PYRNA_STACK_ARRAY) {
-                       PyErr_Format(PyExc_TypeError, "BoolVectorProperty(size=%d): size must be between 0 and %d.", size, PYRNA_STACK_ARRAY);
+                       PyErr_Format(PyExc_TypeError, "BoolVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY), size);
                        return NULL;
                }
 
@@ -369,7 +369,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
                }
 
                if(size < 1 || size > PYRNA_STACK_ARRAY) {
-                       PyErr_Format(PyExc_TypeError, "IntVectorProperty(size=%d): size must be between 0 and %d.", size, PYRNA_STACK_ARRAY);
+                       PyErr_Format(PyExc_TypeError, "IntVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY), size);
                        return NULL;
                }
 
@@ -503,7 +503,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
                }
 
                if(size < 1 || size > PYRNA_STACK_ARRAY) {
-                       PyErr_Format(PyExc_TypeError, "FloatVectorProperty(size=%d): size must be between 0 and %d.", size, PYRNA_STACK_ARRAY);
+                       PyErr_Format(PyExc_TypeError, "FloatVectorProperty(size=%d): size must be between 0 and " STRINGIFY(PYRNA_STACK_ARRAY), size);
                        return NULL;
                }
 
index a663fc79598181183e242857685120e9aed5a75c..238201c7cf05c74afe49baf6c12dc92b24e7991e 100644 (file)
@@ -962,7 +962,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *p
                        if(RNA_property_flag(prop) & PROP_OUTPUT)
                                param = PyObject_IsTrue( value );
                        else
-                               param = PyLong_AsSsize_t( value );
+                               param = PyLong_AsLong( value );
                        
                        if( param < 0 || param > 1) {
                                PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected True/False or 0/1", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
@@ -975,14 +975,20 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *p
                }
                case PROP_INT:
                {
-                       int param = PyLong_AsSsize_t(value);
-                       if (param==-1 && PyErr_Occurred()) {
+                       int overflow;
+                       long param= PyLong_AsLongAndOverflow(value, &overflow);
+                       if(overflow || (param > INT_MAX) || (param < INT_MIN)) {
+                               PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s value not in 'int' range (" STRINGIFY(INT_MIN) ", " STRINGIFY(INT_MAX) ")", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
+                               return -1;
+                       }
+                       else if (param==-1 && PyErr_Occurred()) {
                                PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected an int type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
                                return -1;
                        } else {
-                               RNA_property_int_clamp(ptr, prop, &param);
-                               if(data)        *((int*)data)= param;
-                               else            RNA_property_int_set(ptr, prop, param);
+                               int param_i= (int)param;
+                               RNA_property_int_clamp(ptr, prop, &param_i);
+                               if(data)        *((int*)data)= param_i;
+                               else            RNA_property_int_set(ptr, prop, param_i);
                        }
                        break;
                }
@@ -1261,7 +1267,7 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P
                switch (type) {
                case PROP_BOOLEAN:
                        {
-                               int param = PyLong_AsSsize_t( value );
+                               int param = PyLong_AsLong( value );
                
                                if( param < 0 || param > 1) {
                                        PyErr_SetString(PyExc_TypeError, "expected True/False or 0/1");
@@ -1273,7 +1279,7 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P
                        }
                case PROP_INT:
                        {
-                               int param = PyLong_AsSsize_t(value);
+                               int param = PyLong_AsLong(value);
                                if (param==-1 && PyErr_Occurred()) {
                                        PyErr_SetString(PyExc_TypeError, "expected an int type");
                                        ret = -1;
@@ -1529,7 +1535,7 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject
                Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
                if (i == -1 && PyErr_Occurred())
                        return NULL;
-               return pyrna_prop_array_subscript_int(self, PyLong_AsSsize_t(key));
+               return pyrna_prop_array_subscript_int(self, PyLong_AsLong(key));
        }
        else if (PySlice_Check(key)) {
                Py_ssize_t start, stop, step, slicelength;
@@ -1613,7 +1619,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, in
                                RNA_property_boolean_get_array(ptr, prop, values);
        
                        for(count=start; count<stop; count++)
-                               values[count] = PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, count-start));
+                               values[count] = PyLong_AsLong(PySequence_Fast_GET_ITEM(value, count-start));
 
                        if(PyErr_Occurred())    ret= -1;
                        else                                    RNA_property_boolean_set_array(ptr, prop, values);
@@ -1634,7 +1640,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, in
                                RNA_property_int_get_array(ptr, prop, values);
 
                        for(count=start; count<stop; count++) {
-                               ival = PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, count-start));
+                               ival = PyLong_AsLong(PySequence_Fast_GET_ITEM(value, count-start));
                                CLAMP(ival, min, max);
                                values[count] = ival;
                        }
@@ -2854,7 +2860,7 @@ static PyObject *pyrna_prop_collection_idprop_add(BPy_PropertyRNA *self)
 
 static PyObject *pyrna_prop_collection_idprop_remove(BPy_PropertyRNA *self, PyObject *value)
 {
-       int key= PyLong_AsSsize_t(value);
+       int key= PyLong_AsLong(value);
 
        if (key==-1 && PyErr_Occurred()) {
                PyErr_SetString( PyExc_TypeError, "bpy_prop_collection.remove(): expected one int argument");
@@ -3201,13 +3207,13 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
                                item= PySequence_GetItem(seq, i);
                                switch(raw_type) {
                                case PROP_RAW_CHAR:
-                                       ((char *)array)[i]= (char)PyLong_AsSsize_t(item);
+                                       ((char *)array)[i]= (char)PyLong_AsLong(item);
                                        break;
                                case PROP_RAW_SHORT:
-                                       ((short *)array)[i]= (short)PyLong_AsSsize_t(item);
+                                       ((short *)array)[i]= (short)PyLong_AsLong(item);
                                        break;
                                case PROP_RAW_INT:
-                                       ((int *)array)[i]= (int)PyLong_AsSsize_t(item);
+                                       ((int *)array)[i]= (int)PyLong_AsLong(item);
                                        break;
                                case PROP_RAW_FLOAT:
                                        ((float *)array)[i]= (float)PyFloat_AsDouble(item);
@@ -4971,7 +4977,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
 
                        if (func_arg_count >= 0) { /* -1 if we dont care*/
                                py_arg_count = PyObject_GetAttrString(PyFunction_GET_CODE(item), "co_argcount");
-                               arg_count = PyLong_AsSsize_t(py_arg_count);
+                               arg_count = PyLong_AsLong(py_arg_count);
                                Py_DECREF(py_arg_count);
 
                                /* note, the number of args we check for and the number of args we give to
index a5294f170f3a1d50ee75368e9223c440a27ac083..5b7d952de774db88dd0fccc532cab1d6f8fadc8c 100644 (file)
@@ -893,12 +893,6 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
                op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
        }
 
-       // XXX - hack, only for editing docs
-       if(strcmp(op->type->idname, "WM_OT_doc_edit")==0) {
-               columns= 1;
-               width= 500;
-       }
-
        RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
        layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, width, 20, style);
        uiItemL(layout, op->type->name, 0);
index d745d826bd63837079584a5f2d8d94f69dc01a96..a14cb94b859561c8f9aeceb233e1ccc88eeed2ab 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
-#define STRINGIFY(x) XSTRINGIFY(x)
-#define XSTRINGIFY(x) #x
-
 #ifdef BUILD_DATE
+#include "BKE_utildefines.h"
+
 char build_date[]= STRINGIFY(BUILD_DATE);
 char build_time[]= STRINGIFY(BUILD_TIME);
 char build_rev[]= STRINGIFY(BUILD_REV);
index 4066d16186b7c201a22595a7f88d52cdadd5b12e..8e17bec361fe89f2201d2817ce8eeba09b901063 100644 (file)
@@ -993,7 +993,7 @@ void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
        BLI_argsAdd(ba, 4, "-E", "--engine", "<engine>\n\tSpecify the render engine\n\tuse -E help to list available engines", set_engine, C);
 
        BLI_argsAdd(ba, 4, "-F", "--render-format", format_doc, set_image_type, C);
-       BLI_argsAdd(ba, 4, "-t", "--threads", "<threads>\n\tUse amount of <threads> for rendering in background\n\t[1-" QUOTE(BLENDER_MAX_THREADS) "], 0 for systems processor count.", set_threads, NULL);
+       BLI_argsAdd(ba, 4, "-t", "--threads", "<threads>\n\tUse amount of <threads> for rendering in background\n\t[1-" STRINGIFY(BLENDER_MAX_THREADS) "], 0 for systems processor count.", set_threads, NULL);
        BLI_argsAdd(ba, 4, "-x", "--use-extension", "<bool>\n\tSet option to add the file extension to the end of the file", set_extension, C);
 
 }