Revision: 37614
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37614
Author:   campbellbarton
Date:     2011-06-18 08:45:45 +0000 (Sat, 18 Jun 2011)
Log Message:
-----------
py-api: store frequently used strings as unicode PyObject's to avoid 
creating/distroying every time.
also fix for cmake warning

Modified Paths:
--------------
    trunk/blender/build_files/cmake/macros.cmake
    trunk/blender/source/blender/python/intern/CMakeLists.txt
    trunk/blender/source/blender/python/intern/bpy_interface.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Added Paths:
-----------
    trunk/blender/source/blender/python/intern/bpy_intern_string.c
    trunk/blender/source/blender/python/intern/bpy_intern_string.h

Modified: trunk/blender/build_files/cmake/macros.cmake
===================================================================
--- trunk/blender/build_files/cmake/macros.cmake        2011-06-18 03:14:24 UTC 
(rev 37613)
+++ trunk/blender/build_files/cmake/macros.cmake        2011-06-18 08:45:45 UTC 
(rev 37614)
@@ -37,7 +37,7 @@
 
        foreach(_SRC ${sources})
                get_filename_component(_SRC_EXT ${_SRC} EXT)
-               if(${_SRC_EXT} MATCHES ".h" OR ${_SRC_EXT} MATCHES ".hpp")
+               if((${_SRC_EXT} MATCHES ".h") OR (${_SRC_EXT} MATCHES ".hpp"))
                        source_group("Header Files" FILES ${_SRC})
                else()
                        source_group("Source Files" FILES ${_SRC})

Modified: trunk/blender/source/blender/python/intern/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/python/intern/CMakeLists.txt   2011-06-18 
03:14:24 UTC (rev 37613)
+++ trunk/blender/source/blender/python/intern/CMakeLists.txt   2011-06-18 
08:45:45 UTC (rev 37614)
@@ -45,6 +45,7 @@
        bpy_app.c
        bpy_driver.c
        bpy_interface.c
+       bpy_intern_string.c
        bpy_library.c
        bpy_operator.c
        bpy_operator_wrap.c
@@ -60,6 +61,7 @@
        bpy.h
        bpy_app.h
        bpy_driver.h
+       bpy_intern_string.h
        bpy_operator.h
        bpy_operator_wrap.h
        bpy_props.h

Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c  2011-06-18 
03:14:24 UTC (rev 37613)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c  2011-06-18 
08:45:45 UTC (rev 37614)
@@ -43,6 +43,7 @@
 #include "bpy_rna.h"
 #include "bpy_util.h"
 #include "bpy_traceback.h"
+#include "bpy_intern_string.h"
 
 #include "DNA_space_types.h"
 #include "DNA_text_types.h"
@@ -205,7 +206,9 @@
        Py_NoSiteFlag= 1;
 
        Py_Initialize();
-       
+
+       bpy_intern_string_init();
+
        // PySys_SetArgv(argc, argv); // broken in py3, not a huge deal
        /* sigh, why do python guys not have a char** version anymore? :( */
        {
@@ -251,7 +254,9 @@
        pyrna_free_types();
 
        /* clear all python data from structs */
-       
+
+       bpy_intern_string_exit();
+
        Py_Finalize();
        
 #ifdef TIME_PY_RUN

Added: trunk/blender/source/blender/python/intern/bpy_intern_string.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_intern_string.c              
                (rev 0)
+++ trunk/blender/source/blender/python/intern/bpy_intern_string.c      
2011-06-18 08:45:45 UTC (rev 37614)
@@ -0,0 +1,57 @@
+/*
+ * $Id:
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_intern_string.c
+ *  \ingroup pythonintern
+ */
+
+#include <Python.h>
+
+PyObject *bpy_intern_str_register;
+PyObject *bpy_intern_str_unregister;
+PyObject *bpy_intern_str_bl_rna;
+PyObject *bpy_intern_str_order;
+PyObject *bpy_intern_str_attr;
+PyObject *bpy_intern_str___slots__;
+PyObject *bpy_intern_str___bases__;
+
+void bpy_intern_string_init(void)
+{
+       bpy_intern_str_register= PyUnicode_FromString("register");
+       bpy_intern_str_unregister= PyUnicode_FromString("unregister");;
+       bpy_intern_str_bl_rna= PyUnicode_FromString("bl_rna");
+       bpy_intern_str_order= PyUnicode_FromString("order");
+       bpy_intern_str_attr= PyUnicode_FromString("attr");
+       bpy_intern_str___slots__= PyUnicode_FromString("__slots__");
+}
+
+void bpy_intern_string_exit(void)
+{
+       Py_DECREF(bpy_intern_str_register);
+       Py_DECREF(bpy_intern_str_unregister);
+       Py_DECREF(bpy_intern_str_bl_rna);
+       Py_DECREF(bpy_intern_str_order);
+       Py_DECREF(bpy_intern_str_attr);
+       Py_DECREF(bpy_intern_str___slots__);
+}

Added: trunk/blender/source/blender/python/intern/bpy_intern_string.h
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_intern_string.h              
                (rev 0)
+++ trunk/blender/source/blender/python/intern/bpy_intern_string.h      
2011-06-18 08:45:45 UTC (rev 37614)
@@ -0,0 +1,37 @@
+/*
+ * $Id:
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_intern_string.h
+ *  \ingroup pythonintern
+ */
+
+void bpy_intern_string_init(void);
+void bpy_intern_string_exit(void);
+
+extern PyObject *bpy_intern_str_register;
+extern PyObject *bpy_intern_str_unregister;
+extern PyObject *bpy_intern_str_bl_rna;
+extern PyObject *bpy_intern_str_order;
+extern PyObject *bpy_intern_str_attr;
+extern PyObject *bpy_intern_str___slots__;

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c        2011-06-18 
03:14:24 UTC (rev 37613)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c        2011-06-18 
08:45:45 UTC (rev 37614)
@@ -39,6 +39,7 @@
 #include "bpy_props.h"
 #include "bpy_util.h"
 #include "bpy_rna_callback.h"
+#include "bpy_intern_string.h"
 
 #ifdef USE_PYRNA_INVALIDATE_WEAKREF
 #include "MEM_guardedalloc.h"
@@ -5217,7 +5218,7 @@
        item= pyrna_struct_CreatePyObject(&ptr);
 
        /* note, must set the class not the __dict__ else the internal slots 
are not updated correctly */
-       PyObject_SetAttrString(newclass, "bl_rna", item);
+       PyObject_SetAttr(newclass, bpy_intern_str_bl_rna, item);
        Py_DECREF(item);
 
        /* done with rna instance */
@@ -5279,7 +5280,7 @@
                //PyObject *slots= PyObject_GetAttrString(newclass, 
"__slots__"); // cant do this because it gets superclasses values!
                //PyObject *bases= PyObject_GetAttrString(newclass, 
