Merged changes in the trunk up to revision 26856.
This commit is contained in:
136
source/blender/python/intern/bpy.c
Normal file
136
source/blender/python/intern/bpy.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* $Id:
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* This file defines the '_bpy' module which is used by python's 'bpy' package.
|
||||
* a script writer should never directly access this module */
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "bpy_rna.h"
|
||||
#include "bpy_app.h"
|
||||
#include "bpy_props.h"
|
||||
#include "bpy_operator.h"
|
||||
|
||||
#include "BLI_path_util.h"
|
||||
|
||||
/* external util modules */
|
||||
#include "../generic/Mathutils.h"
|
||||
#include "../generic/Geometry.h"
|
||||
#include "../generic/BGL.h"
|
||||
#include "../generic/IDProp.h"
|
||||
|
||||
#include "BPy_Freestyle.h"
|
||||
|
||||
/* todo, make nice syntax for sphinx */
|
||||
static char bpy_home_paths_doc[] = "home_paths(subfolder), return 3 paths to blender home directories (system, local, user), strings will be empty when not found.";
|
||||
|
||||
PyObject *bpy_home_paths(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *ret= PyTuple_New(3);
|
||||
char *path;
|
||||
char *subfolder= "";
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|s:blender_homes", &subfolder))
|
||||
return NULL;
|
||||
|
||||
path= BLI_gethome_folder(subfolder, BLI_GETHOME_SYSTEM);
|
||||
PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(path?path:""));
|
||||
|
||||
path= BLI_gethome_folder(subfolder, BLI_GETHOME_LOCAL);
|
||||
PyTuple_SET_ITEM(ret, 1, PyUnicode_FromString(path?path:""));
|
||||
|
||||
path= BLI_gethome_folder(subfolder, BLI_GETHOME_USER);
|
||||
PyTuple_SET_ITEM(ret, 2, PyUnicode_FromString(path?path:""));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyMethodDef meth_bpy_home_paths[] = {{ "home_paths", (PyCFunction)bpy_home_paths, METH_VARARGS, bpy_home_paths_doc}};
|
||||
|
||||
static void bpy_import_test(char *modname)
|
||||
{
|
||||
PyObject *mod= PyImport_ImportModuleLevel(modname, NULL, NULL, NULL, 0);
|
||||
if(mod) {
|
||||
Py_DECREF(mod);
|
||||
}
|
||||
else {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Description: Creates the bpy module and adds it to sys.modules for importing
|
||||
*****************************************************************************/
|
||||
void BPy_init_modules( void )
|
||||
{
|
||||
extern BPy_StructRNA *bpy_context_module;
|
||||
PyObject *mod;
|
||||
|
||||
/* Needs to be first since this dir is needed for future modules */
|
||||
char *modpath= BLI_gethome_folder("scripts/modules", BLI_GETHOME_ALL);
|
||||
if(modpath) {
|
||||
PyObject *sys_path= PySys_GetObject("path"); /* borrow */
|
||||
PyObject *py_modpath= PyUnicode_FromString(modpath);
|
||||
PyList_Insert(sys_path, 0, py_modpath); /* add first */
|
||||
Py_DECREF(py_modpath);
|
||||
}
|
||||
|
||||
/* stand alone utility modules not related to blender directly */
|
||||
Geometry_Init();
|
||||
Mathutils_Init();
|
||||
BGL_Init();
|
||||
IDProp_Init_Types();
|
||||
Freestyle_Init();
|
||||
|
||||
|
||||
mod = PyModule_New("_bpy");
|
||||
|
||||
/* add the module so we can import it */
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), "_bpy", mod);
|
||||
Py_DECREF(mod);
|
||||
|
||||
/* run first, initializes rna types */
|
||||
BPY_rna_init();
|
||||
|
||||
PyModule_AddObject( mod, "types", BPY_rna_types() ); /* needs to be first so bpy_types can run */
|
||||
bpy_import_test("bpy_types");
|
||||
PyModule_AddObject( mod, "data", BPY_rna_module() ); /* imports bpy_types by running this */
|
||||
bpy_import_test("bpy_types");
|
||||
PyModule_AddObject( mod, "props", BPY_rna_props() );
|
||||
PyModule_AddObject( mod, "ops", BPY_operator_module() ); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
|
||||
PyModule_AddObject( mod, "app", BPY_app_struct() );
|
||||
|
||||
/* bpy context */
|
||||
bpy_context_module= ( BPy_StructRNA * ) PyObject_NEW( BPy_StructRNA, &pyrna_struct_Type );
|
||||
RNA_pointer_create(NULL, &RNA_Context, NULL, &bpy_context_module->ptr);
|
||||
bpy_context_module->freeptr= 0;
|
||||
PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module);
|
||||
|
||||
/* utility func's that have nowhere else to go */
|
||||
PyModule_AddObject(mod, meth_bpy_home_paths->ml_name, (PyObject *)PyCFunction_New(meth_bpy_home_paths, NULL));
|
||||
|
||||
/* add our own modules dir, this is a python package */
|
||||
bpy_import_test("bpy");
|
||||
}
|
||||
25
source/blender/python/intern/bpy.h
Normal file
25
source/blender/python/intern/bpy.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* $Id:
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK ***** */
|
||||
|
||||
void BPy_init_modules( void );
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
@@ -49,16 +49,16 @@ static PyTypeObject BlenderAppType;
|
||||
|
||||
static PyStructSequence_Field app_info_fields[] = {
|
||||
{"version", "The Blender version as a tuple of 3 numbers. eg. (2, 50, 11)"},
|
||||
{"version_string", "The Blender version formatted as a string."},
|
||||
{"version_string", "The Blender version formatted as a string"},
|
||||
{"home", "The blender home directory, normally matching $HOME"},
|
||||
{"binary_path", "The location of blenders executable, useful for utilities that spawn new instances."},
|
||||
{"debug", "Boolean, set when blender is running in debug mode (started with -d)."},
|
||||
{"binary_path", "The location of blenders executable, useful for utilities that spawn new instances"},
|
||||
{"debug", "Boolean, set when blender is running in debug mode (started with -d)"},
|
||||
|
||||
/* buildinfo */
|
||||
{"build_date", "The date this blender instance was built.."},
|
||||
{"build_time", "The time this blender instance was built."},
|
||||
{"build_revision", "The subversion revision this blender instance was built with."},
|
||||
{"build_platform", "The platform this blender instance was built for."},
|
||||
{"build_date", "The date this blender instance was built"},
|
||||
{"build_time", "The time this blender instance was built"},
|
||||
{"build_revision", "The subversion revision this blender instance was built with"},
|
||||
{"build_platform", "The platform this blender instance was built for"},
|
||||
{"build_type", "The type of build (Release, Debug)"},
|
||||
{0}
|
||||
};
|
||||
@@ -70,9 +70,24 @@ static PyStructSequence_Desc app_info_desc = {
|
||||
10
|
||||
};
|
||||
|
||||
static char *strip_quotes(char *buf, const char *input)
|
||||
{
|
||||
int i;
|
||||
strcpy(buf, input);
|
||||
if(buf[0]=='\0') return buf;
|
||||
while(buf[1] && (buf[0]=='"' || buf[0]=='\'')) buf++;
|
||||
if(buf[0]=='\0') return buf;
|
||||
i= strlen(buf) - 1;
|
||||
while(i>=0 && (buf[i]=='"' || buf[i]=='\'')) i--;
|
||||
buf[i+1]= '\0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static PyObject *make_app_info(void)
|
||||
{
|
||||
extern char bprogname[]; /* argv[0] from creator.c */
|
||||
char buf[256];
|
||||
|
||||
PyObject *app_info;
|
||||
int pos = 0;
|
||||
@@ -84,8 +99,8 @@ static PyObject *make_app_info(void)
|
||||
|
||||
#define SetIntItem(flag) \
|
||||
PyStructSequence_SET_ITEM(app_info, pos++, PyLong_FromLong(flag))
|
||||
#define SetStrItem(flag) \
|
||||
PyStructSequence_SET_ITEM(app_info, pos++, PyUnicode_FromString(flag))
|
||||
#define SetStrItem(str) \
|
||||
PyStructSequence_SET_ITEM(app_info, pos++, PyUnicode_FromString(str))
|
||||
#define SetObjItem(obj) \
|
||||
PyStructSequence_SET_ITEM(app_info, pos++, obj)
|
||||
|
||||
@@ -96,11 +111,11 @@ static PyObject *make_app_info(void)
|
||||
SetObjItem(PyBool_FromLong(G.f & G_DEBUG));
|
||||
|
||||
/* build info */
|
||||
SetStrItem(build_date);
|
||||
SetStrItem(build_time);
|
||||
SetStrItem(build_rev);
|
||||
SetStrItem(build_platform);
|
||||
SetStrItem(build_type);
|
||||
SetStrItem(strip_quotes(buf, build_date));
|
||||
SetStrItem(strip_quotes(buf, build_time));
|
||||
SetStrItem(strip_quotes(buf, build_rev));
|
||||
SetStrItem(strip_quotes(buf, build_platform));
|
||||
SetStrItem(strip_quotes(buf, build_type));
|
||||
|
||||
#undef SetIntItem
|
||||
#undef SetStrItem
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Arystanbek Dyussenov
|
||||
*
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Willian P. Germano, Campbell Barton
|
||||
*
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Michel Selten, Willian P. Germano, Stephen Swaney,
|
||||
* Chris Keith, Chris Want, Ken Hughes, Campbell Barton
|
||||
@@ -38,10 +38,8 @@
|
||||
#include "compile.h" /* for the PyCodeObject */
|
||||
#include "eval.h" /* for PyEval_EvalCode */
|
||||
|
||||
#include "bpy_app.h"
|
||||
#include "bpy.h"
|
||||
#include "bpy_rna.h"
|
||||
#include "bpy_props.h"
|
||||
#include "bpy_operator.h"
|
||||
#include "bpy_util.h"
|
||||
|
||||
#ifndef WIN32
|
||||
@@ -55,10 +53,10 @@
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_path_util.h"
|
||||
#include "BLI_storage.h"
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_path_util.h"
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_text.h"
|
||||
@@ -67,21 +65,13 @@
|
||||
|
||||
#include "BPY_extern.h"
|
||||
|
||||
#include "BPy_Freestyle.h"
|
||||
|
||||
#include "../generic/bpy_internal_import.h" // our own imports
|
||||
/* external util modules */
|
||||
|
||||
#include "../generic/Mathutils.h"
|
||||
#include "../generic/Geometry.h"
|
||||
#include "../generic/BGL.h"
|
||||
#include "../generic/IDProp.h"
|
||||
|
||||
/* for internal use, when starting and ending python scripts */
|
||||
|
||||
/* incase a python script triggers another python call, stop bpy_context_clear from invalidating */
|
||||
static int py_call_level= 0;
|
||||
|
||||
BPy_StructRNA *bpy_context_module= NULL; /* for fast access */
|
||||
|
||||
// only for tests
|
||||
#define TIME_PY_RUN
|
||||
@@ -150,18 +140,6 @@ void bpy_context_clear(bContext *C, PyGILState_STATE *gilstate)
|
||||
}
|
||||
}
|
||||
|
||||
static void bpy_import_test(char *modname)
|
||||
{
|
||||
PyObject *mod= PyImport_ImportModuleLevel(modname, NULL, NULL, NULL, 0);
|
||||
if(mod) {
|
||||
Py_DECREF(mod);
|
||||
}
|
||||
else {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void BPY_free_compiled_text( struct Text *text )
|
||||
{
|
||||
if( text->compiled ) {
|
||||
@@ -170,63 +148,6 @@ void BPY_free_compiled_text( struct Text *text )
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Description: Creates the bpy module and adds it to sys.modules for importing
|
||||
*****************************************************************************/
|
||||
static BPy_StructRNA *bpy_context_module= NULL; /* for fast access */
|
||||
static void bpy_init_modules( void )
|
||||
{
|
||||
PyObject *mod;
|
||||
|
||||
/* Needs to be first since this dir is needed for future modules */
|
||||
char *modpath= BLI_gethome_folder("scripts/modules", BLI_GETHOME_ALL);
|
||||
if(modpath) {
|
||||
PyObject *sys_path= PySys_GetObject("path"); /* borrow */
|
||||
PyObject *py_modpath= PyUnicode_FromString(modpath);
|
||||
PyList_Insert(sys_path, 0, py_modpath); /* add first */
|
||||
Py_DECREF(py_modpath);
|
||||
}
|
||||
|
||||
/* stand alone utility modules not related to blender directly */
|
||||
Geometry_Init();
|
||||
Mathutils_Init();
|
||||
BGL_Init();
|
||||
IDProp_Init_Types();
|
||||
Freestyle_Init();
|
||||
|
||||
|
||||
mod = PyModule_New("_bpy");
|
||||
|
||||
/* add the module so we can import it */
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), "_bpy", mod);
|
||||
Py_DECREF(mod);
|
||||
|
||||
/* run first, initializes rna types */
|
||||
BPY_rna_init();
|
||||
|
||||
PyModule_AddObject( mod, "types", BPY_rna_types() ); /* needs to be first so bpy_types can run */
|
||||
bpy_import_test("bpy_types");
|
||||
PyModule_AddObject( mod, "data", BPY_rna_module() ); /* imports bpy_types by running this */
|
||||
bpy_import_test("bpy_types");
|
||||
/* PyModule_AddObject( mod, "doc", BPY_rna_doc() ); */
|
||||
PyModule_AddObject( mod, "props", BPY_rna_props() );
|
||||
PyModule_AddObject( mod, "ops", BPY_operator_module() ); /* ops is now a python module that does the conversion from SOME_OT_foo -> some.foo */
|
||||
PyModule_AddObject( mod, "app", BPY_app_struct() );
|
||||
|
||||
/* bpy context */
|
||||
{
|
||||
bpy_context_module= ( BPy_StructRNA * ) PyObject_NEW( BPy_StructRNA, &pyrna_struct_Type );
|
||||
|
||||
RNA_pointer_create(NULL, &RNA_Context, NULL, &bpy_context_module->ptr);
|
||||
bpy_context_module->freeptr= 0;
|
||||
|
||||
PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module);
|
||||
}
|
||||
|
||||
/* add our own modules dir, this is a python package */
|
||||
bpy_import_test("bpy");
|
||||
}
|
||||
|
||||
void BPY_update_modules( void )
|
||||
{
|
||||
#if 0 // slow, this runs all the time poll, draw etc 100's of time a sec.
|
||||
@@ -360,7 +281,7 @@ void BPY_start_python( int argc, char **argv )
|
||||
|
||||
|
||||
/* bpy.* and lets us import it */
|
||||
bpy_init_modules();
|
||||
BPy_init_modules();
|
||||
|
||||
{ /* our own import and reload functions */
|
||||
PyObject *item;
|
||||
@@ -785,3 +706,4 @@ int BPY_context_get(bContext *C, const char *member, bContextDataResult *result)
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
@@ -48,8 +48,9 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
|
||||
int error_val = 0;
|
||||
PointerRNA ptr;
|
||||
int operator_ret= OPERATOR_CANCELLED;
|
||||
|
||||
|
||||
char *opname;
|
||||
char *context_str= NULL;
|
||||
PyObject *kw= NULL; /* optional args */
|
||||
PyObject *context_dict= NULL; /* optional args */
|
||||
PyObject *context_dict_back;
|
||||
@@ -60,7 +61,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
|
||||
// XXX Todo, work out a better solution for passing on context, could make a tuple from self and pack the name and Context into it...
|
||||
bContext *C = BPy_GetContext();
|
||||
|
||||
if (!PyArg_ParseTuple(args, "sO|O!i:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context))
|
||||
if (!PyArg_ParseTuple(args, "sO|O!s:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context_str))
|
||||
return NULL;
|
||||
|
||||
ot= WM_operatortype_exists(opname);
|
||||
@@ -70,6 +71,15 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(context_str) {
|
||||
if(RNA_enum_value_from_id(operator_context_items, context_str, &context)==0) {
|
||||
char *enum_str= BPy_enum_as_string(operator_context_items);
|
||||
PyErr_Format(PyExc_TypeError, "Calling operator \"bpy.ops.%s\" error, expected a string enum in (%.200s)", opname, enum_str);
|
||||
MEM_freeN(enum_str);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(!PyDict_Check(context_dict))
|
||||
context_dict= NULL;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
@@ -81,7 +81,7 @@ EnumPropertyItem property_subtype_array_items[] = {
|
||||
static PyObject *bpy_prop_deferred_return(void *func, PyObject *kw)
|
||||
{
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr(func, NULL));
|
||||
PyTuple_SET_ITEM(ret, 0, PyCapsule_New(func, NULL, NULL));
|
||||
PyTuple_SET_ITEM(ret, 1, kw);
|
||||
Py_INCREF(kw);
|
||||
return ret;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
@@ -389,7 +389,7 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
|
||||
|
||||
RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
|
||||
if(item) {
|
||||
result= (char*)BPy_enum_as_string(item);
|
||||
result= BPy_enum_as_string(item);
|
||||
}
|
||||
else {
|
||||
result= "";
|
||||
@@ -401,6 +401,7 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *prop, int *val, const char *error_prefix)
|
||||
{
|
||||
char *param= _PyUnicode_AsString(item);
|
||||
@@ -698,7 +699,7 @@ static PyObject *pyrna_func_to_py(BPy_DummyPointerRNA *pyrna, FunctionRNA *func)
|
||||
PyTuple_SET_ITEM(self, 0, (PyObject *)pyrna);
|
||||
Py_INCREF(pyrna);
|
||||
|
||||
PyTuple_SET_ITEM(self, 1, PyCObject_FromVoidPtr((void *)func, NULL));
|
||||
PyTuple_SET_ITEM(self, 1, PyCapsule_New((void *)func, NULL, NULL));
|
||||
|
||||
ret= PyCFunction_New(&func_meth, self);
|
||||
Py_DECREF(self);
|
||||
@@ -2599,7 +2600,7 @@ PyObject *pyrna_prop_iter(BPy_PropertyRNA *self)
|
||||
{
|
||||
/* Try get values from a collection */
|
||||
PyObject *ret;
|
||||
PyObject *iter;
|
||||
PyObject *iter= NULL;
|
||||
|
||||
if(RNA_property_array_check(&self->ptr, self->prop)) {
|
||||
int len= pyrna_prop_array_length(self);
|
||||
@@ -2614,9 +2615,13 @@ PyObject *pyrna_prop_iter(BPy_PropertyRNA *self)
|
||||
}
|
||||
|
||||
|
||||
/* we know this is a list so no need to PyIter_Check */
|
||||
iter = PyObject_GetIter(ret);
|
||||
Py_DECREF(ret);
|
||||
/* we know this is a list so no need to PyIter_Check
|
||||
* otherwise it could be NULL (unlikely) if conversion failed */
|
||||
if(ret) {
|
||||
iter = PyObject_GetIter(ret);
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
@@ -2844,7 +2849,7 @@ static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
/* Note, both BPy_StructRNA and BPy_PropertyRNA can be used here */
|
||||
PointerRNA *self_ptr= &(((BPy_DummyPointerRNA *)PyTuple_GET_ITEM(self, 0))->ptr);
|
||||
FunctionRNA *self_func= PyCObject_AsVoidPtr(PyTuple_GET_ITEM(self, 1));
|
||||
FunctionRNA *self_func= PyCapsule_GetPointer(PyTuple_GET_ITEM(self, 1), NULL);
|
||||
|
||||
PointerRNA funcptr;
|
||||
ParameterList parms;
|
||||
@@ -3273,7 +3278,7 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna)
|
||||
RNA_pointer_create(NULL, &RNA_Struct, srna, &ptr);
|
||||
item = pyrna_struct_CreatePyObject(&ptr);
|
||||
|
||||
//item = PyCObject_FromVoidPtr(srna, NULL);
|
||||
//item = PyCapsule_New(srna, NULL, NULL);
|
||||
PyDict_SetItemString(((PyTypeObject *)newclass)->tp_dict, "bl_rna", item);
|
||||
Py_DECREF(item);
|
||||
/* done with rna instance */
|
||||
@@ -3689,8 +3694,8 @@ StructRNA *srna_from_self(PyObject *self)
|
||||
if(self==NULL) {
|
||||
return NULL;
|
||||
}
|
||||
else if (PyCObject_Check(self)) {
|
||||
return PyCObject_AsVoidPtr(self);
|
||||
else if (PyCapsule_CheckExact(self)) {
|
||||
return PyCapsule_GetPointer(self, NULL);
|
||||
}
|
||||
else if (PyType_Check(self)==0) {
|
||||
return NULL;
|
||||
@@ -3710,15 +3715,15 @@ static int deferred_register_prop(StructRNA *srna, PyObject *item, PyObject *key
|
||||
PyObject *py_func_ptr, *py_kw, *py_srna_cobject, *py_ret;
|
||||
PyObject *(*pyfunc)(PyObject *, PyObject *, PyObject *);
|
||||
|
||||
if(PyArg_ParseTuple(item, "O!O!", &PyCObject_Type, &py_func_ptr, &PyDict_Type, &py_kw)) {
|
||||
if(PyArg_ParseTuple(item, "O!O!", &PyCapsule_Type, &py_func_ptr, &PyDict_Type, &py_kw)) {
|
||||
|
||||
if(*_PyUnicode_AsString(key)=='_') {
|
||||
PyErr_Format(PyExc_ValueError, "StructRNA \"%.200s\" registration error: %.200s could not register because the property starts with an '_'\n", RNA_struct_identifier(srna), _PyUnicode_AsString(key));
|
||||
Py_DECREF(dummy_args);
|
||||
return -1;
|
||||
}
|
||||
pyfunc = PyCObject_AsVoidPtr(py_func_ptr);
|
||||
py_srna_cobject = PyCObject_FromVoidPtr(srna, NULL);
|
||||
pyfunc = PyCapsule_GetPointer(py_func_ptr, NULL);
|
||||
py_srna_cobject = PyCapsule_New(srna, NULL, NULL);
|
||||
|
||||
/* not 100% nice :/, modifies the dict passed, should be ok */
|
||||
PyDict_SetItemString(py_kw, "attr", key);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Campbell Barton
|
||||
*
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2007 Blender Foundation.
|
||||
* All rights reserved.
|
||||
|
||||
Reference in New Issue
Block a user