* Merged changes in the trunk up to revision 31789.

* Made a local fix for a compilation error with VC++ 2008 and
CMake, reported to the bf-committers mailing list:
http://lists.blender.org/pipermail/bf-committers/2010-September/028643.html
This commit is contained in:
Tamito Kajiyama
2010-09-06 23:26:36 +00:00
279 changed files with 5648 additions and 5317 deletions

View File

@@ -12,10 +12,10 @@ incs += ' #intern/audaspace/intern ' + env['BF_PYTHON_INC']
defs = []
if env['BF_BUILDINFO']:
defs.append('BUILD_DATE')
defs.append('BUILD_DATE')
if env['OURPLATFORM'] in ('win32-mingw', 'win32-vc','win64-vc') and env['BF_DEBUG']:
defs.append('_DEBUG')
defs.append('_DEBUG')
env.BlenderLib( libname = 'bf_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype = ['core','player'], priority = [361,160])

View File

@@ -186,4 +186,4 @@ def BezierInterp(vec_knot_1, vec_handle_1, vec_handle_2, vec_knot_2, resolution)
@note: any vector size is supported, the largest dimension from the input will be used for all returned vectors/
@rtype: list
@return: a list of vectors the size of resolution including the start and end points (vec_knot_1 and vec_knot_2)
"""
"""

View File

@@ -129,4 +129,4 @@ class IDArray:
def __len__():
pass

View File

@@ -1,3 +1,3 @@
import mathutils
# todo
# todo

View File

@@ -1,3 +1,3 @@
import mathutils
# todo
# todo

View File

@@ -1,3 +1,3 @@
import mathutils
# todo
# todo

View File

@@ -15,4 +15,4 @@ quat2 = mat3.to_quat()
angle = quat1.difference(quat2)
print(angle)
print(angle)

View File

@@ -314,6 +314,9 @@ def rna2sphinx(BASEPATH):
if bpy.app.build_revision != "Unknown":
version_string = version_string + " r" + bpy.app.build_revision
# for use with files
version_string_fp = "_".join(str(v) for v in bpy.app.version)
fw("project = 'Blender'\n")
# fw("master_doc = 'index'\n")
fw("copyright = u'Blender Foundation'\n")
@@ -343,7 +346,7 @@ def rna2sphinx(BASEPATH):
fw("\n")
fw("An introduction to Blender and Python can be found at <http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro>\n")
fw("\n")
fw("`A PDF version of this document is also available <blender_python_reference_250.pdf>`__\n")
fw("`A PDF version of this document is also available <blender_python_reference_%s.pdf>`__\n" % version_string_fp)
fw("\n")
fw(".. warning:: The Python API in Blender is **UNSTABLE**, It should only be used for testing, any script written now may break in future releases.\n")
fw(" \n")
@@ -448,7 +451,7 @@ def rna2sphinx(BASEPATH):
fw("\n")
fw(" Access to blenders internal data\n")
fw("\n")
fw(" :type: :class:`bpy.types.Main`\n")
fw(" :type: :class:`bpy.types.BlendData`\n")
file.close()
EXAMPLE_SET_USED.add("bpy.data")
@@ -648,20 +651,24 @@ def rna2sphinx(BASEPATH):
if _BPY_STRUCT_FAKE:
for key, descr in descr_items:
if type(descr) == GetSetDescriptorType:
lines.append("* :class:`%s.%s`\n" % (_BPY_STRUCT_FAKE, key))
lines.append(" * :class:`%s.%s`\n" % (_BPY_STRUCT_FAKE, key))
for base in bases:
for prop in base.properties:
lines.append("* :class:`%s.%s`\n" % (base.identifier, prop.identifier))
lines.append(" * :class:`%s.%s`\n" % (base.identifier, prop.identifier))
for identifier, py_prop in base.get_py_properties():
lines.append("* :class:`%s.%s`\n" % (base.identifier, identifier))
lines.append(" * :class:`%s.%s`\n" % (base.identifier, identifier))
for identifier, py_prop in base.get_py_properties():
lines.append("* :class:`%s.%s`\n" % (base.identifier, identifier))
lines.append(" * :class:`%s.%s`\n" % (base.identifier, identifier))
if lines:
fw(".. rubric:: Inherited Properties\n\n")
fw(".. hlist::\n")
fw(" :columns: 2\n\n")
for line in lines:
fw(line)
fw("\n")
@@ -673,16 +680,20 @@ def rna2sphinx(BASEPATH):
if _BPY_STRUCT_FAKE:
for key, descr in descr_items:
if type(descr) == MethodDescriptorType:
lines.append("* :class:`%s.%s`\n" % (_BPY_STRUCT_FAKE, key))
lines.append(" * :class:`%s.%s`\n" % (_BPY_STRUCT_FAKE, key))
for base in bases:
for func in base.functions:
lines.append("* :class:`%s.%s`\n" % (base.identifier, func.identifier))
lines.append(" * :class:`%s.%s`\n" % (base.identifier, func.identifier))
for identifier, py_func in base.get_py_functions():
lines.append("* :class:`%s.%s`\n" % (base.identifier, identifier))
lines.append(" * :class:`%s.%s`\n" % (base.identifier, identifier))
if lines:
fw(".. rubric:: Inherited Functions\n\n")
fw(".. hlist::\n")
fw(" :columns: 2\n\n")
for line in lines:
fw(line)
fw("\n")
@@ -694,11 +705,14 @@ def rna2sphinx(BASEPATH):
# use this otherwise it gets in the index for a normal heading.
fw(".. rubric:: References\n\n")
fw(".. hlist::\n")
fw(" :columns: 2\n\n")
for ref in struct.references:
ref_split = ref.split(".")
if len(ref_split) > 2:
ref = ref_split[-2] + "." + ref_split[-1]
fw("* :class:`%s`\n" % ref)
fw(" * :class:`%s`\n" % ref)
fw("\n")

View File

@@ -5,7 +5,12 @@
BLENDER="./blender.bin"
SSH_HOST="ideasman42@emo.blender.org"
SSH_UPLOAD="/data/www/vhosts/www.blender.org/documentation/250PythonDoc"
SSH_UPLOAD="/data/www/vhosts/www.blender.org/documentation" # blender_python_api_VERSION, added after
# sed string from hell, 'Blender 2.53 (sub 1) Build' --> '2_53_1'
# "_".join(str(v) for v in bpy.app.version)
BLENDER_VERSION=`$BLENDER --version | cut -f2-4 -d" " | sed 's/(//g' | sed 's/)//g' | sed 's/ sub /./g' | sed 's/\./_/g'`
SSH_UPLOAD_FULL=$SSH_UPLOAD/"blender_python_api_"$BLENDER_VERSION
# dont delete existing docs, now partial updates are used for quick builds.
$BLENDER --background --python ./source/blender/python/doc/sphinx_doc_gen.py
@@ -13,12 +18,12 @@ $BLENDER --background --python ./source/blender/python/doc/sphinx_doc_gen.py
# html
sphinx-build source/blender/python/doc/sphinx-in source/blender/python/doc/sphinx-out
cp source/blender/python/doc/sphinx-out/contents.html source/blender/python/doc/sphinx-out/index.html
ssh ideasman42@emo.blender.org 'rm -rf '$SSH_UPLOAD'/*'
rsync --progress -avze "ssh -p 22" /b/source/blender/python/doc/sphinx-out/* $SSH_HOST:$SSH_UPLOAD/
ssh ideasman42@emo.blender.org 'rm -rf '$SSH_UPLOAD_FULL'/*'
rsync --progress -avze "ssh -p 22" /b/source/blender/python/doc/sphinx-out/* $SSH_HOST:$SSH_UPLOAD_FULL/
# pdf
sphinx-build -b latex source/blender/python/doc/sphinx-in source/blender/python/doc/sphinx-out
cd source/blender/python/doc/sphinx-out
make
cd ../../../../../
rsync --progress -avze "ssh -p 22" source/blender/python/doc/sphinx-out/contents.pdf $SSH_HOST:$SSH_UPLOAD/blender_python_reference_250.pdf
rsync --progress -avze "ssh -p 22" source/blender/python/doc/sphinx-out/contents.pdf $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.pdf

View File

@@ -27,6 +27,15 @@
#include "IDProp.h"
#include "MEM_guardedalloc.h"
#define USE_STRING_COERCE
#ifdef USE_STRING_COERCE
#include "py_capi_utils.h"
#endif
PyObject * PyC_UnicodeFromByte(const char *str);
const char * PuC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */
/*** Function to wrap ID properties ***/
PyObject *BPy_Wrap_IDProperty(ID *id, IDProperty *prop, IDProperty *parent);
@@ -46,7 +55,11 @@ PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop )
{
switch ( prop->type ) {
case IDP_STRING:
return PyUnicode_FromString( prop->data.pointer );
#ifdef USE_STRING_COERCE
return PyC_UnicodeFromByte(prop->data.pointer);
#else
return PyUnicode_FromString(prop->data.pointer);
#endif
case IDP_INT:
return PyLong_FromLong( (long)prop->data.val );
case IDP_FLOAT:
@@ -105,10 +118,25 @@ int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject *value)
PyErr_SetString(PyExc_TypeError, "expected a string!");
return -1;
}
#ifdef USE_STRING_COERCE
{
int alloc_len;
PyObject *value_coerce= NULL;
st= (char *)PuC_UnicodeAsByte(value, &value_coerce);
alloc_len= strlen(st) + 1;
st = _PyUnicode_AsString(value);
IDP_ResizeArray(prop, alloc_len);
memcpy(prop->data.pointer, st, alloc_len);
Py_XDECREF(value_coerce);
}
#else
st = _PyUnicode_AsString(value);
IDP_ResizeArray(prop, strlen(st)+1);
strcpy(prop->data.pointer, st);
#endif
return 0;
}
@@ -281,8 +309,15 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje
val.i = (int) PyLong_AsSsize_t(ob);
prop = IDP_New(IDP_INT, val, name);
} else if (PyUnicode_Check(ob)) {
#ifdef USE_STRING_COERCE
PyObject *value_coerce= NULL;
val.str = (char *)PuC_UnicodeAsByte(ob, &value_coerce);
prop = IDP_New(IDP_STRING, val, name);
Py_XDECREF(value_coerce);
#else
val.str = _PyUnicode_AsString(ob);
prop = IDP_New(IDP_STRING, val, name);
#endif
} else if (PySequence_Check(ob)) {
PyObject *item;
int i;
@@ -432,7 +467,11 @@ static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
{
switch (prop->type) {
case IDP_STRING:
#ifdef USE_STRING_COERCE
return PyC_UnicodeFromByte(prop->data.pointer);
#else
return PyUnicode_FromString(prop->data.pointer);
#endif
break;
case IDP_FLOAT:
return PyFloat_FromDouble(*((float*)&prop->data.val));

View File

@@ -35,6 +35,7 @@
#include "BKE_global.h" /* grr, only for G.sce */
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include <stddef.h>
static Main *bpy_import_main= NULL;
@@ -61,6 +62,12 @@ void bpy_import_main_set(struct Main *maggie)
void bpy_text_filename_get(char *fn, Text *text)
{
sprintf(fn, "%s/%s", text->id.lib ? text->id.lib->filepath : G.sce, text->id.name+2);
/* XXX, this is a bug in python's Py_CompileString()!
the string encoding should not be required to be utf-8
reported: http://bugs.python.org/msg115202
*/
BLI_utf8_invalid_strip(fn, strlen(fn));
}
PyObject *bpy_text_import( Text *text )

View File

@@ -250,7 +250,7 @@ static PyObject *Euler_Rotate(EulerObject * self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected angle (float) and axis (x,y,z)");
return NULL;
}
if(ELEM3(*axis, 'X', 'Y', 'Z') && axis[1]=='\0'){
if(!(ELEM3(*axis, 'X', 'Y', 'Z') && axis[1]=='\0')){
PyErr_SetString(PyExc_TypeError, "euler.rotate(): expected axis to be 'X', 'Y' or 'Z'");
return NULL;
}

View File

@@ -0,0 +1,271 @@
/**
* $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.
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "py_capi_utils.h"
/* for debugging */
void PyC_ObSpit(char *name, PyObject *var) {
fprintf(stderr, "<%s> : ", name);
if (var==NULL) {
fprintf(stderr, "<NIL>");
}
else {
PyObject_Print(var, stderr, 0);
fprintf(stderr, " ref:%d ", (int)var->ob_refcnt);
fprintf(stderr, " ptr:%p", (void *)var);
fprintf(stderr, " type:");
if(Py_TYPE(var))
fprintf(stderr, "%s", Py_TYPE(var)->tp_name);
else
fprintf(stderr, "<NIL>");
}
fprintf(stderr, "\n");
}
void PyC_LineSpit(void) {
const char *filename;
int lineno;
PyErr_Clear();
PyC_FileAndNum(&filename, &lineno);
fprintf(stderr, "%s:%d\n", filename, lineno);
}
void PyC_FileAndNum(const char **filename, int *lineno)
{
PyObject *getframe, *frame;
PyObject *f_lineno= NULL, *co_filename= NULL;
if (filename) *filename= NULL;
if (lineno) *lineno = -1;
getframe = PySys_GetObject("_getframe"); // borrowed
if (getframe==NULL) {
PyErr_Clear();
return;
}
frame = PyObject_CallObject(getframe, NULL);
if (frame==NULL) {
PyErr_Clear();
return;
}
/* when executing a script */
if (filename) {
co_filename= PyC_Object_GetAttrStringArgs(frame, 1, "f_code", "co_filename");
if (co_filename==NULL) {
PyErr_SetString(PyExc_SystemError, "Could not access sys._getframe().f_code.co_filename");
Py_DECREF(frame);
return;
}
*filename = _PyUnicode_AsString(co_filename);
Py_DECREF(co_filename);
}
/* when executing a module */
if(filename && *filename == NULL) {
/* try an alternative method to get the filename - module based
* references below are all borrowed (double checked) */
PyObject *mod_name= PyDict_GetItemString(PyEval_GetGlobals(), "__name__");
if(mod_name) {
PyObject *mod= PyDict_GetItem(PyImport_GetModuleDict(), mod_name);
if(mod) {
*filename= PyModule_GetFilename(mod);
}
/* unlikely, fallback */
if(*filename == NULL) {
*filename= _PyUnicode_AsString(mod_name);
}
}
}
if (lineno) {
f_lineno= PyObject_GetAttrString(frame, "f_lineno");
if (f_lineno==NULL) {
PyErr_SetString(PyExc_SystemError, "Could not access sys._getframe().f_lineno");
Py_DECREF(frame);
return;
}
*lineno = (int)PyLong_AsSsize_t(f_lineno);
Py_DECREF(f_lineno);
}
Py_DECREF(frame);
}
/* Would be nice if python had this built in */
PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...)
{
Py_ssize_t i;
PyObject *item= o;
char *attr;
va_list vargs;
va_start(vargs, n);
for (i=0; i<n; i++) {
attr = va_arg(vargs, char *);
item = PyObject_GetAttrString(item, attr);
if (item)
Py_DECREF(item);
else /* python will set the error value here */
break;
}
va_end(vargs);
Py_XINCREF(item); /* final value has is increfed, to match PyObject_GetAttrString */
return item;
}
/* returns the exception string as a new PyUnicode object, depends on external StringIO module */
PyObject *PyC_ExceptionBuffer(void)
{
PyObject *stdout_backup = PySys_GetObject("stdout"); /* borrowed */
PyObject *stderr_backup = PySys_GetObject("stderr"); /* borrowed */
PyObject *string_io = NULL;
PyObject *string_io_buf = NULL;
PyObject *string_io_mod= NULL;
PyObject *string_io_getvalue= NULL;
PyObject *error_type, *error_value, *error_traceback;
if (!PyErr_Occurred())
return NULL;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
PyErr_Clear();
/* import io
* string_io = io.StringIO()
*/
if(! (string_io_mod= PyImport_ImportModule("io")) ) {
goto error_cleanup;
} else if (! (string_io = PyObject_CallMethod(string_io_mod, "StringIO", NULL))) {
goto error_cleanup;
} else if (! (string_io_getvalue= PyObject_GetAttrString(string_io, "getvalue"))) {
goto error_cleanup;
}
Py_INCREF(stdout_backup); // since these were borrowed we dont want them freed when replaced.
Py_INCREF(stderr_backup);
PySys_SetObject("stdout", string_io); // both of these are free'd when restoring
PySys_SetObject("stderr", string_io);
PyErr_Restore(error_type, error_value, error_traceback);
PyErr_Print(); /* print the error */
PyErr_Clear();
string_io_buf = PyObject_CallObject(string_io_getvalue, NULL);
PySys_SetObject("stdout", stdout_backup);
PySys_SetObject("stderr", stderr_backup);
Py_DECREF(stdout_backup); /* now sys owns the ref again */
Py_DECREF(stderr_backup);
Py_DECREF(string_io_mod);
Py_DECREF(string_io_getvalue);
Py_DECREF(string_io); /* free the original reference */
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;
}
/* string conversion, escape non-unicode chars, coerce must be set to NULL */
const char *PuC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
{
char *result;
result= _PyUnicode_AsString(py_str);
if(result) {
/* 99% of the time this is enough but we better support non unicode
* chars since blender doesnt limit this */
return result;
}
else {
/* mostly copied from fileio.c's, fileio_init */
PyObject *stringobj;
PyObject *u;
PyErr_Clear();
u= PyUnicode_FromObject(py_str); /* coerce into unicode */
if (u == NULL)
return NULL;
stringobj= PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(u), PyUnicode_GET_SIZE(u), "surrogateescape");
Py_DECREF(u);
if (stringobj == NULL)
return NULL;
if (!PyBytes_Check(stringobj)) { /* this seems wrong but it works fine */
// printf("encoder failed to return bytes\n");
Py_DECREF(stringobj);
return NULL;
}
*coerce= stringobj;
return PyBytes_AS_STRING(stringobj);
}
}
PyObject *PyC_UnicodeFromByte(const char *str)
{
PyObject *result= PyUnicode_FromString(str);
if(result) {
/* 99% of the time this is enough but we better support non unicode
* chars since blender doesnt limit this */
return result;
}
else {
PyErr_Clear();
result= PyUnicode_DecodeUTF8(str, strlen(str), "surrogateescape");
return result;
}
}

View File

@@ -0,0 +1,41 @@
/**
* $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 *****
*/
#ifndef PY_CAPI_UTILS_H
#define PY_CAPI_UTILS_H
struct PyObject;
void PyC_ObSpit(char *name, PyObject *var);
void PyC_LineSpit(void);
PyObject * PyC_ExceptionBuffer(void);
PyObject * PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...);
void PyC_FileAndNum(const char **filename, int *lineno);
int PyC_AsArray(void *array, PyObject *value, int length, PyTypeObject *type, char *error_prefix);
/* follow http://www.python.org/dev/peps/pep-0383/ */
PyObject * PyC_UnicodeFromByte(const char *str);
const char * PuC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */
#endif // PY_CAPI_UTILS_H

View File

@@ -22,4 +22,4 @@
* ***** END GPL LICENSE BLOCK ***** */
void BPy_init_modules( void );

View File

@@ -24,6 +24,7 @@
#include "bpy_rna.h"
#include "BKE_global.h"
#include "MEM_guardedalloc.h"
#define MAX_ARRAY_DIMENSION 10
@@ -144,8 +145,9 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA
return 0;
}
#else
PyErr_Format(PyExc_ValueError, "%s %s.%s: array length cannot be changed to %d", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), tot);
return 0;
*totitem= tot;
return 1;
#endif
}
@@ -248,22 +250,25 @@ static int py_to_array(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, Paramet
}
if (totitem) {
if (!param_data || RNA_property_flag(prop) & PROP_DYNAMIC)
data= PyMem_MALLOC(item_size * totitem);
else
/* note: this code is confusing */
if(param_data && RNA_property_flag(prop) & PROP_DYNAMIC) {
/* not freeing allocated mem, RNA_parameter_list_free() will do this */
ParameterDynAlloc *param_alloc= (ParameterDynAlloc *)param_data;
param_alloc->array_tot= (int)totitem;
param_alloc->array= MEM_callocN(item_size * totitem, "py_to_array dyn"); /* freeing param list will free */
data= param_alloc->array;
}
else if (param_data) {
data= param_data;
}
else {
data= PyMem_MALLOC(item_size * totitem);
}
copy_values(py, ptr, prop, 0, data, item_size, NULL, convert_item, NULL);
if (param_data) {
if (RNA_property_flag(prop) & PROP_DYNAMIC) {
/* not freeing allocated mem, RNA_parameter_list_free will do this */
*(char**)param_data= data;
RNA_parameter_length_set_data(parms, prop, param_data, totitem);
}
}
else {
if (param_data==NULL) {
/* NULL can only pass through in case RNA property arraylength is 0 (impossible?) */
rna_set_array(ptr, prop, data);
PyMem_FREE(data);
@@ -452,10 +457,10 @@ static PyObject *pyrna_py_from_array_internal(PointerRNA *ptr, PropertyRNA *prop
}
#endif
PyObject *pyrna_py_from_array_index(BPy_PropertyRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index)
PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index)
{
int totdim, arraydim, arrayoffset, dimsize[MAX_ARRAY_DIMENSION], i, len;
BPy_PropertyRNA *ret= NULL;
BPy_PropertyArrayRNA *ret= NULL;
arraydim= self ? self->arraydim : 0;
arrayoffset = self ? self->arrayoffset : 0;
@@ -473,7 +478,7 @@ PyObject *pyrna_py_from_array_index(BPy_PropertyRNA *self, PointerRNA *ptr, Prop
totdim= RNA_property_array_dimension(ptr, prop, dimsize);
if (arraydim + 1 < totdim) {
ret= (BPy_PropertyRNA*)pyrna_prop_CreatePyObject(ptr, prop);
ret= (BPy_PropertyArrayRNA*)pyrna_prop_CreatePyObject(ptr, prop);
ret->arraydim= arraydim + 1;
/* arr[3][4][5]
@@ -491,7 +496,7 @@ PyObject *pyrna_py_from_array_index(BPy_PropertyRNA *self, PointerRNA *ptr, Prop
}
else {
index = arrayoffset + index;
ret= (BPy_PropertyRNA*)pyrna_array_item(ptr, prop, index);
ret= (BPy_PropertyArrayRNA *)pyrna_array_item(ptr, prop, index);
}
return (PyObject*)ret;

View File

@@ -41,6 +41,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_path_util.h"
#include "BLI_math_base.h"
#include "BLI_string.h"
#include "BKE_context.h"
#include "BKE_text.h"

View File

@@ -40,6 +40,45 @@
#include "MEM_guardedalloc.h"
#include "BKE_report.h"
static PyObject *pyop_poll( PyObject * self, PyObject * args)
{
wmOperatorType *ot;
char *opname;
PyObject *context_dict= NULL; /* optional args */
PyObject *context_dict_back;
PyObject *ret;
// 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, "s|O:_bpy.ops.poll", &opname, &context_dict))
return NULL;
ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
PyErr_Format(PyExc_SystemError, "Polling operator \"bpy.ops.%s\" error, could not be found", opname);
return NULL;
}
if(!PyDict_Check(context_dict))
context_dict= NULL;
context_dict_back= CTX_py_dict_get(C);
CTX_py_dict_set(C, (void *)context_dict);
Py_XINCREF(context_dict); /* so we done loose it */
/* main purpose of thsi function */
ret= WM_operator_poll((bContext*)C, ot) ? Py_True : Py_False;
/* restore with original context dict, probably NULL but need this for nested operator calls */
Py_XDECREF(context_dict);
CTX_py_dict_set(C, (void *)context_dict_back);
Py_INCREF(ret);
return ret;
}
static PyObject *pyop_call( PyObject * self, PyObject * args)
{
@@ -66,7 +105,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
PyErr_Format( PyExc_SystemError, "Calling operator \"bpy.ops.%s\" error, could not be found", opname);
PyErr_Format(PyExc_SystemError, "Calling operator \"bpy.ops.%s\" error, could not be found", opname);
return NULL;
}
@@ -252,6 +291,7 @@ static PyObject *pyop_getrna(PyObject *self, PyObject *value)
PyObject *BPY_operator_module( void )
{
static PyMethodDef pyop_poll_meth = {"poll", (PyCFunction) pyop_poll, METH_VARARGS, NULL};
static PyMethodDef pyop_call_meth = {"call", (PyCFunction) pyop_call, METH_VARARGS, NULL};
static PyMethodDef pyop_as_string_meth ={"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL};
static PyMethodDef pyop_dir_meth = {"dir", (PyCFunction) pyop_dir, METH_NOARGS, NULL};
@@ -261,11 +301,12 @@ PyObject *BPY_operator_module( void )
PyObject *submodule = PyModule_New("_bpy.ops");
PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy.ops", submodule);
PyModule_AddObject( submodule, "call", PyCFunction_New(&pyop_call_meth, NULL) );
PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) );
PyModule_AddObject( submodule, "dir", PyCFunction_New(&pyop_dir_meth, NULL) );
PyModule_AddObject( submodule, "get_rna", PyCFunction_New(&pyop_getrna_meth, NULL) );
PyModule_AddObject( submodule, "macro_define",PyCFunction_New(&pyop_macro_def_meth, NULL) );
PyModule_AddObject( submodule, "poll", PyCFunction_New(&pyop_poll_meth, NULL) );
PyModule_AddObject( submodule, "call", PyCFunction_New(&pyop_call_meth, NULL) );
PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth, NULL) );
PyModule_AddObject( submodule, "dir", PyCFunction_New(&pyop_dir_meth, NULL) );
PyModule_AddObject( submodule, "get_rna", PyCFunction_New(&pyop_getrna_meth, NULL) );
PyModule_AddObject( submodule, "macro_define",PyCFunction_New(&pyop_macro_def_meth, NULL) );
return submodule;
}

