Commit: 654fde2dd213e8799da09875eab961d5286b2452
Author: Campbell Barton
Date:   Fri May 29 14:50:29 2020 +1000
Branches: master
https://developer.blender.org/rB654fde2dd213e8799da09875eab961d5286b2452

PyAPI: use bpy_rna_types_capi.c to set type methods

Remove use of '_bpy' as an intermediate module to store functions
which were then assigned in bpy_types.py.

===================================================================

M       release/scripts/modules/bpy_types.py
M       source/blender/makesrna/RNA_access.h
M       source/blender/python/intern/bpy.c
M       source/blender/python/intern/bpy_library.h
M       source/blender/python/intern/bpy_library_load.c
M       source/blender/python/intern/bpy_library_write.c
M       source/blender/python/intern/bpy_rna_id_collection.c
M       source/blender/python/intern/bpy_rna_id_collection.h
M       source/blender/python/intern/bpy_rna_types_capi.c

===================================================================

diff --git a/release/scripts/modules/bpy_types.py 
b/release/scripts/modules/bpy_types.py
index 845e04caaea..bf14d34ed20 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -25,12 +25,7 @@ StructRNA = bpy_types.bpy_struct
 StructMetaPropGroup = bpy_types.bpy_struct_meta_idprop
 # StructRNA = bpy_types.Struct
 
-bpy_types.BlendDataLibraries.load = _bpy._library_load
-bpy_types.BlendDataLibraries.write = _bpy._library_write
-bpy_types.BlendData.user_map = _bpy._rna_id_collection_user_map
-bpy_types.BlendData.batch_remove = _bpy._rna_id_collection_batch_remove
-bpy_types.BlendData.orphans_purge = _bpy._rna_id_collection_orphans_purge
-
+# Note that methods extended in C are defined in: 'bpy_rna_types_capi.c'
 
 class Context(StructRNA):
     __slots__ = ()
diff --git a/source/blender/makesrna/RNA_access.h 
b/source/blender/makesrna/RNA_access.h
index d2e27bdbcad..65c43ebc151 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -71,6 +71,7 @@ extern StructRNA RNA_BackgroundImage;
 extern StructRNA RNA_BevelModifier;
 extern StructRNA RNA_BezierSplinePoint;
 extern StructRNA RNA_BlendData;
+extern StructRNA RNA_BlendDataLibraries;
 extern StructRNA RNA_BlendTexture;
 extern StructRNA RNA_BlenderRNA;
 extern StructRNA RNA_BoidRule;
diff --git a/source/blender/python/intern/bpy.c 
b/source/blender/python/intern/bpy.c
index 9d0ee0bb500..de8fd87db58 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -380,10 +380,7 @@ void BPy_init_modules(void)
   PyModule_AddObject(mod, "types", BPY_rna_types());
 
   /* needs to be first so bpy_types can run */
-  BPY_library_load_module(mod);
-  BPY_library_write_module(mod);
-
-  BPY_rna_id_collection_module(mod);
+  BPY_library_load_type_ready();
 
   BPY_rna_gizmo_module(mod);
 
diff --git a/source/blender/python/intern/bpy_library.h 
b/source/blender/python/intern/bpy_library.h
index 3fd116d7028..6840807d2b0 100644
--- a/source/blender/python/intern/bpy_library.h
+++ b/source/blender/python/intern/bpy_library.h
@@ -21,7 +21,9 @@
 #ifndef __BPY_LIBRARY_H__
 #define __BPY_LIBRARY_H__
 
-int BPY_library_load_module(PyObject *mod_par);
-int BPY_library_write_module(PyObject *mod_par);
+int BPY_library_load_type_ready(void);
+extern PyMethodDef BPY_library_load_method_def;
+
+extern PyMethodDef BPY_library_write_method_def;
 
 #endif /* __BPY_LIBRARY_H__ */
diff --git a/source/blender/python/intern/bpy_library_load.c 
b/source/blender/python/intern/bpy_library_load.c
index 989b7931444..05cbc9af601 100644
--- a/source/blender/python/intern/bpy_library_load.c
+++ b/source/blender/python/intern/bpy_library_load.c
@@ -459,15 +459,15 @@ static PyObject *bpy_lib_dir(BPy_Library *self)
   return PyDict_Keys(self->dict);
 }
 
