diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-01-20 11:03:23 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-01-20 11:09:00 +0400 |
commit | a696a0ff1e9c55c21696c18a6cf6e5b1b2a40e37 (patch) | |
tree | c9dba903b0a90fddae6375131140bcad58d69859 /source/blender | |
parent | ece504aff8ed3777498c459d5ce618f99be4df6e (diff) |
Python API: create args for meta-classes directly (a little faster).
Also add some new interned strings.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/intern/bpy_intern_string.c | 48 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_intern_string.h | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 33 |
3 files changed, 64 insertions, 19 deletions
diff --git a/source/blender/python/intern/bpy_intern_string.c b/source/blender/python/intern/bpy_intern_string.c index 294f230ce99..9c93af1786c 100644 --- a/source/blender/python/intern/bpy_intern_string.c +++ b/source/blender/python/intern/bpy_intern_string.c @@ -32,38 +32,50 @@ #include "bpy_intern_string.h" +#include "BLI_utildefines.h" + +static PyObject *bpy_intern_str_arr[11]; + PyObject *bpy_intern_str_register; PyObject *bpy_intern_str_unregister; PyObject *bpy_intern_str_bl_rna; PyObject *bpy_intern_str_bl_property; +PyObject *bpy_intern_str_bpy_types; PyObject *bpy_intern_str_order; PyObject *bpy_intern_str_attr; PyObject *bpy_intern_str___slots__; PyObject *bpy_intern_str___name__; PyObject *bpy_intern_str___doc__; +PyObject *bpy_intern_str___module__; 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_bl_property = PyUnicode_FromString("bl_property"); - bpy_intern_str_order = PyUnicode_FromString("order"); - bpy_intern_str_attr = PyUnicode_FromString("attr"); - bpy_intern_str___slots__ = PyUnicode_FromString("__slots__"); - bpy_intern_str___name__ = PyUnicode_FromString("__name__"); - bpy_intern_str___doc__ = PyUnicode_FromString("__doc__"); + unsigned int i = 0; + +#define BPY_INTERN_STR(var, str) \ + { var = bpy_intern_str_arr[i++] = PyUnicode_FromString(str); } (void)0 + + BPY_INTERN_STR(bpy_intern_str_register, "register"); + BPY_INTERN_STR(bpy_intern_str_unregister, "unregister"); + BPY_INTERN_STR(bpy_intern_str_bl_rna, "bl_rna"); + BPY_INTERN_STR(bpy_intern_str_bl_property, "bl_property"); + BPY_INTERN_STR(bpy_intern_str_bpy_types, "bpy.types"); + BPY_INTERN_STR(bpy_intern_str_order, "order"); + BPY_INTERN_STR(bpy_intern_str_attr, "attr"); + BPY_INTERN_STR(bpy_intern_str___slots__, "__slots__"); + BPY_INTERN_STR(bpy_intern_str___name__, "__name__"); + BPY_INTERN_STR(bpy_intern_str___doc__, "__doc__"); + BPY_INTERN_STR(bpy_intern_str___module__, "__module__"); + +#undef BPY_INTERN_STR + + BLI_assert(i == (sizeof(bpy_intern_str_arr) / sizeof(*bpy_intern_str_arr))); } 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_bl_property); - Py_DECREF(bpy_intern_str_order); - Py_DECREF(bpy_intern_str_attr); - Py_DECREF(bpy_intern_str___slots__); - Py_DECREF(bpy_intern_str___name__); - Py_DECREF(bpy_intern_str___doc__); + unsigned int i = sizeof(bpy_intern_str_arr) / sizeof(*bpy_intern_str_arr); + while (i--) { + Py_DECREF(bpy_intern_str_arr[i]); + } } diff --git a/source/blender/python/intern/bpy_intern_string.h b/source/blender/python/intern/bpy_intern_string.h index 41b7303bf8d..f4f4560dbfd 100644 --- a/source/blender/python/intern/bpy_intern_string.h +++ b/source/blender/python/intern/bpy_intern_string.h @@ -34,10 +34,12 @@ extern PyObject *bpy_intern_str_register; extern PyObject *bpy_intern_str_unregister; extern PyObject *bpy_intern_str_bl_rna; extern PyObject *bpy_intern_str_bl_property; +extern PyObject *bpy_intern_str_bpy_types; extern PyObject *bpy_intern_str_order; extern PyObject *bpy_intern_str_attr; extern PyObject *bpy_intern_str___slots__; extern PyObject *bpy_intern_str___name__; extern PyObject *bpy_intern_str___doc__; +extern PyObject *bpy_intern_str___module__; #endif /* __BPY_INTERN_STRING_H__ */ diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 8d6c7d93e50..86ed459eb1f 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -6234,7 +6234,7 @@ static PyObject *pyrna_srna_Subtype(StructRNA *srna) /* subclass equivalents * - class myClass(myBase): * some = 'value' # or ... - * - myClass = type(name='myClass', bases=(myBase,), dict={'__module__':'bpy.types'}) + * - myClass = type(name='myClass', bases=(myBase,), dict={'__module__': 'bpy.types', '__slots__': ()}) */ /* Assume RNA_struct_py_type_get(srna) was already checked */ @@ -6257,8 +6257,39 @@ static PyObject *pyrna_srna_Subtype(StructRNA *srna) } /* always use O not N when calling, N causes refcount errors */ +#if 0 newclass = PyObject_CallFunction(metaclass, (char *)"s(O) {sss()}", idname, py_base, "__module__", "bpy.types", "__slots__"); +#else + { + /* longhand of the call above */ + PyObject *args, *item, *value; + int ok; + + args = PyTuple_New(3); + + /* arg[0] (name=...) */ + PyTuple_SET_ITEM(args, 0, PyUnicode_FromString(idname)); + + + /* arg[1] (bases=...) */ + PyTuple_SET_ITEM(args, 1, item = PyTuple_New(1)); + PyTuple_SET_ITEM(item, 0, py_base); + + + /* arg[2] (dict=...) */ + PyTuple_SET_ITEM(args, 2, item = PyDict_New()); + ok = PyDict_SetItem(item, bpy_intern_str___module__, bpy_intern_str_bpy_types); + BLI_assert(ok != -1); + ok = PyDict_SetItem(item, bpy_intern_str___slots__, value = PyTuple_New(0)); Py_DECREF(value); + BLI_assert(ok != -1); + + newclass = PyObject_CallObject(metaclass, args); + Py_DECREF(args); + + (void)ok; + } +#endif /* newclass will now have 2 ref's, ???, probably 1 is internal since decrefing here segfaults */ |