View File

@@ -26,11 +26,15 @@
#include "bpy_rna.h"
#include "bpy_util.h"
#include "BKE_utildefines.h"
#include "RNA_define.h" /* for defining our own rna */
#include "RNA_enum_types.h"
#include "MEM_guardedalloc.h"
#include "../generic/py_capi_utils.h"
EnumPropertyItem property_flag_items[] = {
{PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
{PROP_ANIMATABLE, "ANIMATABLE", 0, "Animateable", ""},
@@ -156,7 +160,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -219,7 +223,7 @@ PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
if(pydef && BPyAsPrimitiveArray(def, pydef, size, &PyBool_Type, "BoolVectorProperty(default=sequence)") < 0)
if(pydef && PyC_AsArray(def, pydef, size, &PyBool_Type, "BoolVectorProperty(default=sequence)") < 0)
return NULL;
// prop= RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name, description);
@@ -232,7 +236,7 @@ PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -292,13 +296,13 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
RNA_def_property_int_default(prop, def);
RNA_def_property_range(prop, min, max);
RNA_def_property_ui_text(prop, name, description);
RNA_def_property_ui_range(prop, soft_min, soft_max, step, 3);
RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
if(pyopts) {
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -361,7 +365,7 @@ PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
if(pydef && BPyAsPrimitiveArray(def, pydef, size, &PyLong_Type, "IntVectorProperty(default=sequence)") < 0)
if(pydef && PyC_AsArray(def, pydef, size, &PyLong_Type, "IntVectorProperty(default=sequence)") < 0)
return NULL;
prop= RNA_def_property(srna, id, PROP_INT, subtype);
@@ -369,13 +373,13 @@ PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if(pydef) RNA_def_property_int_array_default(prop, def);
RNA_def_property_range(prop, min, max);
RNA_def_property_ui_text(prop, name, description);
RNA_def_property_ui_range(prop, soft_min, soft_max, step, 3);
RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
if(pyopts) {
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -446,13 +450,13 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
RNA_def_property_float_default(prop, def);
RNA_def_property_range(prop, min, max);
RNA_def_property_ui_text(prop, name, description);
RNA_def_property_ui_range(prop, soft_min, soft_max, step, precision);
RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
if(pyopts) {
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -515,7 +519,7 @@ PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
}
if(pydef && BPyAsPrimitiveArray(def, pydef, size, &PyFloat_Type, "FloatVectorProperty(default=sequence)") < 0)
if(pydef && PyC_AsArray(def, pydef, size, &PyFloat_Type, "FloatVectorProperty(default=sequence)") < 0)
return NULL;
prop= RNA_def_property(srna, id, PROP_FLOAT, subtype);
@@ -523,13 +527,13 @@ PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if(pydef) RNA_def_property_float_array_default(prop, def);
RNA_def_property_range(prop, min, max);
RNA_def_property_ui_text(prop, name, description);
RNA_def_property_ui_range(prop, soft_min, soft_max, step, precision);
RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
if(pyopts) {
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -594,7 +598,7 @@ PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -700,7 +704,7 @@ PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
MEM_freeN(eitems);
Py_RETURN_NONE;
@@ -717,7 +721,7 @@ static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix
srna= srna_from_self(value, "BoolProperty(...):");
if(!srna) {
PyObject *msg= BPY_exception_buffer();
PyObject *msg= PyC_ExceptionBuffer();
char *msg_char= _PyUnicode_AsString(msg);
PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from IDPropertyGroup, failed with: %s", error_prefix, msg_char);
Py_DECREF(msg);
@@ -783,7 +787,7 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */
@@ -843,7 +847,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
if((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
}
RNA_def_property_duplicate_pointers(prop);
RNA_def_property_duplicate_pointers(srna, prop);
Py_RETURN_NONE;
}
else { /* operators defer running this function */

View File

@@ -54,10 +54,11 @@
#ifdef USE_MATHUTILS
#include "../generic/mathutils.h" /* so we can have mathutils callbacks */
#include "../generic/IDProp.h" /* for IDprop lookups */
#include "../generic/py_capi_utils.h"
static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyRNA *self, PointerRNA *ptr, PropertyRNA *prop, int start, int stop, int length);
static Py_ssize_t pyrna_prop_array_length(BPy_PropertyRNA *self);
static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, void *data, PyObject *value, const char *error_prefix);
static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int start, int stop, int length);
static Py_ssize_t pyrna_prop_array_length(BPy_PropertyArrayRNA *self);
static Py_ssize_t pyrna_prop_collection_length(BPy_PropertyRNA *self);
static short pyrna_rotation_euler_order_get(PointerRNA *ptr, PropertyRNA **prop_eul_order, short order_fallback);
@@ -100,6 +101,11 @@ static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype)
float min, max;
if(self->prop==NULL)
return 0;
if (!RNA_property_editable_flag(&self->ptr, self->prop)) {
PyErr_Format(PyExc_AttributeError, "bpy_prop \"%.200s.%.200s\" is read-only", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop));
return 0;
}
RNA_property_float_range(&self->ptr, self->prop, &min, &max);
@@ -143,6 +149,11 @@ static int mathutils_rna_vector_set_index(BaseMathObject *bmo, int subtype, int
if(self->prop==NULL)
return 0;
if (!RNA_property_editable_flag(&self->ptr, self->prop)) {
PyErr_Format(PyExc_AttributeError, "bpy_prop \"%.200s.%.200s\" is read-only", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop));
return 0;
}
RNA_property_float_clamp(&self->ptr, self->prop, &bmo->data[index]);
RNA_property_float_set_index(&self->ptr, self->prop, index, bmo->data[index]);
@@ -179,6 +190,12 @@ static int mathutils_rna_matrix_set(BaseMathObject *bmo, int subtype)
if(self->prop==NULL)
return 0;
if (!RNA_property_editable_flag(&self->ptr, self->prop)) {
PyErr_Format(PyExc_AttributeError, "bpy_prop \"%.200s.%.200s\" is read-only", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop));
return 0;
}
/* can ignore clamping here */
RNA_property_float_set_array(&self->ptr, self->prop, bmo->data);
RNA_property_update(BPy_GetContext(), &self->ptr, self->prop);
@@ -193,62 +210,6 @@ Mathutils_Callback mathutils_rna_matrix_cb = {
NULL
};
#ifdef USE_STRING_COERCE
/* string conversion, escape non-unicode chars, coerce must be set to NULL */
static const char *py_safe_unicode_to_byte(PyObject *py_str, PyObject **coerce)
{
char *result;
result= _PyUnicode_AsString(py_str);
if(result) {
/* 99% of the time this is enough but we better support non unicode
* chars since blender doesnt limit this */
return result;
}
else {
/* mostly copied from fileio.c's, fileio_init */
PyObject *stringobj;
PyObject *u;
PyErr_Clear();
u= PyUnicode_FromObject(py_str); /* coerce into unicode */
if (u == NULL)
return NULL;
stringobj= PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(u), PyUnicode_GET_SIZE(u), "surrogateescape");
Py_DECREF(u);
if (stringobj == NULL)
return NULL;
if (!PyBytes_Check(stringobj)) { /* this seems wrong but it works fine */
// printf("encoder failed to return bytes\n");
Py_DECREF(stringobj);
return NULL;
}
*coerce= stringobj;
return PyBytes_AS_STRING(stringobj);
}
}
static PyObject *py_safe_byte_to_unicode(char *str)
{
PyObject *result= PyUnicode_FromString(str);
if(result) {
/* 99% of the time this is enough but we better support non unicode
* chars since blender doesnt limit this */
return result;
}
else {
PyErr_Clear();
result= PyUnicode_DecodeUTF8(str, strlen(str), "surrogateescape");
return result;
}
}
#endif
/* same as RNA_enum_value_from_id but raises an exception */
int pyrna_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value, const char *error_prefix)
{
@@ -540,7 +501,7 @@ static PyObject *pyrna_prop_str( BPy_PropertyRNA *self )
if(type==PROP_COLLECTION) {
len= pyrna_prop_collection_length(self);
} else if (RNA_property_array_check(&self->ptr, self->prop)) {
len= pyrna_prop_array_length(self);
len= pyrna_prop_array_length((BPy_PropertyArrayRNA *)self);
}
if(len != -1)
@@ -831,7 +792,7 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
#ifdef USE_STRING_COERCE
/* only file paths get special treatment, they may contain non utf-8 chars */
if(ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
ret= py_safe_byte_to_unicode(buf);
ret= PyC_UnicodeFromByte(buf);
}
else {
ret= PyUnicode_FromString(buf);
@@ -956,7 +917,7 @@ static PyObject *pyrna_func_to_py(BPy_DummyPointerRNA *pyrna, FunctionRNA *func)
int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, void *data, PyObject *value, const char *error_prefix)
static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, void *data, PyObject *value, const char *error_prefix)
{
/* XXX hard limits should be checked here */
int type = RNA_property_type(prop);
@@ -1044,7 +1005,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
PyObject *value_coerce= NULL;
int subtype= RNA_property_subtype(prop);
if(ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
param= py_safe_unicode_to_byte(value, &value_coerce);
param= PuC_UnicodeAsByte(value, &value_coerce);
}
else {
param= _PyUnicode_AsString(value);
@@ -1111,7 +1072,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
}
/* another exception, allow to pass a collection as an RNA property */
if(Py_TYPE(value)==&pyrna_prop_collection_Type) {
if(Py_TYPE(value)==&pyrna_prop_collection_Type) { /* ok to ignore idprop collections */
PointerRNA c_ptr;
BPy_PropertyRNA *value_prop= (BPy_PropertyRNA *)value;
if(RNA_property_collection_type_get(&value_prop->ptr, value_prop->prop, &c_ptr)) {
@@ -1223,7 +1184,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
RNA_property_collection_add(ptr, prop, &itemptr);
if(pyrna_pydict_to_props(&itemptr, item, 1, "Converting a python list to an RNA collection")==-1) {
PyObject *msg= BPY_exception_buffer();
PyObject *msg= PyC_ExceptionBuffer();
char *msg_char= _PyUnicode_AsString(msg);
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s error converting a member of a collection from a dicts into an RNA collection, failed with: %s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), msg_char);
@@ -1250,12 +1211,12 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
return 0;
}
static PyObject * pyrna_prop_to_py_index(BPy_PropertyRNA *self, int index)
static PyObject * pyrna_prop_array_to_py_index(BPy_PropertyArrayRNA *self, int index)
{
return pyrna_py_from_array_index(self, &self->ptr, self->prop, index);
}
static int pyrna_py_to_prop_index(BPy_PropertyRNA *self, int index, PyObject *value)
static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, PyObject *value)
{
int ret = 0;
int totdim;
@@ -1325,7 +1286,7 @@ static int pyrna_py_to_prop_index(BPy_PropertyRNA *self, int index, PyObject *va
}
//---------------sequence-------------------------------------------
static Py_ssize_t pyrna_prop_array_length(BPy_PropertyRNA *self)
static Py_ssize_t pyrna_prop_array_length(BPy_PropertyArrayRNA *self)
{
if (RNA_property_array_dimension(&self->ptr, self->prop, NULL) > 1)
return RNA_property_multi_array_length(&self->ptr, self->prop, self->arraydim);
@@ -1377,14 +1338,14 @@ static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_s
return NULL;
}
static PyObject *pyrna_prop_array_subscript_int(BPy_PropertyRNA *self, int keynum)
static PyObject *pyrna_prop_array_subscript_int(BPy_PropertyArrayRNA *self, int keynum)
{
int len= pyrna_prop_array_length(self);
if(keynum < 0) keynum += len;
if(keynum >= 0 && keynum < len)
return pyrna_prop_to_py_index(self, keynum);
return pyrna_prop_array_to_py_index(self, keynum);
PyErr_Format(PyExc_IndexError, "bpy_prop_array[index]: index %d out of range", keynum);
return NULL;
@@ -1425,10 +1386,10 @@ static PyObject *pyrna_prop_collection_subscript_slice(PointerRNA *ptr, Property
}
/* TODO - dimensions
* note: could also use pyrna_prop_to_py_index(self, count) in a loop but its a lot slower
* note: could also use pyrna_prop_array_to_py_index(self, count) in a loop but its a lot slower
* since at the moment it reads (and even allocates) the entire array for each index.
*/
static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyRNA *self, PointerRNA *ptr, PropertyRNA *prop, int start, int stop, int length)
static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int start, int stop, int length)
{
int count, totdim;
@@ -1438,7 +1399,7 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyRNA *self, Pointer
if (totdim > 1) {
for (count = start; count < stop; count++)
PyList_SET_ITEM(list, count - start, pyrna_prop_to_py_index(self, count));
PyList_SET_ITEM(list, count - start, pyrna_prop_array_to_py_index(self, count));
}
else {
switch (RNA_property_type(prop)) {
@@ -1536,7 +1497,7 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject
}
}
static PyObject *pyrna_prop_array_subscript(BPy_PropertyRNA *self, PyObject *key)
static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject *key)
{
/*if (PyUnicode_Check(key)) {
return pyrna_prop_array_subscript_str(self, _PyUnicode_AsString(key));
@@ -1571,7 +1532,7 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyRNA *self, PyObject *key
}
}
/* could call (pyrna_py_to_prop_index(self, i, value) in a loop but it is slow */
/* could call (pyrna_py_to_prop_array_index(self, i, value) in a loop but it is slow */
static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, int start, int stop, int length, PyObject *value_orig)
{
PyObject *value;
@@ -1674,20 +1635,20 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, in
}
static int prop_subscript_ass_array_int(BPy_PropertyRNA *self, Py_ssize_t keynum, PyObject *value)
static int prop_subscript_ass_array_int(BPy_PropertyArrayRNA *self, Py_ssize_t keynum, PyObject *value)
{
int len= pyrna_prop_array_length(self);
if(keynum < 0) keynum += len;
if(keynum >= 0 && keynum < len)
return pyrna_py_to_prop_index(self, keynum, value);
return pyrna_py_to_prop_array_index(self, keynum, value);
PyErr_SetString(PyExc_IndexError, "bpy_prop_array[index] = value: index out of range");
return -1;
}
static int pyrna_prop_array_ass_subscript( BPy_PropertyRNA *self, PyObject *key, PyObject *value )
static int pyrna_prop_array_ass_subscript( BPy_PropertyArrayRNA *self, PyObject *key, PyObject *value )
{
/* char *keyname = NULL; */ /* not supported yet */
int ret= -1;
@@ -2306,11 +2267,16 @@ static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args)
return NULL;
if (RNA_path_resolve(&self->ptr, path, &r_ptr, &r_prop)) {
if(coerce == Py_False) {
return pyrna_prop_CreatePyObject(&r_ptr, r_prop);
if(r_prop) {
if(coerce == Py_False) {
return pyrna_prop_CreatePyObject(&r_ptr, r_prop);
}
else {
return pyrna_prop_to_py(&r_ptr, r_prop);
}
}
else {
return pyrna_prop_to_py(&r_ptr, r_prop);
return pyrna_struct_CreatePyObject(&r_ptr);
}
}
else {
@@ -2744,7 +2710,7 @@ static int pyrna_prop_collection_setattro( BPy_PropertyRNA *self, PyObject *pyna
}
/* odd case, we need to be able return a python method from a tp_getset */
static PyObject *pyrna_prop_add(BPy_PropertyRNA *self)
static PyObject *pyrna_prop_collection_idprop_add(BPy_PropertyRNA *self)
{
PointerRNA r_ptr;
@@ -2758,7 +2724,7 @@ static PyObject *pyrna_prop_add(BPy_PropertyRNA *self)
}
}
static PyObject *pyrna_prop_remove(BPy_PropertyRNA *self, PyObject *value)
static PyObject *pyrna_prop_collection_idprop_remove(BPy_PropertyRNA *self, PyObject *value)
{
PyObject *ret;
int key= PyLong_AsSsize_t(value);
@@ -2779,7 +2745,7 @@ static PyObject *pyrna_prop_remove(BPy_PropertyRNA *self, PyObject *value)
return ret;
}
static PyObject *pyrna_prop_move(BPy_PropertyRNA *self, PyObject *args)
static PyObject *pyrna_prop_collection_idprop_move(BPy_PropertyRNA *self, PyObject *args)
{
PyObject *ret;
int key=0, pos=0;
@@ -2943,19 +2909,16 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args)
static char pyrna_struct_as_pointer_doc[] =
".. method:: as_pointer()\n"
"\n"
" Returns capsule which holds a pointer to blenders internal data\n"
" Returns the memory address which holds a pointer to blenders internal data\n"
"\n"
" :return: capsule with a name set from the struct type.\n"
" :rtype: PyCapsule\n"
" :rtype: int\n"
"\n"
" .. note:: This is intended only for advanced script writers who need to pass blender data to their own C/Python modules.\n";
static PyObject *pyrna_struct_as_pointer(BPy_StructRNA *self)
{
if(self->ptr.data)
return PyCapsule_New(self->ptr.data, RNA_struct_identifier(self->ptr.type), NULL);
Py_RETURN_NONE;
return PyLong_FromVoidPtr(self->ptr.data);
}
static PyObject *pyrna_prop_get(BPy_PropertyRNA *self, PyObject *args)
@@ -3228,7 +3191,7 @@ static PyObject *pyrna_prop_foreach_set(BPy_PropertyRNA *self, PyObject *args)
/* A bit of a kludge, make a list out of a collection or array,
* then return the lists iter function, not especially fast but convenient for now */
PyObject *pyrna_prop_array_iter(BPy_PropertyRNA *self)
PyObject *pyrna_prop_array_iter(BPy_PropertyArrayRNA *self)
{
/* Try get values from a collection */
PyObject *ret;
@@ -3325,11 +3288,13 @@ static struct PyMethodDef pyrna_prop_collection_methods[] = {
{"values", (PyCFunction)pyrna_prop_values, METH_NOARGS, NULL},
{"get", (PyCFunction)pyrna_prop_get, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};
/* moved into a getset */
{"add", (PyCFunction)pyrna_prop_add, METH_NOARGS, NULL},
{"remove", (PyCFunction)pyrna_prop_remove, METH_O, NULL},
{"move", (PyCFunction)pyrna_prop_move, METH_VARARGS, NULL},
static struct PyMethodDef pyrna_prop_collection_idprop_methods[] = {
{"add", (PyCFunction)pyrna_prop_collection_idprop_add, METH_NOARGS, NULL},
{"remove", (PyCFunction)pyrna_prop_collection_idprop_remove, METH_O, NULL},
{"move", (PyCFunction)pyrna_prop_collection_idprop_move, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};
@@ -3391,9 +3356,9 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, ParameterList *parms, PropertyRNA *
int len;
if (flag & PROP_DYNAMIC) {
len= RNA_parameter_length_get_data(parms, prop, data);
data= *((void **)data);
ParameterDynAlloc *data_alloc= data;
len= data_alloc->array_tot;
data= data_alloc->array;
}
else
len= RNA_property_array_length(ptr, prop);
@@ -3466,7 +3431,7 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, ParameterList *parms, PropertyRNA *
#ifdef USE_STRING_COERCE
if(ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
ret= py_safe_byte_to_unicode(data_ch);
ret= PyC_UnicodeFromByte(data_ch);
}
else {
ret= PyUnicode_FromString(data_ch);
@@ -3940,7 +3905,7 @@ PyTypeObject pyrna_prop_Type = {
PyTypeObject pyrna_prop_array_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"bpy_prop_array", /* tp_name */
sizeof( BPy_PropertyRNA ), /* tp_basicsize */
sizeof( BPy_PropertyArrayRNA ), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
NULL, /* tp_dealloc */
@@ -4097,6 +4062,87 @@ PyTypeObject pyrna_prop_collection_Type = {
NULL
};
/* only for add/remove/move methods */
PyTypeObject pyrna_prop_collection_idprop_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"bpy_prop_collection_idprop", /* tp_name */
sizeof( BPy_PropertyRNA ), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
NULL, /* tp_dealloc */
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
NULL, /* subclassed */ /* tp_repr */
/* Method suites for standard classes */
NULL, /* PyNumberMethods *tp_as_number; */
NULL, /* PySequenceMethods *tp_as_sequence; */
NULL, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
/* will only use these if this is a subtype of a py class */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
/* Functions to access object as input/output buffer */
NULL, /* PyBufferProcs *tp_as_buffer; */
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* long tp_flags; */
NULL, /* char *tp_doc; Documentation string */
/*** Assigned meaning in release 2.0 ***/
/* call function for all accessible objects */
NULL, /* traverseproc tp_traverse; */
/* delete references to contained objects */
NULL, /* inquiry tp_clear; */
/*** Assigned meaning in release 2.1 ***/
/*** rich comparisons ***/
NULL, /* subclassed */ /* richcmpfunc tp_richcompare; */
/*** weak reference enabler ***/
0, /* long tp_weaklistoffset; */
/*** Added in release 2.2 ***/
/* Iterators */
NULL, /* getiterfunc tp_iter; */
NULL, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
pyrna_prop_collection_idprop_methods, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
NULL /*pyrna_prop_getseters*/, /* struct PyGetSetDef *tp_getset; */
&pyrna_prop_collection_Type, /* struct _typeobject *tp_base; */
NULL, /* PyObject *tp_dict; */
NULL, /* descrgetfunc tp_descr_get; */
NULL, /* descrsetfunc tp_descr_set; */
0, /* long tp_dictoffset; */
NULL, /* initproc tp_init; */
NULL, /* allocfunc tp_alloc; */
NULL, /* newfunc tp_new; */
/* Low-level free-memory routine */
NULL, /* freefunc tp_free; */
/* For PyObject_IS_GC */
NULL, /* inquiry tp_is_gc; */
NULL, /* PyObject *tp_bases; */
/* method resolution order */
NULL, /* PyObject *tp_mro; */
NULL, /* PyObject *tp_cache; */
NULL, /* PyObject *tp_subclasses; */
NULL, /* PyObject *tp_weaklist; */
NULL
};
static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna)
{
PointerRNA ptr;
@@ -4106,7 +4152,7 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna)
Py_INCREF(newclass);
if (RNA_struct_py_type_get(srna))
PyObSpit("RNA WAS SET - ", RNA_struct_py_type_get(srna));
PyC_ObSpit("RNA WAS SET - ", RNA_struct_py_type_get(srna));
Py_XDECREF(((PyObject *)RNA_struct_py_type_get(srna)));
@@ -4192,7 +4238,7 @@ static PyObject* pyrna_srna_ExternalType(StructRNA *srna)
if(base_compare != base) {
fprintf(stderr, "pyrna_srna_ExternalType: incorrect subclassing of SRNA '%s'\nSee bpy_types.py\n", idname);
PyObSpit("Expected! ", base_compare);
PyC_ObSpit("Expected! ", base_compare);
newclass= NULL;
}
else {
@@ -4242,7 +4288,7 @@ static PyObject* pyrna_srna_Subtype(StructRNA *srna)
newclass = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sss()}", idname, py_base, "__module__","bpy.types", "__slots__");
/* newclass will now have 2 ref's, ???, probably 1 is internal since decrefing here segfaults */
/* PyObSpit("new class ref", newclass); */
/* PyC_ObSpit("new class ref", newclass); */
if (newclass) {
/* srna owns one, and the other is owned by the caller */
@@ -4308,7 +4354,7 @@ PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr )
pyrna->ptr= *ptr;
pyrna->freeptr= FALSE;
// PyObSpit("NewStructRNA: ", (PyObject *)pyrna);
// PyC_ObSpit("NewStructRNA: ", (PyObject *)pyrna);
return ( PyObject * ) pyrna;
}
@@ -4316,12 +4362,29 @@ PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr )
PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop )
{
BPy_PropertyRNA *pyrna;
PyTypeObject *type;
if (RNA_property_type(prop) == PROP_COLLECTION) type= &pyrna_prop_collection_Type;
else if (RNA_property_array_check(ptr, prop)) type= &pyrna_prop_array_Type;
else type= &pyrna_prop_Type;
pyrna = ( BPy_PropertyRNA * ) PyObject_NEW(BPy_PropertyRNA, type);
if (RNA_property_array_check(ptr, prop) == 0) {
PyTypeObject *type;
if (RNA_property_type(prop) != PROP_COLLECTION) {
type= &pyrna_prop_Type;
}
else {
if((RNA_property_flag(prop) & PROP_IDPROPERTY) == 0) {
type= &pyrna_prop_collection_Type;
}
else {
type= &pyrna_prop_collection_idprop_Type;
}
}
pyrna = (BPy_PropertyRNA *) PyObject_NEW(BPy_PropertyRNA, type);
}
else {
pyrna = (BPy_PropertyRNA *) PyObject_NEW(BPy_PropertyArrayRNA, &pyrna_prop_array_Type);
((BPy_PropertyArrayRNA *)pyrna)->arraydim= 0;
((BPy_PropertyArrayRNA *)pyrna)->arrayoffset= 0;
}
if( !pyrna ) {
PyErr_SetString( PyExc_MemoryError, "couldn't create BPy_rna object" );
@@ -4330,9 +4393,6 @@ PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop )
pyrna->ptr = *ptr;
pyrna->prop = prop;
pyrna->arraydim= 0;
pyrna->arrayoffset= 0;
return ( PyObject * ) pyrna;
}
@@ -4355,6 +4415,9 @@ void BPY_rna_init(void)
if( PyType_Ready( &pyrna_prop_collection_Type ) < 0 )
return;
if( PyType_Ready( &pyrna_prop_collection_idprop_Type ) < 0 )
return;
}
/* bpy.data from python */
@@ -4468,7 +4531,6 @@ PyObject *BPY_rna_types(void)
}
self= (BPy_BaseTypeRNA *)PyObject_NEW( BPy_BaseTypeRNA, &pyrna_basetype_Type );
self->arraydim = self->arrayoffset = 0; /* unused but better set */
/* avoid doing this lookup for every getattr */
RNA_blender_rna_pointer_create(&self->ptr);
@@ -4573,7 +4635,7 @@ static int deferred_register_prop(StructRNA *srna, PyObject *item, PyObject *key
PyErr_Print();
PyErr_Clear();
// PyLineSpit();
// PyC_LineSpit();
PyErr_Format(PyExc_ValueError, "bpy_struct \"%.200s\" registration error: %.200s could not register\n", RNA_struct_identifier(srna), _PyUnicode_AsString(key));
return -1;
}
@@ -4582,7 +4644,7 @@ static int deferred_register_prop(StructRNA *srna, PyObject *item, PyObject *key
/* Since this is a class dict, ignore args that can't be passed */
/* for testing only */
/* PyObSpit("Why doesn't this work??", item);
/* PyC_ObSpit("Why doesn't this work??", item);
PyErr_Print(); */
PyErr_Clear();
}
@@ -5027,7 +5089,7 @@ static void bpy_class_free(void *pyob_ptr)
if(G.f&G_DEBUG) {
if(self->ob_refcnt > 1) {
PyObSpit("zombie class - ref should be 1", self);
PyC_ObSpit("zombie class - ref should be 1", self);
}
}
@@ -5207,7 +5269,7 @@ static PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class)
/*if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")==NULL) {
PWM_cursor_wait(0);
yErr_SetString(PyExc_ValueError, "bpy.types.unregister(): not a registered as a subclass.");
PyErr_SetString(PyExc_ValueError, "bpy.types.unregister(): not a registered as a subclass.");
return NULL;
}*/