"__bases__"); // can do this but faster not to.
                PyObject *bases= ((PyTypeObject *)newclass)->tp_bases;
-               PyObject *slots= PyDict_GetItemString(((PyTypeObject 
*)newclass)->tp_dict, "__slots__");
+               PyObject *slots= PyDict_GetItem(((PyTypeObject 
*)newclass)->tp_dict, bpy_intern_str___slots__);
 
                if(slots==NULL) {
                        fprintf(stderr, "pyrna_srna_ExternalType: expected 
class '%s' to have __slots__ defined\n\nSee bpy_types.py\n", idname);
@@ -5649,7 +5650,7 @@
 
        /* ack, PyObject_GetAttrString wont look up this types tp_dict first :/ 
*/
        if(PyType_Check(self)) {
-               py_srna= (BPy_StructRNA *)PyDict_GetItemString(((PyTypeObject 
*)self)->tp_dict, "bl_rna");
+               py_srna= (BPy_StructRNA *)PyDict_GetItem(((PyTypeObject 
*)self)->tp_dict, bpy_intern_str_bl_rna);
                Py_XINCREF(py_srna);
        }
 
@@ -5657,7 +5658,7 @@
                /* be very careful with this since it will return a parent 
classes srna.
                 * modifying this will do confusing stuff! */
                if(py_srna==NULL)
-                       py_srna= (BPy_StructRNA*)PyObject_GetAttrString(self, 
"bl_rna");
+                       py_srna= (BPy_StructRNA*)PyObject_GetAttr(self, 
bpy_intern_str_bl_rna);
        }
 
        if(py_srna==NULL) {
@@ -5747,7 +5748,7 @@
                        py_srna_cobject= PyCapsule_New(srna, NULL, NULL);
 
                        /* not 100% nice :/, modifies the dict passed, should 
be ok */
-                       PyDict_SetItemString(py_kw, "attr", key);
+                       PyDict_SetItem(py_kw, bpy_intern_str_attr, key);
 
                        args_fake= PyTuple_New(1);
                        PyTuple_SET_ITEM(args_fake, 0, py_srna_cobject);
@@ -5794,7 +5795,7 @@
        /* in both cases PyDict_CheckExact(class_dict) will be true even
         * though Operators have a metaclass dict namespace */
 
-       if((order= PyDict_GetItemString(class_dict, "order")) && 
PyList_CheckExact(order)) {
+       if((order= PyDict_GetItem(class_dict, bpy_intern_str_order)) && 
PyList_CheckExact(order)) {
                for(pos= 0; pos<PyList_GET_SIZE(order); pos++) {
                        key= PyList_GET_ITEM(order, pos);
                        item= PyDict_GetItem(class_dict, key);
@@ -6299,7 +6300,7 @@
        // PyDict_Clear(((PyTypeObject*)self)->tp_dict);
        //
        // remove the rna attribute instead.
-       PyDict_DelItemString(((PyTypeObject *)self)->tp_dict, "bl_rna");
+       PyDict_DelItem(((PyTypeObject *)self)->tp_dict, bpy_intern_str_bl_rna);
        if(PyErr_Occurred())
                PyErr_Clear();
 
@@ -6405,7 +6406,7 @@
        const char *identifier;
        PyObject *py_cls_meth;
 
-       if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")) {
+       if(PyDict_GetItem(((PyTypeObject*)py_class)->tp_dict, 
bpy_intern_str_bl_rna)) {
                PyErr_SetString(PyExc_AttributeError, "register_class(...): 
already registered as a subclass");
                return NULL;
        }
@@ -6470,7 +6471,7 @@
                return NULL;
 
        /* call classed register method () */
-       py_cls_meth= PyObject_GetAttrString(py_class, "register");
+       py_cls_meth= PyObject_GetAttr(py_class, bpy_intern_str_register);
        if(py_cls_meth == NULL) {
                PyErr_Clear();
        }
@@ -6528,7 +6529,7 @@
        StructRNA *srna;
        PyObject *py_cls_meth;
 
-       /*if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, 
"bl_rna")==NULL) {
+       /*if(PyDict_GetItem(((PyTypeObject*)py_class)->tp_dict, 
bpy_intern_str_bl_rna)==NULL) {
                PWM_cursor_wait(0);
                PyErr_SetString(PyExc_ValueError, "unregister_class(): not a 
registered as a subclass");
                return NULL;
@@ -6547,7 +6548,7 @@
        }
 
        /* call classed unregister method */
-       py_cls_meth= PyObject_GetAttrString(py_class, "unregister");
+       py_cls_meth= PyObject_GetAttr(py_class, bpy_intern_str_unregister);

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to