workaround for python bug [#24400] If Script is executed with TEXT Editor, it becomes an error.
having the blend file as a part of the __file__ variable is not essential, this is fixed in python 3.2 so add an ifdef and don't use the blend file path for py older then 3.2.
This commit is contained in:
@@ -26,7 +26,13 @@
|
|||||||
* ***** END GPL LICENSE BLOCK *****
|
* ***** END GPL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
#include "compile.h" /* for the PyCodeObject */
|
||||||
|
#include "eval.h" /* for PyEval_EvalCode */
|
||||||
|
#include "osdefs.h" /* for 'SEP' */
|
||||||
|
|
||||||
#include "bpy_internal_import.h"
|
#include "bpy_internal_import.h"
|
||||||
|
|
||||||
#include "DNA_text_types.h"
|
#include "DNA_text_types.h"
|
||||||
|
|
||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
@@ -62,16 +68,17 @@ void bpy_import_main_set(struct Main *maggie)
|
|||||||
/* returns a dummy filename for a textblock so we can tell what file a text block comes from */
|
/* returns a dummy filename for a textblock so we can tell what file a text block comes from */
|
||||||
void bpy_text_filename_get(char *fn, Text *text)
|
void bpy_text_filename_get(char *fn, Text *text)
|
||||||
{
|
{
|
||||||
sprintf(fn, "%s/%s", text->id.lib ? text->id.lib->filepath : G.main->name, text->id.name+2);
|
#if PY_VERSION_HEX >= 0x03020000
|
||||||
|
sprintf(fn, "%s%c%s", text->id.lib ? text->id.lib->filepath : G.main->name, SEP, text->id.name+2);
|
||||||
/* XXX, this is a bug in python's Py_CompileString()!
|
#else
|
||||||
|
/* this is a bug in python's Py_CompileString()!, fixed for python 3.2.
|
||||||
the string encoding should not be required to be utf-8
|
the string encoding should not be required to be utf-8
|
||||||
reported: http://bugs.python.org/msg115202
|
reported: http://bugs.python.org/msg115202 */
|
||||||
*/
|
strcpy(fn, text->id.name+2);
|
||||||
BLI_utf8_invalid_strip(fn, strlen(fn));
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *bpy_text_import( Text *text )
|
PyObject *bpy_text_import(Text *text)
|
||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
char modulename[24];
|
char modulename[24];
|
||||||
|
|||||||
@@ -28,8 +28,8 @@
|
|||||||
|
|
||||||
/* Note, the BGE needs to use this too, keep it minimal */
|
/* Note, the BGE needs to use this too, keep it minimal */
|
||||||
|
|
||||||
#ifndef EXPP_bpy_import_h
|
#ifndef BPY_INTERNAL_IMPORT_H
|
||||||
#define EXPP_bpy_import_h
|
#define BPY_INTERNAL_IMPORT_H
|
||||||
|
|
||||||
/* python redefines :/ */
|
/* python redefines :/ */
|
||||||
#ifdef _POSIX_C_SOURCE
|
#ifdef _POSIX_C_SOURCE
|
||||||
@@ -40,16 +40,12 @@
|
|||||||
#undef _XOPEN_SOURCE
|
#undef _XOPEN_SOURCE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include "compile.h" /* for the PyCodeObject */
|
|
||||||
#include "eval.h" /* for PyEval_EvalCode */
|
|
||||||
|
|
||||||
struct Text;
|
struct Text;
|
||||||
|
|
||||||
PyObject* bpy_text_import( struct Text *text );
|
PyObject* bpy_text_import(struct Text *text);
|
||||||
PyObject* bpy_text_import_name( char *name, int *found );
|
PyObject* bpy_text_import_name(char *name, int *found);
|
||||||
PyObject* bpy_text_reimport( PyObject *module, int *found );
|
PyObject* bpy_text_reimport(PyObject *module, int *found);
|
||||||
/* void bpy_text_clear_modules( int clear_all );*/ /* Clear user modules */
|
/* void bpy_text_clear_modules(int clear_all);*/ /* Clear user modules */
|
||||||
|
|
||||||
void bpy_text_filename_get(char *fn, struct Text *text);
|
void bpy_text_filename_get(char *fn, struct Text *text);
|
||||||
|
|
||||||
@@ -60,4 +56,4 @@ extern PyMethodDef bpy_reload_meth;
|
|||||||
struct Main *bpy_import_main_get(void);
|
struct Main *bpy_import_main_get(void);
|
||||||
void bpy_import_main_set(struct Main *maggie);
|
void bpy_import_main_set(struct Main *maggie);
|
||||||
|
|
||||||
#endif /* EXPP_bpy_import_h */
|
#endif /* BPY_INTERNAL_IMPORT_H */
|
||||||
|
|||||||
@@ -23,13 +23,12 @@
|
|||||||
* ***** END GPL LICENSE BLOCK *****
|
* ***** END GPL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* grr, python redefines */
|
/* grr, python redefines */
|
||||||
#ifdef _POSIX_C_SOURCE
|
#ifdef _POSIX_C_SOURCE
|
||||||
#undef _POSIX_C_SOURCE
|
#undef _POSIX_C_SOURCE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
#include "bpy.h"
|
#include "bpy.h"
|
||||||
#include "bpy_rna.h"
|
#include "bpy_rna.h"
|
||||||
|
|||||||
@@ -36,6 +36,16 @@
|
|||||||
|
|
||||||
#ifndef DISABLE_PYTHON
|
#ifndef DISABLE_PYTHON
|
||||||
|
|
||||||
|
#ifdef _POSIX_C_SOURCE
|
||||||
|
#undef _POSIX_C_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _XOPEN_SOURCE
|
||||||
|
#undef _XOPEN_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */
|
#include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */
|
||||||
#include "py_capi_utils.h"
|
#include "py_capi_utils.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user