View File

@@ -51,6 +51,12 @@ typedef struct {
int freeptr; /* needed in some cases if ptr.data is created on the fly, free when deallocing */
} BPy_StructRNA;
typedef struct {
PyObject_HEAD /* required python macro */
PointerRNA ptr;
PropertyRNA *prop;
} BPy_PropertyRNA;
typedef struct {
PyObject_HEAD /* required python macro */
PointerRNA ptr;
@@ -59,7 +65,7 @@ typedef struct {
/* Arystan: this is a hack to allow sub-item r/w access like: face.uv[n][m] */
int arraydim; /* array dimension, e.g: 0 for face.uv, 2 for face.uv[n][m], etc. */
int arrayoffset; /* array first item offset, e.g. if face.uv is [4][2], arrayoffset for face.uv[n] is 2n */
} BPy_PropertyRNA;
} BPy_PropertyArrayRNA;
/* cheap trick */
#define BPy_BaseTypeRNA BPy_PropertyRNA
@@ -77,7 +83,6 @@ PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr );
PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop );
/* operators also need this to set args */
int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, void *data, PyObject *value, const char *error_prefix);
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix);
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
@@ -97,7 +102,7 @@ int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms,
int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, int arrayoffset, int index, PyObject *py, const char *error_prefix);
PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop);
PyObject *pyrna_py_from_array_index(BPy_PropertyRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index);
PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index);
PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop);
int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value);