-int BPY_library_load_module(PyObject *mod_par)
+PyMethodDef BPY_library_load_method_def = {
+    "load",
+    (PyCFunction)bpy_lib_load,
+    METH_STATIC | METH_VARARGS | METH_KEYWORDS,
+    bpy_lib_load_doc,
+};
+
+int BPY_library_load_type_ready(void)
 {
-  static PyMethodDef load_meth = {
-      "load",
-      (PyCFunction)bpy_lib_load,
-      METH_STATIC | METH_VARARGS | METH_KEYWORDS,
-      bpy_lib_load_doc,
-  };
-  PyModule_AddObject(mod_par, "_library_load", PyCFunction_New(&load_meth, 
NULL));
 
   /* some compilers don't like accessing this directly, delay assignment */
   bpy_lib_Type.tp_getattro = PyObject_GenericGetAttr;
diff --git a/source/blender/python/intern/bpy_library_write.c 
b/source/blender/python/intern/bpy_library_write.c
index 6c8f1deb126..fec0cef7b05 100644
--- a/source/blender/python/intern/bpy_library_write.c
+++ b/source/blender/python/intern/bpy_library_write.c
@@ -204,16 +204,9 @@ finally:
   return ret;
 }
 
-int BPY_library_write_module(PyObject *mod_par)
-{
-  static PyMethodDef write_meth = {
-      "write",
-      (PyCFunction)bpy_lib_write,
-      METH_STATIC | METH_VARARGS | METH_KEYWORDS,
-      bpy_lib_write_doc,
-  };
-
-  PyModule_AddObject(mod_par, "_library_write", PyCFunction_New(&write_meth, 
NULL));
-
-  return 0;
-}
+PyMethodDef BPY_library_write_method_def = {
+    "write",
+    (PyCFunction)bpy_lib_write,
+    METH_STATIC | METH_VARARGS | METH_KEYWORDS,
+    bpy_lib_write_doc,
+};
diff --git a/source/blender/python/intern/bpy_rna_id_collection.c 
b/source/blender/python/intern/bpy_rna_id_collection.c
index 6b6ffa97995..b607f1635e6 100644
--- a/source/blender/python/intern/bpy_rna_id_collection.c
+++ b/source/blender/python/intern/bpy_rna_id_collection.c
@@ -385,32 +385,21 @@ static PyObject *bpy_orphans_purge(PyObject *UNUSED(self),
   return Py_None;
 }
 
-int BPY_rna_id_collection_module(PyObject *mod_par)
-{
-  static PyMethodDef user_map = {
-      "user_map", (PyCFunction)bpy_user_map, METH_VARARGS | METH_KEYWORDS, 
bpy_user_map_doc};
-
-  PyModule_AddObject(mod_par, "_rna_id_collection_user_map", 
PyCFunction_New(&user_map, NULL));
-
-  static PyMethodDef batch_remove = {
-      "batch_remove",
-      (PyCFunction)bpy_batch_remove,
-      METH_VARARGS | METH_KEYWORDS,
-      bpy_batch_remove_doc,
-  };
-
-  PyModule_AddObject(
-      mod_par, "_rna_id_collection_batch_remove", 
PyCFunction_New(&batch_remove, NULL));
-
-  static PyMethodDef orphans_purge = {
-      "orphans_purge",
-      (PyCFunction)bpy_orphans_purge,
-      METH_VARARGS | METH_KEYWORDS,
-      bpy_orphans_purge_doc,
-  };
-
-  PyModule_AddObject(
-      mod_par, "_rna_id_collection_orphans_purge", 
PyCFunction_New(&orphans_purge, NULL));
-
-  return 0;
-}
+PyMethodDef BPY_rna_id_collection_user_map_method_def = {
+    "user_map",
+    (PyCFunction)bpy_user_map,
+    METH_STATIC | METH_VARARGS | METH_KEYWORDS,
+    bpy_user_map_doc,
+};
+PyMethodDef BPY_rna_id_collection_batch_remove_method_def = {
+    "batch_remove",
+    (PyCFunction)bpy_batch_remove,
+    METH_STATIC | METH_VARARGS | METH_KEYWORDS,
+    bpy_batch_remove_doc,
+};
+PyMethodDef BPY_rna_id_collection_orphans_purge_method_def = {
+    "orphans_purge",
+    (PyCFunction)bpy_orphans_purge,
+    METH_STATIC | METH_VARARGS | METH_KEYWORDS,
+    bpy_orphans_purge_doc,
+};
diff --git a/source/blender/python/intern/bpy_rna_id_collection.h 
b/source/blender/python/intern/bpy_rna_id_collection.h
index 8cb375960a9..ee8f4c666a8 100644
--- a/source/blender/python/intern/bpy_rna_id_collection.h
+++ b/source/blender/python/intern/bpy_rna_id_collection.h
@@ -21,6 +21,8 @@
 #ifndef __BPY_RNA_ID_COLLECTION_H__
 #define __BPY_RNA_ID_COLLECTION_H__
 
