Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/python/intern/bpy_rna.c')
-rw-r--r--source/blender/python/intern/bpy_rna.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 39485f322d4..179daad2f60 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -9040,32 +9040,41 @@ void pyrna_struct_type_extend_capi(struct StructRNA *srna,
struct PyMethodDef *method,
struct PyGetSetDef *getset)
{
- PyObject *cls = pyrna_srna_Subtype(srna);
+ /* See 'add_methods' in Python's 'typeobject.c'. */
+ PyTypeObject *type = (PyTypeObject *)pyrna_srna_Subtype(srna);
+ PyObject *dict = type->tp_dict;
if (method != NULL) {
for (; method->ml_name != NULL; method++) {
- PyObject *func = PyCFunction_New(method, NULL);
- PyObject *args = PyTuple_New(1);
- PyTuple_SET_ITEM(args, 0, func);
- PyObject *classmethod = PyObject_CallObject((PyObject *)&PyClassMethod_Type, args);
+ PyObject *py_method;
- PyObject_SetAttrString(cls, method->ml_name, classmethod);
+ if (method->ml_flags & METH_CLASS) {
+ PyObject *cfunc = PyCFunction_New(method, (PyObject *)type);
+ py_method = PyClassMethod_New(cfunc);
+ Py_DECREF(cfunc);
+ }
+ else {
+ /* Currently only static and class methods are used. */
+ BLI_assert(method->ml_flags & METH_STATIC);
+ py_method = PyCFunction_New(method, NULL);
+ }
- Py_DECREF(classmethod);
- Py_DECREF(args); /* Clears 'func' too. */
+ int err = PyDict_SetItemString(dict, method->ml_name, py_method);
+ Py_DECREF(py_method);
+ BLI_assert(!(err < 0));
+ UNUSED_VARS_NDEBUG(err);
}
}
if (getset != NULL) {
- PyObject *dict = ((PyTypeObject *)cls)->tp_dict;
for (; getset->name != NULL; getset++) {
- PyObject *descr = PyDescr_NewGetSet((PyTypeObject *)cls, getset);
+ PyObject *descr = PyDescr_NewGetSet(type, getset);
/* Ensure we're not overwriting anything that already exists. */
BLI_assert(PyDict_GetItem(dict, PyDescr_NAME(descr)) == NULL);
PyDict_SetItem(dict, PyDescr_NAME(descr), descr);
Py_DECREF(descr);
}
}
- Py_DECREF(cls);
+ Py_DECREF(type);
}
/* Access to 'owner_id' internal global. */