View File

@@ -26,136 +26,14 @@
#include "BLI_dynstr.h"
#include "MEM_guardedalloc.h"
#include "BKE_report.h"
#include "BKE_context.h"
#include "../generic/py_capi_utils.h"
bContext* __py_context = NULL;
bContext* BPy_GetContext(void) { return __py_context; };
void BPy_SetContext(bContext *C) { __py_context= C; };
/* for debugging */
void PyObSpit(char *name, PyObject *var) {
fprintf(stderr, "<%s> : ", name);
if (var==NULL) {
fprintf(stderr, "<NIL>");
}
else {
PyObject_Print(var, stderr, 0);
fprintf(stderr, " ref:%d ", (int)var->ob_refcnt);
fprintf(stderr, " ptr:%p", (void *)var);
fprintf(stderr, " type:");
if(Py_TYPE(var))
fprintf(stderr, "%s", Py_TYPE(var)->tp_name);
else
fprintf(stderr, "<NIL>");
}
fprintf(stderr, "\n");
}
void PyLineSpit(void) {
const char *filename;
int lineno;
PyErr_Clear();
BPY_getFileAndNum(&filename, &lineno);
fprintf(stderr, "%s:%d\n", filename, lineno);
}
void BPY_getFileAndNum(const char **filename, int *lineno)
{
PyObject *getframe, *frame;
PyObject *f_lineno= NULL, *co_filename= NULL;
if (filename) *filename= NULL;
if (lineno) *lineno = -1;
getframe = PySys_GetObject("_getframe"); // borrowed
if (getframe==NULL) {
PyErr_Clear();
return;
}
frame = PyObject_CallObject(getframe, NULL);
if (frame==NULL) {
PyErr_Clear();
return;
}
/* when executing a script */
if (filename) {
co_filename= PyObject_GetAttrStringArgs(frame, 1, "f_code", "co_filename");
if (co_filename==NULL) {
PyErr_SetString(PyExc_SystemError, "Could not access sys._getframe().f_code.co_filename");
Py_DECREF(frame);
return;
}
*filename = _PyUnicode_AsString(co_filename);
Py_DECREF(co_filename);
}
/* when executing a module */
if(filename && *filename == NULL) {
/* try an alternative method to get the filename - module based
* references below are all borrowed (double checked) */
PyObject *mod_name= PyDict_GetItemString(PyEval_GetGlobals(), "__name__");
if(mod_name) {
PyObject *mod= PyDict_GetItem(PyImport_GetModuleDict(), mod_name);
if(mod) {
*filename= PyModule_GetFilename(mod);
}
/* unlikely, fallback */
if(*filename == NULL) {
*filename= _PyUnicode_AsString(mod_name);
}
}
}
if (lineno) {
f_lineno= PyObject_GetAttrString(frame, "f_lineno");
if (f_lineno==NULL) {
PyErr_SetString(PyExc_SystemError, "Could not access sys._getframe().f_lineno");
Py_DECREF(frame);
return;
}
*lineno = (int)PyLong_AsSsize_t(f_lineno);
Py_DECREF(f_lineno);
}
Py_DECREF(frame);
}
/* Would be nice if python had this built in */
PyObject *PyObject_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...)
{
Py_ssize_t i;
PyObject *item= o;
char *attr;
va_list vargs;
va_start(vargs, n);
for (i=0; i<n; i++) {
attr = va_arg(vargs, char *);
item = PyObject_GetAttrString(item, attr);
if (item)
Py_DECREF(item);
else /* python will set the error value here */
break;
}
va_end(vargs);
Py_XINCREF(item); /* final value has is increfed, to match PyObject_GetAttrString */
return item;
}
int BPY_class_validate(const char *class_type, PyObject *class, PyObject *base_class, BPY_class_attr_check* class_attrs, PyObject **py_class_attrs)
{
PyObject *item, *fitem;
@@ -244,75 +122,6 @@ int BPY_class_validate(const char *class_type, PyObject *class, PyObject *base_c
/* returns the exception string as a new PyUnicode object, depends on external StringIO module */
PyObject *BPY_exception_buffer(void)
{
PyObject *stdout_backup = PySys_GetObject("stdout"); /* borrowed */
PyObject *stderr_backup = PySys_GetObject("stderr"); /* borrowed */
PyObject *string_io = NULL;
PyObject *string_io_buf = NULL;
PyObject *string_io_mod= NULL;
PyObject *string_io_getvalue= NULL;
PyObject *error_type, *error_value, *error_traceback;
if (!PyErr_Occurred())
return NULL;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
PyErr_Clear();
/* import io
* string_io = io.StringIO()
*/
if(! (string_io_mod= PyImport_ImportModule("io")) ) {
goto error_cleanup;
} else if (! (string_io = PyObject_CallMethod(string_io_mod, "StringIO", NULL))) {
goto error_cleanup;
} else if (! (string_io_getvalue= PyObject_GetAttrString(string_io, "getvalue"))) {
goto error_cleanup;
}
Py_INCREF(stdout_backup); // since these were borrowed we dont want them freed when replaced.
Py_INCREF(stderr_backup);
PySys_SetObject("stdout", string_io); // both of these are free'd when restoring
PySys_SetObject("stderr", string_io);
PyErr_Restore(error_type, error_value, error_traceback);
PyErr_Print(); /* print the error */
PyErr_Clear();
string_io_buf = PyObject_CallObject(string_io_getvalue, NULL);
PySys_SetObject("stdout", stdout_backup);
PySys_SetObject("stderr", stderr_backup);
Py_DECREF(stdout_backup); /* now sys owns the ref again */
Py_DECREF(stderr_backup);
Py_DECREF(string_io_mod);
Py_DECREF(string_io_getvalue);
Py_DECREF(string_io); /* free the original reference */
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)
{
DynStr *dynstr= BLI_dynstr_new();
@@ -363,14 +172,14 @@ int BPy_errors_to_report(ReportList *reports)
return 1;
}
pystring= BPY_exception_buffer();
pystring= PyC_ExceptionBuffer();
if(pystring==NULL) {
BKE_report(reports, RPT_ERROR, "unknown py-exception, could not convert");
return 0;
}
BPY_getFileAndNum(&filename, &lineno);
PyC_FileAndNum(&filename, &lineno);
if(filename==NULL)
filename= "<unknown location>";
@@ -392,7 +201,7 @@ int BPy_errors_to_report(ReportList *reports)
}
/* array utility function */
int BPyAsPrimitiveArray(void *array, PyObject *value, int length, PyTypeObject *type, char *error_prefix)
int PyC_AsArray(void *array, PyObject *value, int length, PyTypeObject *type, char *error_prefix)
{
PyObject *value_fast;
int value_len;

View File

@@ -36,17 +36,6 @@
struct EnumPropertyItem;
struct ReportList;
void PyObSpit(char *name, PyObject *var);
void PyLineSpit(void);
void BPY_getFileAndNum(const char **filename, int *lineno);
PyObject *BPY_exception_buffer(void);
/* own python like utility function */
PyObject *PyObject_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...);
/* Class type checking, use for checking classes can be added as operators, panels etc */
typedef struct BPY_class_attr_check {
const char *name; /* name of the class attribute */
@@ -77,6 +66,4 @@ void BPy_SetContext(struct bContext *C);
extern void bpy_context_set(struct bContext *C, PyGILState_STATE *gilstate);
extern void bpy_context_clear(struct bContext *C, PyGILState_STATE *gilstate);
int BPyAsPrimitiveArray(void *array, PyObject *value, int length, PyTypeObject *type, char *error_prefix);
#endif