-int BPY_rna_id_collection_module(PyObject *);
+extern PyMethodDef BPY_rna_id_collection_user_map_method_def;
+extern PyMethodDef BPY_rna_id_collection_batch_remove_method_def;
+extern PyMethodDef BPY_rna_id_collection_orphans_purge_method_def;
 
 #endif /* __BPY_RNA_ID_COLLECTION_H__ */
diff --git a/source/blender/python/intern/bpy_rna_types_capi.c 
b/source/blender/python/intern/bpy_rna_types_capi.c
index 10d6d7e8e32..5a2ba4a5cdb 100644
--- a/source/blender/python/intern/bpy_rna_types_capi.c
+++ b/source/blender/python/intern/bpy_rna_types_capi.c
@@ -33,8 +33,10 @@
 
 #include "BLI_utildefines.h"
 
+#include "bpy_library.h"
 #include "bpy_rna.h"
 #include "bpy_rna_callback.h"
+#include "bpy_rna_id_collection.h"
 #include "bpy_rna_types_capi.h"
 
 #include "../generic/py_capi_utils.h"
@@ -45,6 +47,31 @@
 
 #include "WM_api.h"
 
+/* -------------------------------------------------------------------- */
+/** \name Blend Data
+ * \{ */
+
+static struct PyMethodDef pyrna_blenddata_methods[] = {
+    {NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_user_map_method_def */
+    {NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_batch_remove_method_def */
+    {NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_orphans_purge_method_def 
*/
+    {NULL, NULL, 0, NULL},
+};
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Blend Data Libraries
+ * \{ */
+
+static struct PyMethodDef pyrna_blenddatalibraries_methods[] = {
+    {NULL, NULL, 0, NULL}, /* #BPY_library_load_method_def */
+    {NULL, NULL, 0, NULL}, /* #BPY_library_write_method_def */
+    {NULL, NULL, 0, NULL},
+};
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name Window Manager Clipboard Property
  *
@@ -164,7 +191,24 @@ static struct PyMethodDef pyrna_space_methods[] = {
 
 void BPY_rna_types_extend_capi(void)
 {
+  /* BlendData */
+  ARRAY_SET_ITEMS(pyrna_blenddata_methods,
+                  BPY_rna_id_collection_user_map_method_def,
+                  BPY_rna_id_collection_batch_remove_method_def,
+                  BPY_rna_id_collection_orphans_purge_method_def);
+  BLI_assert(ARRAY_SIZE(pyrna_blenddata_methods) == 4);
+  pyrna_struct_type_extend_capi(&RNA_BlendData, pyrna_blenddata_methods, NULL);
+
+  /* BlendDataLibraries */
+  ARRAY_SET_ITEMS(
+      pyrna_blenddatalibraries_methods, BPY_library_load_method_def, 
BPY_library_write_method_def);
+  BLI_assert(ARRAY_SIZE(pyrna_blenddatalibraries_methods) == 3);
+  pyrna_struct_type_extend_capi(&RNA_BlendDataLibraries, 
pyrna_blenddatalibraries_methods, NULL);
+
+  /* Space */
   pyrna_struct_type_extend_capi(&RNA_Space, pyrna_space_methods, NULL);
+
+  /* WindowManager */
   pyrna_struct_type_extend_capi(
       &RNA_WindowManager, pyrna_windowmanager_methods, 
pyrna_windowmanager_getset);
 }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to