diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-05 09:44:52 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-05 09:44:52 +0400 |
commit | 62f22185546e80b661424b45c88006f8b592d8b1 (patch) | |
tree | 518849699eb9f7299605f6bedc32bc71264816e1 /source/blender/python | |
parent | a71e2c498cbb3c1ec077e38e0fcb8ee1581e4d6b (diff) |
macro formatting & remve some unused code.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/generic/bgl.c | 47 | ||||
-rw-r--r-- | source/blender/python/generic/bgl.h | 15 | ||||
-rw-r--r-- | source/blender/python/generic/bpy_internal_import.c | 80 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 94 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 32 |
5 files changed, 105 insertions, 163 deletions
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 24d963243f6..441c4b6438a 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -205,29 +205,36 @@ PyTypeObject BGL_bufferType = { NULL /*tp_del*/ }; - -/* #ifndef __APPLE__ */ - -#define BGL_Wrap(nargs, funcname, ret, arg_list) \ -static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args) {\ - arg_def##nargs arg_list; \ - ret_def_##ret; \ - if (!PyArg_ParseTuple(args, arg_str##nargs arg_list, arg_ref##nargs arg_list)) return NULL;\ - ret_set_##ret gl##funcname (arg_var##nargs arg_list);\ - ret_ret_##ret; \ +#define BGL_Wrap(nargs, funcname, ret, arg_list) \ +static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args) \ +{ \ + arg_def##nargs arg_list; \ + ret_def_##ret; \ + if (!PyArg_ParseTuple(args, \ + arg_str##nargs arg_list, \ + arg_ref##nargs arg_list)) \ + { \ + return NULL; \ + } \ + ret_set_##ret gl##funcname (arg_var##nargs arg_list); \ + ret_ret_##ret; \ } -#define BGLU_Wrap(nargs, funcname, ret, arg_list) \ -static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args) {\ - arg_def##nargs arg_list; \ - ret_def_##ret; \ - if (!PyArg_ParseTuple(args, arg_str##nargs arg_list, arg_ref##nargs arg_list)) return NULL;\ - ret_set_##ret glu##funcname (arg_var##nargs arg_list);\ - ret_ret_##ret; \ +#define BGLU_Wrap(nargs, funcname, ret, arg_list) \ +static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args) \ +{ \ + arg_def##nargs arg_list; \ + ret_def_##ret; \ + if (!PyArg_ParseTuple(args, \ + arg_str##nargs arg_list, \ + arg_ref##nargs arg_list)) \ + { \ + return NULL; \ + } \ + ret_set_##ret glu##funcname (arg_var##nargs arg_list); \ + ret_ret_##ret; \ } -/* #endif */ - /********/ int BGL_typeSize(int type) { @@ -267,7 +274,7 @@ Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuf memcpy(buffer->dimensions, dimensions, ndimensions*sizeof(int)); buffer->type= type; buffer->buf.asvoid= buf; - + if (initbuffer) { memcpy(buffer->buf.asvoid, initbuffer, length*size); } diff --git a/source/blender/python/generic/bgl.h b/source/blender/python/generic/bgl.h index 5cf9eac8289..6df534a3940 100644 --- a/source/blender/python/generic/bgl.h +++ b/source/blender/python/generic/bgl.h @@ -331,12 +331,13 @@ extern PyTypeObject BGL_bufferType; #define ret_def_GLstring const unsigned char *ret_str; #define ret_set_GLstring ret_str= -#define ret_ret_GLstring \ - if (ret_str) {\ - return PyUnicode_FromString((const char *)ret_str);\ - } else {\ - PyErr_SetString(PyExc_AttributeError, "could not get opengl string");\ - return NULL;\ - } +#define ret_ret_GLstring \ + if (ret_str) { \ + return PyUnicode_FromString((const char *)ret_str); \ + } \ + else { \ + PyErr_SetString(PyExc_AttributeError, "could not get opengl string"); \ + return NULL; \ + } \ #endif /* BGL_H */ diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index 293ade35584..acfe6ee80bf 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -15,12 +15,10 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * * This is a new part of Blender. * - * Contributor(s): Willian P. Germano + * Contributor(s): Willian P. Germano, + * Campbell Barton * * ***** END GPL LICENSE BLOCK ***** */ @@ -308,77 +306,3 @@ static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module) PyMethodDef bpy_import_meth= {"bpy_import_meth", (PyCFunction)blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"}; PyMethodDef bpy_reload_meth= {"bpy_reload_meth", (PyCFunction)blender_reload, METH_O, "blenders reload"}; - - -/* Clear user modules. - * This is to clear any modules that could be defined from running scripts in blender. - * - * Its also needed for the BGE Python api so imported scripts are not used between levels - * - * This clears every modules that has a __file__ attribute (is not a builtin) - * - * Note that clearing external python modules is important for the BGE otherwise - * it wont reload scripts between loading different blend files or while making the game. - * - use 'clear_all' arg in this case. - * - * Since pythons built-ins include a full path even for win32. - * even if we remove a python module a re-import will bring it back again. - */ - -#if 0 // not used anymore but may still come in handy later - -#if defined(WIN32) || defined(WIN64) -#define SEPSTR "\\" -#else -#define SEPSTR "/" -#endif - - -void bpy_text_clear_modules(int clear_all) -{ - PyObject *modules= PyImport_GetModuleDict(); - - char *fname; - char *file_extension; - - /* looping over the dict */ - PyObject *key, *value; - Py_ssize_t pos= 0; - - /* new list */ - PyObject *list; - - if (modules==NULL) - return; /* should never happen but just incase */ - - list= PyList_New(0); - - /* go over sys.modules and remove anything with a - * sys.modukes[x].__file__ thats ends with a .py and has no path - */ - while (PyDict_Next(modules, &pos, &key, &value)) { - fname= PyModule_GetFilename(value); - if (fname) { - if (clear_all || ((strstr(fname, SEPSTR))==0)) { /* no path ? */ - file_extension= strstr(fname, ".py"); - if (file_extension && (*(file_extension + 3) == '\0' || *(file_extension + 4) == '\0')) { /* .py or pyc extension? */ - /* now we can be fairly sure its a python import from the blendfile */ - PyList_Append(list, key); /* free'd with the list */ - } - } - } - else { - PyErr_Clear(); - } - } - - /* remove all our modules */ - for (pos=0; pos < PyList_GET_SIZE(list); pos++) { - /* PyObject_Print(key, stderr, 0); */ - key= PyList_GET_ITEM(list, pos); - PyDict_DelItem(modules, key); - } - - Py_DECREF(list); /* removes all references from append */ -} -#endif diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index b10223207bf..cfd2e5556a1 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -279,52 +279,60 @@ static int py_long_as_int(PyObject *py_long, int *r_int) /* this define runs at the start of each function and deals with * returning a deferred property (to be registered later) */ -#define BPY_PROPDEF_HEAD(_func) \ - if (PyTuple_GET_SIZE(args) == 1) { \ - PyObject *ret; \ - self= PyTuple_GET_ITEM(args, 0); \ - args= PyTuple_New(0); \ - ret= BPy_##_func(self, args, kw); \ - Py_DECREF(args); \ - return ret; \ - } \ - else if (PyTuple_GET_SIZE(args) > 1) { \ - PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \ - return NULL; \ - } \ - srna= srna_from_self(self, #_func"(...):"); \ - if (srna==NULL) { \ - if (PyErr_Occurred()) \ - return NULL; \ - return bpy_prop_deferred_return((void *)pymeth_##_func, kw); \ - } \ +#define BPY_PROPDEF_HEAD(_func) \ + if (PyTuple_GET_SIZE(args) == 1) { \ + PyObject *ret; \ + self= PyTuple_GET_ITEM(args, 0); \ + args= PyTuple_New(0); \ + ret= BPy_##_func(self, args, kw); \ + Py_DECREF(args); \ + return ret; \ + } \ + else if (PyTuple_GET_SIZE(args) > 1) { \ + PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \ + return NULL; \ + } \ + srna= srna_from_self(self, #_func"(...):"); \ + if (srna==NULL) { \ + if (PyErr_Occurred()) \ + return NULL; \ + return bpy_prop_deferred_return((void *)pymeth_##_func, kw); \ + } \ /* terse macros for error checks shared between all funcs cant use function * calls because of static strins passed to pyrna_set_to_enum_bitfield */ -#define BPY_PROPDEF_CHECK(_func, _property_flag_items) \ - if (id_len >= MAX_IDPROP_NAME) { \ - PyErr_Format(PyExc_TypeError, \ - #_func"(): '%.200s' too long, max length is %d", \ - id, MAX_IDPROP_NAME-1); \ - return NULL; \ - } \ - if (RNA_def_property_free_identifier(srna, id) == -1) { \ - PyErr_Format(PyExc_TypeError, \ - #_func"(): '%s' is defined as a non-dynamic type", \ - id); \ - return NULL; \ - } \ - if (pyopts && pyrna_set_to_enum_bitfield(_property_flag_items, pyopts, &opts, #_func"(options={...}):")) \ - return NULL; \ - -#define BPY_PROPDEF_SUBTYPE_CHECK(_func, _property_flag_items, _subtype) \ - BPY_PROPDEF_CHECK(_func, _property_flag_items) \ - if (pysubtype && RNA_enum_value_from_id(_subtype, pysubtype, &subtype)==0) { \ - PyErr_Format(PyExc_TypeError, \ - #_func"(subtype='%s'): invalid subtype", \ - pysubtype); \ - return NULL; \ - } \ +#define BPY_PROPDEF_CHECK(_func, _property_flag_items) \ + if (id_len >= MAX_IDPROP_NAME) { \ + PyErr_Format(PyExc_TypeError, \ + #_func"(): '%.200s' too long, max length is %d", \ + id, MAX_IDPROP_NAME-1); \ + return NULL; \ + } \ + if (RNA_def_property_free_identifier(srna, id) == -1) { \ + PyErr_Format(PyExc_TypeError, \ + #_func"(): '%s' is defined as a non-dynamic type", \ + id); \ + return NULL; \ + } \ + if (pyopts && pyrna_set_to_enum_bitfield(_property_flag_items, \ + pyopts, \ + &opts, \ + #_func"(options={...}):")) \ + { \ + return NULL; \ + } \ + +#define BPY_PROPDEF_SUBTYPE_CHECK(_func, _property_flag_items, _subtype) \ + BPY_PROPDEF_CHECK(_func, _property_flag_items) \ + if (pysubtype && RNA_enum_value_from_id(_subtype, \ + pysubtype, \ + &subtype)==0) \ + { \ + PyErr_Format(PyExc_TypeError, \ + #_func"(subtype='%s'): invalid subtype", \ + pysubtype); \ + return NULL; \ + } \ #define BPY_PROPDEF_NAME_DOC \ diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 1ecbeb4d16a..3411bceda69 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -82,10 +82,10 @@ static PyObject* pyrna_struct_Subtype(PointerRNA *ptr); static PyObject *pyrna_prop_collection_values(BPy_PropertyRNA *self); -#define BPY_DOC_ID_PROP_TYPE_NOTE \ -" .. note::\n" \ -"\n" \ -" Only :class:`bpy.types.ID`, :class:`bpy.types.Bone` and \n" \ +#define BPY_DOC_ID_PROP_TYPE_NOTE \ +" .. note::\n" \ +"\n" \ +" Only :class:`bpy.types.ID`, :class:`bpy.types.Bone` and \n" \ " :class:`bpy.types.PoseBone` classes support custom properties.\n" @@ -6404,17 +6404,19 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun if (item==NULL) { /* Sneaky workaround to use the class name as the bl_idname */ -#define BPY_REPLACEMENT_STRING(rna_attr, py_attr) \ - if (strcmp(identifier, rna_attr) == 0) { \ - item= PyObject_GetAttrString(py_class, py_attr); \ - if (item && item != Py_None) { \ - if (pyrna_py_to_prop(dummyptr, prop, NULL, item, "validating class:") != 0) { \ - Py_DECREF(item); \ - return -1; \ - } \ - } \ - Py_XDECREF(item); \ - } \ +#define BPY_REPLACEMENT_STRING(rna_attr, py_attr) \ + if (strcmp(identifier, rna_attr) == 0) { \ + item= PyObject_GetAttrString(py_class, py_attr); \ + if (item && item != Py_None) { \ + if (pyrna_py_to_prop(dummyptr, prop, NULL, \ + item, "validating class:") != 0) \ + { \ + Py_DECREF(item); \ + return -1; \ + } \ + } \ + Py_XDECREF(item); \ + } \ BPY_REPLACEMENT_STRING("bl_idname", "__name__"); |