Merge with 2.5 -r 21515:21619.
This commit is contained in:
@@ -114,6 +114,13 @@ PyObject *Mathutils_Init(const char *from)
|
||||
|
||||
//seed the generator for the rand function
|
||||
BLI_srand((unsigned int) (PIL_check_seconds_timer() * 0x7FFFFFFF));
|
||||
|
||||
#if (PY_VERSION_HEX < 0x03000000)
|
||||
vector_Type.tp_flags |= Py_TPFLAGS_CHECKTYPES;
|
||||
matrix_Type.tp_flags |= Py_TPFLAGS_CHECKTYPES;
|
||||
euler_Type.tp_flags |= Py_TPFLAGS_CHECKTYPES;
|
||||
quaternion_Type.tp_flags |= Py_TPFLAGS_CHECKTYPES;
|
||||
#endif
|
||||
|
||||
if( PyType_Ready( &vector_Type ) < 0 )
|
||||
return NULL;
|
||||
|
||||
@@ -462,8 +462,7 @@ void BPY_run_ui_scripts(bContext *C, int reload)
|
||||
|
||||
PyGILState_STATE gilstate;
|
||||
PyObject *mod;
|
||||
PyObject *sys_path_orig;
|
||||
PyObject *sys_path_new;
|
||||
PyObject *sys_path;
|
||||
|
||||
gilstate = PyGILState_Ensure();
|
||||
|
||||
@@ -471,6 +470,10 @@ void BPY_run_ui_scripts(bContext *C, int reload)
|
||||
BPy_SetContext(C);
|
||||
bpy_import_main_set(CTX_data_main(C));
|
||||
|
||||
|
||||
sys_path= PySys_GetObject("path"); /* borrow */
|
||||
PyList_Insert(sys_path, 0, Py_None); /* place holder, resizes the list */
|
||||
|
||||
for(a=0; dirs[a]; a++) {
|
||||
dirname= BLI_gethome_folder(dirs[a]);
|
||||
|
||||
@@ -481,15 +484,9 @@ void BPY_run_ui_scripts(bContext *C, int reload)
|
||||
|
||||
if(!dir)
|
||||
continue;
|
||||
|
||||
/* backup sys.path */
|
||||
sys_path_orig= PySys_GetObject("path");
|
||||
Py_INCREF(sys_path_orig); /* dont free it */
|
||||
|
||||
sys_path_new= PyList_New(1);
|
||||
PyList_SET_ITEM(sys_path_new, 0, PyUnicode_FromString(dirname));
|
||||
PySys_SetObject("path", sys_path_new);
|
||||
Py_DECREF(sys_path_new);
|
||||
/* set the first dir in the sys.path for fast importing of modules */
|
||||
PyList_SetItem(sys_path, 0, PyUnicode_FromString(dirname)); /* steals the ref */
|
||||
|
||||
while((de = readdir(dir)) != NULL) {
|
||||
/* We could stat the file but easier just to let python
|
||||
@@ -519,11 +516,10 @@ void BPY_run_ui_scripts(bContext *C, int reload)
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
PySys_SetObject("path", sys_path_orig);
|
||||
Py_DECREF(sys_path_orig);
|
||||
}
|
||||
|
||||
PyList_SetSlice(sys_path, 0, 1, NULL); /* remove the first item */
|
||||
|
||||
bpy_import_main_set(NULL);
|
||||
|
||||
PyGILState_Release(gilstate);
|
||||
|
||||
@@ -68,7 +68,7 @@ static PyObject *pyop_base_call( PyObject * self, PyObject * args, PyObject * k
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ot= WM_operatortype_find(opname);
|
||||
ot= WM_operatortype_find(opname, 1);
|
||||
if (ot == NULL) {
|
||||
PyErr_Format( PyExc_SystemError, "Operator \"%s\"could not be found", opname);
|
||||
return NULL;
|
||||
@@ -130,12 +130,19 @@ static PyObject *pyop_base_getattro( BPy_OperatorBase * self, PyObject *pyname )
|
||||
PyObject *ret;
|
||||
wmOperatorType *ot;
|
||||
|
||||
if ((ret = PyObject_GenericGetAttr((PyObject *)self, pyname))) {
|
||||
/* do nothing, this accounts for methoddef's add and remove */
|
||||
}
|
||||
else if ((ot= WM_operatortype_find(name))) {
|
||||
/* First look for the operator, then our own methods if that fails.
|
||||
* when methods are searched first, PyObject_GenericGetAttr will raise an error
|
||||
* each time we want to call an operator, we could clear the error but I prefer
|
||||
* not to since calling operators is a lot more common then adding and removing. - Campbell */
|
||||
|
||||
if ((ot= WM_operatortype_find(name, 1))) {
|
||||
ret = PyCFunction_New( pyop_base_call_meth, pyname); /* set the name string as self, PyCFunction_New incref's self */
|
||||
}
|
||||
else if ((ret = PyObject_GenericGetAttr((PyObject *)self, pyname))) {
|
||||
/* do nothing, this accounts for methoddef's add and remove
|
||||
* An exception is raised when PyObject_GenericGetAttr fails
|
||||
* but its ok because its overwritten below */
|
||||
}
|
||||
else {
|
||||
PyErr_Format( PyExc_AttributeError, "Operator \"%s\" not found", name);
|
||||
ret= NULL;
|
||||
@@ -170,7 +177,7 @@ static PyObject *pyop_base_rna(PyObject *self, PyObject *pyname)
|
||||
char *name = _PyUnicode_AsString(pyname);
|
||||
wmOperatorType *ot;
|
||||
|
||||
if ((ot= WM_operatortype_find(name))) {
|
||||
if ((ot= WM_operatortype_find(name, 1))) {
|
||||
BPy_StructRNA *pyrna;
|
||||
PointerRNA ptr;
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#define PYOP_ATTR_UINAME "__label__"
|
||||
#define PYOP_ATTR_IDNAME "__name__" /* use pythons class name */
|
||||
#define PYOP_ATTR_DESCRIPTION "__doc__" /* use pythons docstring */
|
||||
#define PYOP_ATTR_REGISTER "__register__" /* True/False. if this python operator should be registered */
|
||||
|
||||
static struct BPY_flag_def pyop_ret_flags[] = {
|
||||
{"RUNNING_MODAL", OPERATOR_RUNNING_MODAL},
|
||||
@@ -210,8 +211,8 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve
|
||||
|
||||
/* get class name */
|
||||
item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME);
|
||||
Py_DECREF(item);
|
||||
strcpy(class_name, _PyUnicode_AsString(item));
|
||||
Py_DECREF(item);
|
||||
|
||||
fprintf(stderr, "%s's %s returned %s\n", class_name, mode == PYOP_EXEC ? "execute" : "invoke", flag_str);
|
||||
}
|
||||
@@ -246,14 +247,14 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
||||
|
||||
/* identifiers */
|
||||
item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME);
|
||||
Py_DECREF(item);
|
||||
ot->idname= _PyUnicode_AsString(item);
|
||||
Py_DECREF(item);
|
||||
|
||||
|
||||
item= PyObject_GetAttrString(py_class, PYOP_ATTR_UINAME);
|
||||
if (item) {
|
||||
Py_DECREF(item);
|
||||
ot->name= _PyUnicode_AsString(item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
else {
|
||||
ot->name= ot->idname;
|
||||
@@ -261,8 +262,8 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
||||
}
|
||||
|
||||
item= PyObject_GetAttrString(py_class, PYOP_ATTR_DESCRIPTION);
|
||||
Py_DECREF(item);
|
||||
ot->description= (item && PyUnicode_Check(item)) ? _PyUnicode_AsString(item):"";
|
||||
Py_DECREF(item);
|
||||
|
||||
/* api callbacks, detailed checks dont on adding */
|
||||
if (PyObject_HasAttrString(py_class, "invoke"))
|
||||
@@ -274,13 +275,22 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
||||
|
||||
ot->pyop_data= userdata;
|
||||
|
||||
/* flags */
|
||||
item= PyObject_GetAttrString(py_class, PYOP_ATTR_REGISTER);
|
||||
if (item) {
|
||||
ot->flag= PyObject_IsTrue(item)!=0 ? OPTYPE_REGISTER:0;
|
||||
Py_DECREF(item);
|
||||
}
|
||||
else {
|
||||
ot->flag= OPTYPE_REGISTER; /* unspesified, leave on for now to help debug */
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
props= PyObject_GetAttrString(py_class, PYOP_ATTR_PROP);
|
||||
|
||||
if (props) {
|
||||
PyObject *dummy_args = PyTuple_New(0);
|
||||
int i;
|
||||
|
||||
Py_DECREF(props);
|
||||
|
||||
for(i=0; i<PyList_Size(props); i++) {
|
||||
PyObject *py_func_ptr, *py_kw, *py_srna_cobject, *py_ret;
|
||||
@@ -310,6 +320,7 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
||||
// expect a tuple with a CObject and a dict
|
||||
}
|
||||
Py_DECREF(dummy_args);
|
||||
Py_DECREF(props);
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
@@ -340,16 +351,16 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
|
||||
// in python would be...
|
||||
//PyObject *optype = PyObject_GetAttrString(PyObject_GetAttrString(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), "types"), "Operator");
|
||||
base_class = PyObject_GetAttrStringArgs(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), 2, "types", "Operator");
|
||||
Py_DECREF(base_class);
|
||||
|
||||
if(BPY_class_validate("Operator", py_class, base_class, pyop_class_attr_values, NULL) < 0) {
|
||||
return NULL; /* BPY_class_validate sets the error */
|
||||
}
|
||||
Py_DECREF(base_class);
|
||||
|
||||
/* class name is used for operator ID - this can be changed later if we want */
|
||||
item= PyObject_GetAttrString(py_class, PYOP_ATTR_IDNAME);
|
||||
Py_DECREF(item);
|
||||
idname = _PyUnicode_AsString(item);
|
||||
Py_DECREF(item);
|
||||
|
||||
/* remove if it already exists */
|
||||
if ((ot=WM_operatortype_exists(idname))) {
|
||||
@@ -362,7 +373,6 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
|
||||
/* If we have properties set, check its a list of dicts */
|
||||
item= PyObject_GetAttrString(py_class, PYOP_ATTR_PROP);
|
||||
if (item) {
|
||||
Py_DECREF(item);
|
||||
for(i=0; i<PyList_Size(item); i++) {
|
||||
PyObject *py_args = PyList_GET_ITEM(item, i);
|
||||
PyObject *py_func_ptr, *py_kw; /* place holders */
|
||||
@@ -372,6 +382,7 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
Py_DECREF(item);
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
|
||||
@@ -227,10 +227,16 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
EnumPropertyItem *item;
|
||||
char *result;
|
||||
int free;
|
||||
int free= 0;
|
||||
|
||||
RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
|
||||
result= (char*)BPy_enum_as_string(item);
|
||||
if(item) {
|
||||
result= (char*)BPy_enum_as_string(item);
|
||||
}
|
||||
else {
|
||||
result= "";
|
||||
}
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
|
||||
@@ -321,12 +327,12 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
|
||||
ret = PyUnicode_FromString( identifier );
|
||||
} else {
|
||||
EnumPropertyItem *item;
|
||||
int free;
|
||||
int free= 0;
|
||||
|
||||
/* don't throw error here, can't trust blender 100% to give the
|
||||
* right values, python code should not generate error for that */
|
||||
RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
|
||||
if(item->identifier) {
|
||||
if(item && item->identifier) {
|
||||
ret = PyUnicode_FromString( item->identifier );
|
||||
}
|
||||
else {
|
||||
@@ -1842,20 +1848,12 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data)
|
||||
if (RNA_property_enum_identifier(BPy_GetContext(), ptr, prop, val, &identifier)) {
|
||||
ret = PyUnicode_FromString( identifier );
|
||||
} else {
|
||||
EnumPropertyItem *item;
|
||||
int free;
|
||||
|
||||
/* don't throw error here, can't trust blender 100% to give the
|
||||
* right values, python code should not generate error for that */
|
||||
RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
|
||||
if(item[0].identifier)
|
||||
ret = PyUnicode_FromString( item[0].identifier );
|
||||
else
|
||||
ret = PyUnicode_FromString( "" );
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
|
||||
/* prefer not fail silently incase of api errors, maybe disable it later */
|
||||
char error_str[128];
|
||||
sprintf(error_str, "RNA Warning: Current value \"%d\" matches no enum", val);
|
||||
PyErr_Warn(PyExc_RuntimeWarning, error_str);
|
||||
|
||||
ret = PyUnicode_FromString( "" );
|
||||
/*PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val);
|
||||
ret = NULL;*/
|
||||
}
|
||||
|
||||
@@ -557,6 +557,7 @@ PyObject *BPY_ui_module( void )
|
||||
PyModule_AddObject( mod, "SCRIPT", PyLong_FromSsize_t(SPACE_SCRIPT) );
|
||||
PyModule_AddObject( mod, "TIME", PyLong_FromSsize_t(SPACE_TIME) );
|
||||
PyModule_AddObject( mod, "NODE", PyLong_FromSsize_t(SPACE_NODE) );
|
||||
PyModule_AddObject( mod, "CONSOLE", PyLong_FromSsize_t(SPACE_CONSOLE) );
|
||||
|
||||
/* INCREF since its its assumed that all these functions return the
|
||||
* module with a new ref like PyDict_New, since they are passed to
|
||||
|
||||
@@ -353,8 +353,8 @@ PyObject *BPY_exception_buffer(void)
|
||||
PyObject *stderr_backup = PySys_GetObject("stderr"); /* borrowed */
|
||||
PyObject *string_io = NULL;
|
||||
PyObject *string_io_buf = NULL;
|
||||
PyObject *string_io_mod;
|
||||
PyObject *string_io_getvalue;
|
||||
PyObject *string_io_mod= NULL;
|
||||
PyObject *string_io_getvalue= NULL;
|
||||
|
||||
PyObject *error_type, *error_value, *error_traceback;
|
||||
|
||||
@@ -374,14 +374,11 @@ PyObject *BPY_exception_buffer(void)
|
||||
#else
|
||||
if(! (string_io_mod= PyImport_ImportModule("io")) ) {
|
||||
#endif
|
||||
return NULL;
|
||||
goto error_cleanup;
|
||||
} else if (! (string_io = PyObject_CallMethod(string_io_mod, "StringIO", NULL))) {
|
||||
Py_DECREF(string_io_mod);
|
||||
return NULL;
|
||||
goto error_cleanup;
|
||||
} else if (! (string_io_getvalue= PyObject_GetAttrString(string_io, "getvalue"))) {
|
||||
Py_DECREF(string_io_mod);
|
||||
Py_DECREF(string_io);
|
||||
return NULL;
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
Py_INCREF(stdout_backup); // since these were borrowed we dont want them freed when replaced.
|
||||
@@ -408,6 +405,18 @@ PyObject *BPY_exception_buffer(void)
|
||||
|
||||
PyErr_Clear();
|
||||
return string_io_buf;
|
||||
|
||||
|
||||
error_cleanup:
|
||||
/* could not import the module so print the error and close */
|
||||
Py_XDECREF(string_io_mod);
|
||||
Py_XDECREF(string_io);
|
||||
|
||||
PyErr_Restore(error_type, error_value, error_traceback);
|
||||
PyErr_Print(); /* print the error */
|
||||
PyErr_Clear();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *BPy_enum_as_string(EnumPropertyItem *item)
|
||||
|
||||
Reference in New Issue
Block a user