2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Michel Selten, Willian P. Germano, Stephen Swaney,
19 * Chris Keith, Chris Want, Ken Hughes, Campbell Barton
21 * ***** END GPL LICENSE BLOCK *****
24 /** \file blender/python/intern/bpy_interface.c
25 * \ingroup pythonintern
27 * This file deals with embedding the python interpreter within blender,
28 * starting and stopping python and exposing blender/python modules so they can
29 * be accesses from scripts.
33 /* grr, python redefines */
34 #ifdef _POSIX_C_SOURCE
35 # undef _POSIX_C_SOURCE
40 #include "MEM_guardedalloc.h"
42 #include "BLI_utildefines.h"
43 #include "BLI_path_util.h"
44 #include "BLI_fileops.h"
45 #include "BLI_listbase.h"
46 #include "BLI_math_base.h"
47 #include "BLI_string.h"
48 #include "BLI_string_utf8.h"
49 #include "BLI_threads.h"
51 #include "RNA_types.h"
58 #include "bpy_traceback.h"
59 #include "bpy_intern_string.h"
61 #include "DNA_space_types.h"
62 #include "DNA_text_types.h"
64 #include "BKE_context.h"
67 #include "BKE_global.h" /* only for script checking */
71 #include "BPY_extern.h"
73 #include "../generic/bpy_internal_import.h" /* our own imports */
74 #include "../generic/py_capi_utils.h"
76 /* inittab initialization functions */
77 #include "../generic/bgl.h"
78 #include "../generic/blf_py_api.h"
79 #include "../generic/idprop_py_api.h"
80 #include "../bmesh/bmesh_py_api.h"
81 #include "../mathutils/mathutils.h"
84 /* for internal use, when starting and ending python scripts */
86 /* in case a python script triggers another python call, stop bpy_context_clear from invalidating */
87 static int py_call_level = 0;
88 BPy_StructRNA *bpy_context_module = NULL; /* for fast access */
90 // #define TIME_PY_RUN // simple python tests. prints on exit.
94 static int bpy_timer_count = 0;
95 static double bpy_timer; /* time since python starts */
96 static double bpy_timer_run; /* time for each python script run */
97 static double bpy_timer_run_tot; /* accumulate python runs */
100 /* use for updating while a python script runs - in case of file load */
101 void BPY_context_update(bContext *C)
103 /* don't do this from a non-main (e.g. render) thread, it can cause a race
104 * condition on C->data.recursion. ideal solution would be to disable
105 * context entirely from non-main threads, but that's more complicated */
106 if (!BLI_thread_is_main())
110 bpy_import_main_set(CTX_data_main(C));
111 BPY_modules_update(C); /* can give really bad results if this isn't here */
114 void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
119 *gilstate = PyGILState_Ensure();
121 if (py_call_level == 1) {
122 BPY_context_update(C);
125 if (bpy_timer_count == 0) {
126 /* record time from the beginning */
127 bpy_timer = PIL_check_seconds_timer();
128 bpy_timer_run = bpy_timer_run_tot = 0.0;
130 bpy_timer_run = PIL_check_seconds_timer();
138 /* context should be used but not now because it causes some bugs */
139 void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate)
144 PyGILState_Release(*gilstate);
146 if (py_call_level < 0) {
147 fprintf(stderr, "ERROR: Python context internal state bug. this should not happen!\n");
149 else if (py_call_level == 0) {
150 /* XXX - Calling classes currently wont store the context :\,
151 * cant set NULL because of this. but this is very flakey still. */
153 BPy_SetContext(NULL);
154 bpy_import_main_set(NULL);
158 bpy_timer_run_tot += PIL_check_seconds_timer() - bpy_timer_run;
165 void BPY_text_free_code(Text *text)
167 if (text->compiled) {
168 PyGILState_STATE gilstate;
169 bool use_gil = !PYC_INTERPRETER_ACTIVE;
172 gilstate = PyGILState_Ensure();
174 Py_DECREF((PyObject *)text->compiled);
175 text->compiled = NULL;
178 PyGILState_Release(gilstate);
182 void BPY_modules_update(bContext *C)
184 #if 0 /* slow, this runs all the time poll, draw etc 100's of time a sec. */
185 PyObject *mod = PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
186 PyModule_AddObject(mod, "data", BPY_rna_module());
187 PyModule_AddObject(mod, "types", BPY_rna_types()); /* atm this does not need updating */
190 /* refreshes the main struct */
191 BPY_update_rna_module();
192 if (bpy_context_module)
193 bpy_context_module->ptr.data = (void *)C;
196 void BPY_context_set(bContext *C)
201 /* defined in AUD_C-API.cpp */
202 extern PyObject *AUD_initPython(void);
205 /* defined in cycles module */
206 static PyObject *CCL_initPython(void)
208 return (PyObject *)CCL_python_module_init();
212 static struct _inittab bpy_internal_modules[] = {
213 {(char *)"mathutils", PyInit_mathutils},
214 // {(char *)"mathutils.geometry", PyInit_mathutils_geometry},
215 // {(char *)"mathutils.noise", PyInit_mathutils_noise},
216 {(char *)"_bpy_path", BPyInit__bpy_path},
217 {(char *)"bgl", BPyInit_bgl},
218 {(char *)"blf", BPyInit_blf},
219 {(char *)"bmesh", BPyInit_bmesh},
220 // {(char *)"bmesh.types", BPyInit_bmesh_types},
221 // {(char *)"bmesh.utils", BPyInit_bmesh_utils},
222 #ifdef WITH_AUDASPACE
223 {(char *)"aud", AUD_initPython},
226 {(char *)"_cycles", CCL_initPython},
228 {(char *)"gpu", GPU_initPython},
229 {(char *)"idprop", BPyInit_idprop},
233 /* call BPY_context_set first */
234 void BPY_python_start(int argc, const char **argv)
236 #ifndef WITH_PYTHON_MODULE
237 PyThreadState *py_tstate = NULL;
238 const char *py_path_bundle = BLI_get_folder(BLENDER_SYSTEM_PYTHON, NULL);
240 /* not essential but nice to set our name */
241 static wchar_t program_path_wchar[FILE_MAX]; /* python holds a reference */
242 BLI_strncpy_wchar_from_utf8(program_path_wchar, BLI_program_path(), sizeof(program_path_wchar) / sizeof(wchar_t));
243 Py_SetProgramName(program_path_wchar);
245 /* must run before python initializes */
246 PyImport_ExtendInittab(bpy_internal_modules);
248 /* allow to use our own included python */
249 PyC_SetHomePath(py_path_bundle);
251 /* without this the sys.stdout may be set to 'ascii'
252 * (it is on my system at least), where printing unicode values will raise
253 * an error, this is highly annoying, another stumbling block for devs,
254 * so use a more relaxed error handler and enforce utf-8 since the rest of
255 * blender is utf-8 too - campbell */
257 /* XXX, update: this is unreliable! 'PYTHONIOENCODING' is ignored in MS-Windows
258 * when dynamically linked, see: [#31555] for details.
259 * Python doesn't expose a good way to set this. */
260 BLI_setenv("PYTHONIOENCODING", "utf-8:surrogateescape");
262 /* Update, Py3.3 resolves attempting to parse non-existing header */
264 /* Python 3.2 now looks for '2.xx/python/include/python3.2d/pyconfig.h' to
265 * parse from the 'sysconfig' module which is used by 'site',
266 * so for now disable site. alternatively we could copy the file. */
267 if (py_path_bundle) {
276 /* THIS IS BAD: see http://bugs.python.org/issue16129 */
277 /* this clobbers the stdout on exit (no 'MEM_printmemlist_stats') */
279 /* until python provides a reliable way to set the env var */
280 PyRun_SimpleString("import sys, io\n"
281 "sys.__backup_stdio__ = sys.__stdout__, sys.__stderr__\n" /* else we loose the FD's [#32720] */
282 "sys.__stdout__ = sys.stdout = io.TextIOWrapper(io.open(sys.stdout.fileno(), 'wb', -1), "
283 "encoding='utf-8', errors='surrogateescape', newline='\\n', line_buffering=True)\n"
284 "sys.__stderr__ = sys.stderr = io.TextIOWrapper(io.open(sys.stderr.fileno(), 'wb', -1), "
285 "encoding='utf-8', errors='surrogateescape', newline='\\n', line_buffering=True)\n");
286 if (PyErr_Occurred()) {
291 /* end the baddness */
294 // PySys_SetArgv(argc, argv); /* broken in py3, not a huge deal */
295 /* sigh, why do python guys not have a (char **) version anymore? */
298 PyObject *py_argv = PyList_New(argc);
299 for (i = 0; i < argc; i++) {
300 /* should fix bug #20021 - utf path name problems, by replacing
301 * PyUnicode_FromString, with this one */
302 PyList_SET_ITEM(py_argv, i, PyC_UnicodeFromByte(argv[i]));
305 PySys_SetObject("argv", py_argv);
309 /* Initialize thread support (also acquires lock) */
310 PyEval_InitThreads();
315 /* must run before python initializes */
316 /* broken in py3.3, load explicitly below */
317 // PyImport_ExtendInittab(bpy_internal_modules);
320 bpy_intern_string_init();
323 #ifdef WITH_PYTHON_MODULE
325 /* Manually load all modules */
326 struct _inittab *inittab_item;
327 PyObject *sys_modules = PyImport_GetModuleDict();
329 for (inittab_item = bpy_internal_modules; inittab_item->name; inittab_item++) {
330 PyObject *mod = inittab_item->initfunc();
332 PyDict_SetItemString(sys_modules, inittab_item->name, mod);
338 // Py_DECREF(mod); /* ideally would decref, but in this case we never want to free */
343 /* bpy.* and lets us import it */
346 bpy_import_init(PyEval_GetBuiltins());
350 #ifndef WITH_PYTHON_MODULE
351 /* py module runs atexit when bpy is freed */
352 BPY_atexit_register(); /* this can init any time */
354 py_tstate = PyGILState_GetThisThreadState();
355 PyEval_ReleaseThread(py_tstate);
359 void BPY_python_end(void)
361 // fprintf(stderr, "Ending Python!\n");
363 PyGILState_Ensure(); /* finalizing, no need to grab the state */
365 /* free other python data. */
368 /* clear all python data from structs */
370 bpy_intern_string_exit();
372 #ifndef WITH_PYTHON_MODULE
373 BPY_atexit_unregister(); /* without this we get recursive calls to WM_exit */
379 /* measure time since py started */
380 bpy_timer = PIL_check_seconds_timer() - bpy_timer;
382 printf("*bpy stats* - ");
383 printf("tot exec: %d, ", bpy_timer_count);
384 printf("tot run: %.4fsec, ", bpy_timer_run_tot);
385 if (bpy_timer_count > 0)
386 printf("average run: %.6fsec, ", (bpy_timer_run_tot / bpy_timer_count));
389 printf("tot usage %.4f%%", (bpy_timer_run_tot / bpy_timer) * 100.0);
393 // fprintf(stderr, "Ending Python Done!\n");
399 static void python_script_error_jump_text(struct Text *text)
403 python_script_error_jump(text->id.name + 2, &lineno, &offset);
405 /* select the line with the error */
406 txt_move_to(text, lineno - 1, INT_MAX, false);
407 txt_move_to(text, lineno - 1, offset, true);
411 /* super annoying, undo _PyModule_Clear(), bug [#23871] */
412 #define PYMODULE_CLEAR_WORKAROUND
414 #ifdef PYMODULE_CLEAR_WORKAROUND
415 /* bad!, we should never do this, but currently only safe way I could find to keep namespace.
416 * from being cleared. - campbell */
420 /* ommit other values, we only want the dict. */
424 static int python_script_exec(bContext *C, const char *fn, struct Text *text,
425 struct ReportList *reports, const bool do_jump)
427 Main *bmain_old = CTX_data_main(C);
428 PyObject *main_mod = NULL;
429 PyObject *py_dict = NULL, *py_result = NULL;
430 PyGILState_STATE gilstate;
432 BLI_assert(fn || text);
434 if (fn == NULL && text == NULL) {
438 bpy_context_set(C, &gilstate);
440 PyC_MainModule_Backup(&main_mod);
443 char fn_dummy[FILE_MAXDIR];
444 bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);
446 if (text->compiled == NULL) { /* if it wasn't already compiled, do it now */
447 char *buf = txt_to_buf(text);
449 text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input);
453 if (PyErr_Occurred()) {
455 python_script_error_jump_text(text);
457 BPY_text_free_code(text);
461 if (text->compiled) {
462 py_dict = PyC_DefaultNameSpace(fn_dummy);
463 py_result = PyEval_EvalCode(text->compiled, py_dict, py_dict);
468 FILE *fp = BLI_fopen(fn, "r");
471 py_dict = PyC_DefaultNameSpace(fn);
474 /* Previously we used PyRun_File to run directly the code on a FILE
475 * object, but as written in the Python/C API Ref Manual, chapter 2,
476 * 'FILE structs for different C libraries can be different and
478 * So now we load the script file data to a buffer */
484 pystring = MEM_mallocN(strlen(fn) + 37, "pystring");
486 sprintf(pystring, "f=open(r'%s');exec(f.read());f.close()", fn);
487 py_result = PyRun_String(pystring, Py_file_input, py_dict, py_dict);
491 py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);
496 PyErr_Format(PyExc_IOError,
497 "Python file \"%s\" could not be opened: %s",
498 fn, strerror(errno));
506 /* ensure text is valid before use, the script may have freed its self */
507 Main *bmain_new = CTX_data_main(C);
508 if ((bmain_old == bmain_new) && (BLI_findindex(&bmain_new->text, text) != -1)) {
509 python_script_error_jump_text(text);
513 BPy_errors_to_report(reports);
516 Py_DECREF(py_result);
520 #ifdef PYMODULE_CLEAR_WORKAROUND
521 PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItemString(PyThreadState_GET()->interp->modules, "__main__");
522 PyObject *dict_back = mmod->md_dict;
523 /* freeing the module will clear the namespace,
524 * gives problems running classes defined in this namespace being used later. */
525 mmod->md_dict = NULL;
526 Py_DECREF(dict_back);
529 #undef PYMODULE_CLEAR_WORKAROUND
532 PyC_MainModule_Restore(main_mod);
534 bpy_context_clear(C, &gilstate);
536 return (py_result != NULL);
539 /* Can run a file or text block */
540 int BPY_filepath_exec(bContext *C, const char *filepath, struct ReportList *reports)
542 return python_script_exec(C, filepath, NULL, reports, false);
546 int BPY_text_exec(bContext *C, struct Text *text, struct ReportList *reports, const bool do_jump)
548 return python_script_exec(C, NULL, text, reports, do_jump);
551 void BPY_DECREF(void *pyob_ptr)
553 PyGILState_STATE gilstate = PyGILState_Ensure();
554 Py_DECREF((PyObject *)pyob_ptr);
555 PyGILState_Release(gilstate);
558 void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr)
560 PyGILState_STATE gilstate = PyGILState_Ensure();
561 const int do_invalidate = (Py_REFCNT((PyObject *)pyob_ptr) > 1);
562 Py_DECREF((PyObject *)pyob_ptr);
564 pyrna_invalidate(pyob_ptr);
566 PyGILState_Release(gilstate);
570 /* return -1 on error, else 0 */
571 int BPY_button_exec(bContext *C, const char *expr, double *value, const short verbose)
573 PyGILState_STATE gilstate;
574 PyObject *py_dict, *mod, *retval;
576 PyObject *main_mod = NULL;
578 if (!value || !expr) return -1;
580 if (expr[0] == '\0') {
585 bpy_context_set(C, &gilstate);
587 PyC_MainModule_Backup(&main_mod);
589 py_dict = PyC_DefaultNameSpace("<blender button>");
591 mod = PyImport_ImportModule("math");
593 PyDict_Merge(py_dict, PyModule_GetDict(mod), 0); /* 0 - don't overwrite existing values */
596 else { /* highly unlikely but possibly */
601 retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
603 if (retval == NULL) {
609 if (PyTuple_Check(retval)) {
610 /* Users my have typed in 10km, 2m
611 * add up all values */
615 for (i = 0; i < PyTuple_GET_SIZE(retval); i++) {
616 const double val_item = PyFloat_AsDouble(PyTuple_GET_ITEM(retval, i));
617 if (val_item == -1 && PyErr_Occurred()) {
625 val = PyFloat_AsDouble(retval);
629 if (val == -1 && PyErr_Occurred()) {
632 else if (!finite(val)) {
642 BPy_errors_to_report(CTX_wm_reports(C));
649 PyC_MainModule_Restore(main_mod);
651 bpy_context_clear(C, &gilstate);
656 int BPY_string_exec(bContext *C, const char *expr)
658 PyGILState_STATE gilstate;
659 PyObject *main_mod = NULL;
660 PyObject *py_dict, *retval;
662 Main *bmain_back; /* XXX, quick fix for release (Copy Settings crash), needs further investigation */
664 if (!expr) return -1;
666 if (expr[0] == '\0') {
670 bpy_context_set(C, &gilstate);
672 PyC_MainModule_Backup(&main_mod);
674 py_dict = PyC_DefaultNameSpace("<blender string>");
676 bmain_back = bpy_import_main_get();
677 bpy_import_main_set(CTX_data_main(C));
679 retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
681 bpy_import_main_set(bmain_back);
683 if (retval == NULL) {
686 BPy_errors_to_report(CTX_wm_reports(C));
692 PyC_MainModule_Restore(main_mod);
694 bpy_context_clear(C, &gilstate);
700 void BPY_modules_load_user(bContext *C)
702 PyGILState_STATE gilstate;
703 Main *bmain = CTX_data_main(C);
706 /* can happen on file load */
710 /* update pointers since this can run from a nested script
713 BPY_context_update(C);
716 bpy_context_set(C, &gilstate);
718 for (text = bmain->text.first; text; text = text->id.next) {
719 if (text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name + 2, ".py")) {
720 if (!(G.f & G_SCRIPT_AUTOEXEC)) {
721 printf("scripts disabled for \"%s\", skipping '%s'\n", bmain->name, text->id.name + 2);
724 PyObject *module = bpy_text_import(text);
726 if (module == NULL) {
734 /* check if the script loaded a new file */
735 if (bmain != CTX_data_main(C)) {
741 bpy_context_clear(C, &gilstate);
744 int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *result)
746 PyGILState_STATE gilstate;
747 bool use_gil = !PYC_INTERPRETER_ACTIVE;
751 PointerRNA *ptr = NULL;
755 gilstate = PyGILState_Ensure();
757 pyctx = (PyObject *)CTX_py_dict_get(C);
758 item = PyDict_GetItemString(pyctx, member);
763 else if (item == Py_None) {
766 else if (BPy_StructRNA_Check(item)) {
767 ptr = &(((BPy_StructRNA *)item)->ptr);
769 //result->ptr = ((BPy_StructRNA *)item)->ptr;
770 CTX_data_pointer_set(result, ptr->id.data, ptr->type, ptr->data);
771 CTX_data_type_set(result, CTX_DATA_TYPE_POINTER);
774 else if (PySequence_Check(item)) {
775 PyObject *seq_fast = PySequence_Fast(item, "bpy_context_get sequence conversion");
776 if (seq_fast == NULL) {
781 int len = PySequence_Fast_GET_SIZE(seq_fast);
783 for (i = 0; i < len; i++) {
784 PyObject *list_item = PySequence_Fast_GET_ITEM(seq_fast, i);
786 if (BPy_StructRNA_Check(list_item)) {
788 CollectionPointerLink *link = MEM_callocN(sizeof(CollectionPointerLink), "bpy_context_get");
789 link->ptr = ((BPy_StructRNA *)item)->ptr;
790 BLI_addtail(&result->list, link);
792 ptr = &(((BPy_StructRNA *)list_item)->ptr);
793 CTX_data_list_add(result, ptr->id.data, ptr->type, ptr->data);
796 printf("PyContext: '%s' list item not a valid type in sequece type '%s'\n",
797 member, Py_TYPE(item)->tp_name);
802 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
808 if (item) printf("PyContext '%s' not a valid type\n", member);
809 else printf("PyContext '%s' not found\n", member);
812 if (G.debug & G_DEBUG_PYTHON) {
813 printf("PyContext '%s' found\n", member);
818 PyGILState_Release(gilstate);
823 #ifdef WITH_PYTHON_MODULE
824 #include "BLI_fileops.h"
825 /* TODO, reloading the module isn't functional at the moment. */
827 static void bpy_module_free(void *mod);
828 extern int main_python_enter(int argc, const char **argv);
829 extern void main_python_exit(void);
830 static struct PyModuleDef bpy_proxy_def = {
831 PyModuleDef_HEAD_INIT,
835 NULL, /* m_methods */
837 NULL, /* m_traverse */
839 bpy_module_free, /* m_free */
844 /* Type-specific fields go here. */
848 /* call once __file__ is set */
849 static void bpy_module_delay_init(PyObject *bpy_proxy)
854 /* updating the module dict below will loose the reference to __file__ */
855 PyObject *filename_obj = PyModule_GetFilenameObject(bpy_proxy);
857 const char *filename_rel = _PyUnicode_AsString(filename_obj); /* can be relative */
858 char filename_abs[1024];
860 BLI_strncpy(filename_abs, filename_rel, sizeof(filename_abs));
861 BLI_path_cwd(filename_abs);
863 argv[0] = filename_abs;
866 // printf("module found %s\n", argv[0]);
868 main_python_enter(argc, argv);
870 /* initialized in BPy_init_modules() */
871 PyDict_Update(PyModule_GetDict(bpy_proxy), PyModule_GetDict(bpy_package_py));
874 static void dealloc_obj_dealloc(PyObject *self);
876 static PyTypeObject dealloc_obj_Type = {{{0}}};
878 /* use our own dealloc so we can free a property if we use one */
879 static void dealloc_obj_dealloc(PyObject *self)
881 bpy_module_delay_init(((dealloc_obj *)self)->mod);
883 /* Note, for subclassed PyObjects we cant just call PyObject_DEL() directly or it will crash */
884 dealloc_obj_Type.tp_free(self);
893 PyObject *bpy_proxy = PyModule_Create(&bpy_proxy_def);
896 * 1) this init function is expected to have a private member defined - 'md_def'
897 * but this is only set for C defined modules (not py packages)
898 * so we cant return 'bpy_package_py' as is.
900 * 2) there is a 'bpy' C module for python to load which is basically all of blender,
901 * and there is scripts/bpy/__init__.py,
902 * we may end up having to rename this module so there is no naming conflict here eg:
903 * 'from blender import bpy'
905 * 3) we don't know the filename at this point, workaround by assigning a dummy value
906 * which calls back when its freed so the real loading can take place.
909 /* assign an object which is freed after __file__ is assigned */
912 /* assign dummy type */
913 dealloc_obj_Type.tp_name = "dealloc_obj";
914 dealloc_obj_Type.tp_basicsize = sizeof(dealloc_obj);
915 dealloc_obj_Type.tp_dealloc = dealloc_obj_dealloc;
916 dealloc_obj_Type.tp_flags = Py_TPFLAGS_DEFAULT;
918 if (PyType_Ready(&dealloc_obj_Type) < 0)
921 dob = (dealloc_obj *) dealloc_obj_Type.tp_alloc(&dealloc_obj_Type, 0);
922 dob->mod = bpy_proxy; /* borrow */
923 PyModule_AddObject(bpy_proxy, "__file__", (PyObject *)dob); /* borrow */
928 static void bpy_module_free(void *UNUSED(mod))
936 /* EVIL, define text.c functions here... */
938 int text_check_identifier_unicode(const unsigned int ch)
940 return (ch < 255 && text_check_identifier((char)ch)) || Py_UNICODE_ISALNUM(ch);
943 int text_check_identifier_nodigit_unicode(const unsigned int ch)
945 return (ch < 255 && text_check_identifier_nodigit((char)ch)) || Py_UNICODE_ISALPHA(ch);