Merged changes in the trunk up to revision 30952.

This commit is contained in:
2010-08-01 23:37:52 +00:00
180 changed files with 2339 additions and 2526 deletions

View File

@@ -148,25 +148,24 @@ void BPY_update_modules( void )
/*****************************************************************************
* Description: This function creates a new Python dictionary object.
* note: dict is owned by sys.modules["__main__"] module, reference is borrowed
* note: important we use the dict from __main__, this is what python expects
for 'pickle' to work as well as strings like this...
>> foo = 10
>> print(__import__("__main__").foo)
*****************************************************************************/
static PyObject *CreateGlobalDictionary( bContext *C, const char *filename )
static PyObject *CreateGlobalDictionary(bContext *C, const char *filename)
{
PyObject *item;
PyObject *dict = PyDict_New( );
PyDict_SetItemString( dict, "__builtins__", PyEval_GetBuiltins( ) );
PyInterpreterState *interp= PyThreadState_GET()->interp;
PyObject *mod_main= PyModule_New("__main__");
PyDict_SetItemString(interp->modules, "__main__", mod_main);
Py_DECREF(mod_main); /* sys.modules owns now */
item = PyUnicode_FromString( "__main__" );
PyDict_SetItemString( dict, "__name__", item );
Py_DECREF(item);
/* __file__ only for nice UI'ness */
if(filename) {
PyObject *item = PyUnicode_FromString( filename );
PyDict_SetItemString( dict, "__file__", item );
Py_DECREF(item);
}
PyModule_AddObject(mod_main, "__builtins__", interp->builtins);
PyModule_AddStringConstant(mod_main, "__name__", "__main__");
PyModule_AddStringConstant(mod_main, "__file__", filename); /* __file__ only for nice UI'ness */
return dict;
return PyModule_GetDict(mod_main);
}
/* must be called before Py_Initialize */
@@ -229,9 +228,12 @@ void BPY_start_python( int argc, char **argv )
{
PyThreadState *py_tstate = NULL;
BPY_start_python_path(); /* allow to use our own included python */
/* not essential but nice to set our name */
static wchar_t bprogname_wchar[FILE_MAXDIR+FILE_MAXFILE]; /* python holds a reference */
utf8towchar(bprogname_wchar, bprogname);
Py_SetProgramName(bprogname_wchar);
// Py_SetProgramName(); // extern char bprogname[FILE_MAXDIR+FILE_MAXFILE];
BPY_start_python_path(); /* allow to use our own included python */
Py_Initialize( );
@@ -389,7 +391,7 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
Py_DECREF( py_result );
}
Py_DECREF(py_dict);
PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None);
bpy_context_clear(C, &gilstate);
@@ -527,7 +529,7 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
Py_XDECREF(module);
Py_DECREF(py_dict);
PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None);
PyGILState_Release(gilstate);
return 1;
@@ -538,7 +540,7 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
int BPY_eval_button(bContext *C, const char *expr, double *value)
{
PyGILState_STATE gilstate;
PyObject *dict, *mod, *retval;
PyObject *py_dict, *mod, *retval;
int error_ret = 0;
if (!value || !expr) return -1;
@@ -550,11 +552,11 @@ int BPY_eval_button(bContext *C, const char *expr, double *value)
bpy_context_set(C, &gilstate);
dict= CreateGlobalDictionary(C, NULL);
py_dict= CreateGlobalDictionary(C, "<blender button>");
mod = PyImport_ImportModule("math");
if (mod) {
PyDict_Merge(dict, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
PyDict_Merge(py_dict, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
Py_DECREF(mod);
}
else { /* highly unlikely but possibly */
@@ -562,7 +564,7 @@ int BPY_eval_button(bContext *C, const char *expr, double *value)
PyErr_Clear();
}
retval = PyRun_String(expr, Py_eval_input, dict, dict);
retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
if (retval == NULL) {
error_ret= -1;
@@ -599,8 +601,9 @@ int BPY_eval_button(bContext *C, const char *expr, double *value)
if(error_ret) {
BPy_errors_to_report(CTX_wm_reports(C));
}
PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None);
Py_DECREF(dict);
bpy_context_clear(C, &gilstate);
return error_ret;
@@ -609,7 +612,7 @@ int BPY_eval_button(bContext *C, const char *expr, double *value)
int BPY_eval_string(bContext *C, const char *expr)
{
PyGILState_STATE gilstate;
PyObject *dict, *retval;
PyObject *py_dict, *retval;
int error_ret = 0;
if (!expr) return -1;
@@ -620,9 +623,9 @@ int BPY_eval_string(bContext *C, const char *expr)
bpy_context_set(C, &gilstate);
dict= CreateGlobalDictionary(C, NULL);
py_dict= CreateGlobalDictionary(C, "<blender string>");
retval = PyRun_String(expr, Py_eval_input, dict, dict);
retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
if (retval == NULL) {
error_ret= -1;
@@ -633,9 +636,10 @@ int BPY_eval_string(bContext *C, const char *expr)
Py_DECREF(retval);
}
Py_DECREF(dict);
PyDict_SetItemString(PyThreadState_GET()->interp->modules, "__main__", Py_None);
bpy_context_clear(C, &gilstate);
return error_ret;
}

View File

@@ -3086,37 +3086,47 @@ static struct PyMethodDef pyrna_prop_collection_methods[] = {
* todo - also accept useful args */
static PyObject * pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
BPy_StructRNA *base = NULL;
BPy_StructRNA *base;
if (!PyArg_ParseTuple(args, "O!:bpy_struct.__new__", &pyrna_struct_Type, &base))
return NULL;
if (type == &pyrna_struct_Type) {
return pyrna_struct_CreatePyObject(&base->ptr);
} else {
if (type == Py_TYPE(base)) {
Py_INCREF(base);
return (PyObject *)base;
} else if (PyType_IsSubtype(type, &pyrna_struct_Type)) {
BPy_StructRNA *ret = (BPy_StructRNA *) type->tp_alloc(type, 0);
ret->ptr = base->ptr;
return (PyObject *)ret;
}
else {
PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): type '%.200s' is not a subtype of bpy_struct.", type->tp_name);
return NULL;
}
}
/* only needed for subtyping, so a new class gets a valid BPy_StructRNA
* todo - also accept useful args */
static PyObject * pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
BPy_PropertyRNA *base = NULL;
BPy_PropertyRNA *base;
if (!PyArg_ParseTuple(args, "O!:Base BPy_PropertyRNA", &pyrna_prop_Type, &base))
if (!PyArg_ParseTuple(args, "O!:bpy_prop.__new__", &pyrna_prop_Type, &base))
return NULL;
if (ELEM3(type, &pyrna_prop_Type, &pyrna_prop_array_Type, &pyrna_prop_collection_Type)) {
return pyrna_prop_CreatePyObject(&base->ptr, base->prop);
} else {
if (type == Py_TYPE(base)) {
Py_INCREF(base);
return (PyObject *)base;
} else if (PyType_IsSubtype(type, &pyrna_prop_Type)) {
BPy_PropertyRNA *ret = (BPy_PropertyRNA *) type->tp_alloc(type, 0);
ret->ptr = base->ptr;
ret->prop = base->prop;
return (PyObject *)ret;
}
else {
PyErr_Format(PyExc_TypeError, "bpy_prop.__new__(type): type '%.200s' is not a subtype of bpy_prop.", type->tp_name);
return NULL;
}
}
PyObject *pyrna_param_to_py(PointerRNA *ptr, ParameterList *parms, PropertyRNA *prop, void *data)
@@ -4570,10 +4580,13 @@ static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *par
else {
args = PyTuple_New(1);
PyTuple_SET_ITEM(args, 0, py_srna);
py_class_instance = PyObject_Call(py_class, args, NULL);
py_class_instance= PyObject_Call(py_class, args, NULL);
Py_DECREF(args);
if(py_class_instance_store) {
if(py_class_instance == NULL) {
err= -1; /* so the error is not overridden below */
}
else if(py_class_instance_store) {
*py_class_instance_store = py_class_instance;
Py_INCREF(py_class_instance);
}
@@ -4626,8 +4639,11 @@ static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *par
}
}
else {
PyErr_Format(PyExc_RuntimeError, "could not create instance of %.200s to call callback function %.200s.", RNA_struct_identifier(ptr->type), RNA_function_identifier(func));
err= -1;
/* the error may be alredy set if the class instance couldnt be created */
if(err != -1) {
PyErr_Format(PyExc_RuntimeError, "could not create instance of %.200s to call callback function %.200s.", RNA_struct_identifier(ptr->type), RNA_function_identifier(func));
err= -1;
}
}
if (ret == NULL) { /* covers py_class_instance failing too */
@@ -4787,7 +4803,7 @@ static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
reg= RNA_struct_register(srna);
if(!reg) {
PyErr_SetString(PyExc_ValueError, "bpy.types.register(...): expected a Type subclassed from a registerable rna type (no register supported).");
PyErr_Format(PyExc_ValueError, "bpy.types.register(...): expected a subclass of a registerable rna type (%.200s does not support registration).", RNA_struct_identifier(srna));
return NULL;
}