[Bf-blender-cvs] [8305dd94996] master: Cleanup: localize creator.c definitions

Campbell Barton noreply at git.blender.org
Sun Aug 2 08:20:46 CEST 2020


Commit: 8305dd9499692e3f98452f9b778676ea2cf765a4
Author: Campbell Barton
Date:   Sun Aug 2 13:11:30 2020 +1000
Branches: master
https://developer.blender.org/rB8305dd9499692e3f98452f9b778676ea2cf765a4

Cleanup: localize creator.c definitions

As creator.c is used for the 'main' function,
avoid obscure declarations being placed so prominently.

- Move Blender as a Python module declarations into it's own section.
- Move USD declaration to an 'extern' just before it's called.

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

M	source/blender/python/intern/bpy_interface.c
M	source/creator/creator.c

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

diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index f91afa414ce..585119a0eae 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -921,8 +921,11 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
 /* TODO, reloading the module isn't functional at the moment. */
 
 static void bpy_module_free(void *mod);
+
+/* Defined in 'creator.c' when building as a Python module. */
 extern int main_python_enter(int argc, const char **argv);
 extern void main_python_exit(void);
+
 static struct PyModuleDef bpy_proxy_def = {
     PyModuleDef_HEAD_INIT,
     "bpy",           /* m_name */
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 2793765bf2c..3d76d832d9f 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -110,25 +110,10 @@
 #include "creator_intern.h" /* own include */
 
 /* Local Function prototypes. */
-#ifdef WITH_PYTHON_MODULE
-int main_python_enter(int argc, const char **argv);
-void main_python_exit(void);
-#endif
 
-#ifdef WITH_USD
-/**
- * Workaround to make it possible to pass a path at runtime to USD.
- *
- * USD requires some JSON files, and it uses a static constructor to determine the possible
- * file-system paths to find those files. This made it impossible for Blender to pass a path to the
- * USD library at runtime, as the constructor would run before Blender's main() function. We have
- * patched USD (see usd.diff) to avoid that particular static constructor, and have an
- * initialization function instead.
- *
- * This function is implemented in the USD source code, `pxr/base/lib/plug/initConfig.cpp`.
- */
-void usd_initialise_plugin_path(const char *datafiles_usd_path);
-#endif
+/* -------------------------------------------------------------------- */
+/** \name Local Application State
+ * \{ */
 
 /* written to by 'creator_args.c' */
 struct ApplicationState app_state = {
@@ -143,6 +128,8 @@ struct ApplicationState app_state = {
         },
 };
 
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name Application Level Callbacks
  *
@@ -199,11 +186,19 @@ static void callback_clg_fatal(void *fp)
 /** \} */
 
 /* -------------------------------------------------------------------- */
-/** \name Main Function
+/** \name Blender as a Stand-Alone Python Module (bpy)
+ *
+ * While not officially supported, this can be useful for Python developers.
+ * See: https://wiki.blender.org/wiki/Building_Blender/Other/BlenderAsPyModule
  * \{ */
 
 #ifdef WITH_PYTHON_MODULE
-/* allow python module to call main */
+
+/* Called in `bpy_interface.c` when building as a Python module. */
+int main_python_enter(int argc, const char **argv);
+void main_python_exit(void);
+
+/* Rename the 'main' function, allowing Python initialization to call it. */
 #  define main main_python_enter
 static void *evil_C = NULL;
 
@@ -211,8 +206,15 @@ static void *evil_C = NULL;
 /* Environment is not available in macOS shared libraries. */
 #    include <crt_externs.h>
 char **environ = NULL;
-#  endif
-#endif
+#  endif /* __APPLE__ */
+
+#endif /* WITH_PYTHON_MODULE */
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Main Function
+ * \{ */
 
 /**
  * Blender's main function responsibilities are:
@@ -441,10 +443,21 @@ int main(int argc,
   BKE_materials_init();
 
 #ifdef WITH_USD
+  /* Workaround to make it possible to pass a path at runtime to USD.
+   *
+   * USD requires some JSON files, and it uses a static constructor to determine the possible
+   * file-system paths to find those files. This made it impossible for Blender to pass a path to
+   * the USD library at runtime, as the constructor would run before Blender's main() function.
+   * We have patched USD (see usd.diff) to avoid that particular static constructor, and have an
+   * initialization function instead.
+   *
+   * This function is implemented in the USD source code, `pxr/base/lib/plug/initConfig.cpp`. */
+  extern void usd_initialise_plugin_path(const char *datafiles_usd_path);
+
   /* Tell USD which directory to search for its JSON files. If 'datafiles/usd'
    * does not exist, the USD library will not be able to read or write any files. */
   usd_initialise_plugin_path(BKE_appdir_folder_id(BLENDER_DATAFILES, "usd"));
-#endif
+#endif /* WITH_USD */
 
   if (G.background == 0) {
 #ifndef WITH_PYTHON_MODULE



More information about the Bf-blender-cvs mailing list