style cleanup: py/capi
This commit is contained in:
@@ -80,10 +80,10 @@ static PyObject *Buffer_repr(Buffer *self);
|
||||
|
||||
static PyObject *Buffer_to_list(Buffer *self)
|
||||
{
|
||||
int i, len= self->dimensions[0];
|
||||
PyObject *list= PyList_New(len);
|
||||
int i, len = self->dimensions[0];
|
||||
PyObject *list = PyList_New(len);
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
for (i = 0; i < len; i++) {
|
||||
PyList_SET_ITEM(list, i, Buffer_item(self, i));
|
||||
}
|
||||
|
||||
@@ -95,17 +95,17 @@ static PyObject *Buffer_to_list_recursive(Buffer *self)
|
||||
PyObject *list;
|
||||
|
||||
if (self->ndimensions > 1) {
|
||||
int i, len= self->dimensions[0];
|
||||
list= PyList_New(len);
|
||||
int i, len = self->dimensions[0];
|
||||
list = PyList_New(len);
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
Buffer *sub= (Buffer *)Buffer_item(self, i);
|
||||
for (i = 0; i < len; i++) {
|
||||
Buffer *sub = (Buffer *)Buffer_item(self, i);
|
||||
PyList_SET_ITEM(list, i, Buffer_to_list_recursive(sub));
|
||||
Py_DECREF(sub);
|
||||
}
|
||||
}
|
||||
else {
|
||||
list= Buffer_to_list(self);
|
||||
list = Buffer_to_list(self);
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -113,10 +113,10 @@ static PyObject *Buffer_to_list_recursive(Buffer *self)
|
||||
|
||||
static PyObject *Buffer_dimensions(Buffer *self, void *UNUSED(arg))
|
||||
{
|
||||
PyObject *list= PyList_New(self->ndimensions);
|
||||
PyObject *list = PyList_New(self->ndimensions);
|
||||
int i;
|
||||
|
||||
for (i= 0; i<self->ndimensions; i++) {
|
||||
for (i = 0; i < self->ndimensions; i++) {
|
||||
PyList_SET_ITEM(list, i, PyLong_FromLong(self->dimensions[i]));
|
||||
}
|
||||
|
||||
@@ -239,16 +239,16 @@ static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args) \
|
||||
int BGL_typeSize(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case GL_BYTE:
|
||||
return sizeof(char);
|
||||
case GL_SHORT:
|
||||
return sizeof(short);
|
||||
case GL_INT:
|
||||
return sizeof(int);
|
||||
case GL_FLOAT:
|
||||
return sizeof(float);
|
||||
case GL_DOUBLE:
|
||||
return sizeof(double);
|
||||
case GL_BYTE:
|
||||
return sizeof(char);
|
||||
case GL_SHORT:
|
||||
return sizeof(short);
|
||||
case GL_INT:
|
||||
return sizeof(int);
|
||||
case GL_FLOAT:
|
||||
return sizeof(float);
|
||||
case GL_DOUBLE:
|
||||
return sizeof(double);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -256,30 +256,31 @@ int BGL_typeSize(int type)
|
||||
Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuffer)
|
||||
{
|
||||
Buffer *buffer;
|
||||
void *buf= NULL;
|
||||
void *buf = NULL;
|
||||
int i, size, length;
|
||||
|
||||
length= 1;
|
||||
for (i=0; i<ndimensions; i++)
|
||||
length*= dimensions[i];
|
||||
|
||||
size= BGL_typeSize(type);
|
||||
|
||||
buf= MEM_mallocN(length*size, "Buffer buffer");
|
||||
|
||||
buffer= (Buffer *) PyObject_NEW(Buffer, &BGL_bufferType);
|
||||
buffer->parent= NULL;
|
||||
buffer->ndimensions= ndimensions;
|
||||
buffer->dimensions= MEM_mallocN(ndimensions*sizeof(int), "Buffer dimensions");
|
||||
memcpy(buffer->dimensions, dimensions, ndimensions*sizeof(int));
|
||||
buffer->type= type;
|
||||
buffer->buf.asvoid= buf;
|
||||
length = 1;
|
||||
for (i = 0; i < ndimensions; i++) {
|
||||
length *= dimensions[i];
|
||||
}
|
||||
|
||||
size = BGL_typeSize(type);
|
||||
|
||||
buf = MEM_mallocN(length * size, "Buffer buffer");
|
||||
|
||||
buffer = (Buffer *)PyObject_NEW(Buffer, &BGL_bufferType);
|
||||
buffer->parent = NULL;
|
||||
buffer->ndimensions = ndimensions;
|
||||
buffer->dimensions = MEM_mallocN(ndimensions * sizeof(int), "Buffer dimensions");
|
||||
memcpy(buffer->dimensions, dimensions, ndimensions * sizeof(int));
|
||||
buffer->type = type;
|
||||
buffer->buf.asvoid = buf;
|
||||
|
||||
if (initbuffer) {
|
||||
memcpy(buffer->buf.asvoid, initbuffer, length*size);
|
||||
memcpy(buffer->buf.asvoid, initbuffer, length * size);
|
||||
}
|
||||
else {
|
||||
memset(buffer->buf.asvoid, 0, length*size);
|
||||
memset(buffer->buf.asvoid, 0, length * size);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
@@ -288,10 +289,10 @@ Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuf
|
||||
#define MAX_DIMENSIONS 256
|
||||
static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyObject *length_ob= NULL, *init= NULL;
|
||||
PyObject *length_ob = NULL, *init = NULL;
|
||||
Buffer *buffer;
|
||||
int dimensions[MAX_DIMENSIONS];
|
||||
|
||||
|
||||
int type;
|
||||
Py_ssize_t i, ndimensions = 0;
|
||||
|
||||
@@ -312,15 +313,15 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject
|
||||
}
|
||||
|
||||
if (PyLong_Check(length_ob)) {
|
||||
ndimensions= 1;
|
||||
if (((dimensions[0]= PyLong_AsLong(length_ob)) < 1)) {
|
||||
ndimensions = 1;
|
||||
if (((dimensions[0] = PyLong_AsLong(length_ob)) < 1)) {
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"dimensions must be between 1 and "STRINGIFY(MAX_DIMENSIONS));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (PySequence_Check(length_ob)) {
|
||||
ndimensions= PySequence_Size(length_ob);
|
||||
ndimensions = PySequence_Size(length_ob);
|
||||
if (ndimensions > MAX_DIMENSIONS) {
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"too many dimensions, max is "STRINGIFY(MAX_DIMENSIONS));
|
||||
@@ -331,11 +332,13 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject
|
||||
"sequence must have at least one dimension");
|
||||
return NULL;
|
||||
}
|
||||
for (i=0; i<ndimensions; i++) {
|
||||
PyObject *ob= PySequence_GetItem(length_ob, i);
|
||||
for (i = 0; i < ndimensions; i++) {
|
||||
PyObject *ob = PySequence_GetItem(length_ob, i);
|
||||
|
||||
if (!PyLong_Check(ob)) dimensions[i]= 1;
|
||||
else dimensions[i]= PyLong_AsLong(ob);
|
||||
if (!PyLong_Check(ob))
|
||||
dimensions[i] = 1;
|
||||
else
|
||||
dimensions[i] = PyLong_AsLong(ob);
|
||||
Py_DECREF(ob);
|
||||
|
||||
if (dimensions[i] < 1) {
|
||||
@@ -351,16 +354,16 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject
|
||||
"or an int, not a %.200s", Py_TYPE(length_ob)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer= BGL_MakeBuffer(type, ndimensions, dimensions, NULL);
|
||||
|
||||
buffer = BGL_MakeBuffer(type, ndimensions, dimensions, NULL);
|
||||
if (init && ndimensions) {
|
||||
if (Buffer_ass_slice(buffer, 0, dimensions[0], init)) {
|
||||
Py_DECREF(buffer);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return (PyObject *) buffer;
|
||||
|
||||
return (PyObject *)buffer;
|
||||
}
|
||||
|
||||
/*@ Buffer sequence methods */
|
||||
@@ -377,12 +380,12 @@ static PyObject *Buffer_item(Buffer *self, int i)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (self->ndimensions==1) {
|
||||
if (self->ndimensions == 1) {
|
||||
switch (self->type) {
|
||||
case GL_BYTE: return Py_BuildValue("b", self->buf.asbyte[i]);
|
||||
case GL_SHORT: return Py_BuildValue("h", self->buf.asshort[i]);
|
||||
case GL_INT: return Py_BuildValue("i", self->buf.asint[i]);
|
||||
case GL_FLOAT: return PyFloat_FromDouble(self->buf.asfloat[i]);
|
||||
case GL_BYTE: return Py_BuildValue("b", self->buf.asbyte[i]);
|
||||
case GL_SHORT: return Py_BuildValue("h", self->buf.asshort[i]);
|
||||
case GL_INT: return Py_BuildValue("i", self->buf.asint[i]);
|
||||
case GL_FLOAT: return PyFloat_FromDouble(self->buf.asfloat[i]);
|
||||
case GL_DOUBLE: return Py_BuildValue("d", self->buf.asdouble[i]);
|
||||
}
|
||||
}
|
||||
@@ -390,26 +393,24 @@ static PyObject *Buffer_item(Buffer *self, int i)
|
||||
Buffer *newbuf;
|
||||
int j, length, size;
|
||||
|
||||
length= 1;
|
||||
for (j=1; j < self->ndimensions; j++) {
|
||||
length = 1;
|
||||
for (j = 1; j < self->ndimensions; j++) {
|
||||
length *= self->dimensions[j];
|
||||
}
|
||||
size= BGL_typeSize(self->type);
|
||||
size = BGL_typeSize(self->type);
|
||||
|
||||
newbuf= (Buffer *) PyObject_NEW(Buffer, &BGL_bufferType);
|
||||
newbuf = (Buffer *)PyObject_NEW(Buffer, &BGL_bufferType);
|
||||
|
||||
Py_INCREF(self);
|
||||
newbuf->parent= (PyObject *)self;
|
||||
newbuf->parent = (PyObject *)self;
|
||||
|
||||
newbuf->ndimensions= self->ndimensions - 1;
|
||||
newbuf->type= self->type;
|
||||
newbuf->buf.asvoid= self->buf.asbyte + i*length*size;
|
||||
newbuf->dimensions= MEM_mallocN(newbuf->ndimensions*sizeof(int),
|
||||
"Buffer dimensions");
|
||||
memcpy(newbuf->dimensions, self->dimensions+1,
|
||||
newbuf->ndimensions*sizeof(int));
|
||||
newbuf->ndimensions = self->ndimensions - 1;
|
||||
newbuf->type = self->type;
|
||||
newbuf->buf.asvoid = self->buf.asbyte + i * length * size;
|
||||
newbuf->dimensions = MEM_mallocN(newbuf->ndimensions * sizeof(int), "Buffer dimensions");
|
||||
memcpy(newbuf->dimensions, self->dimensions + 1, newbuf->ndimensions * sizeof(int));
|
||||
|
||||
return (PyObject *) newbuf;
|
||||
return (PyObject *)newbuf;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -420,13 +421,13 @@ static PyObject *Buffer_slice(Buffer *self, int begin, int end)
|
||||
PyObject *list;
|
||||
int count;
|
||||
|
||||
if (begin < 0) begin= 0;
|
||||
if (end > self->dimensions[0]) end= self->dimensions[0];
|
||||
if (begin > end) begin= end;
|
||||
if (begin < 0) begin = 0;
|
||||
if (end > self->dimensions[0]) end = self->dimensions[0];
|
||||
if (begin > end) begin = end;
|
||||
|
||||
list= PyList_New(end-begin);
|
||||
list = PyList_New(end - begin);
|
||||
|
||||
for (count= begin; count<end; count++) {
|
||||
for (count = begin; count < end; count++) {
|
||||
PyList_SET_ITEM(list, count-begin, Buffer_item(self, count));
|
||||
}
|
||||
return list;
|
||||
@@ -440,11 +441,11 @@ static int Buffer_ass_item(Buffer *self, int i, PyObject *v)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (self->ndimensions!=1) {
|
||||
Buffer *row= (Buffer *)Buffer_item(self, i);
|
||||
if (self->ndimensions != 1) {
|
||||
Buffer *row = (Buffer *)Buffer_item(self, i);
|
||||
|
||||
if (row) {
|
||||
int ret= Buffer_ass_slice(row, 0, self->dimensions[1], v);
|
||||
int ret = Buffer_ass_slice(row, 0, self->dimensions[1], v);
|
||||
Py_DECREF(row);
|
||||
return ret;
|
||||
}
|
||||
@@ -454,29 +455,23 @@ static int Buffer_ass_item(Buffer *self, int i, PyObject *v)
|
||||
}
|
||||
|
||||
switch (self->type) {
|
||||
case GL_BYTE:
|
||||
return PyArg_Parse(v, "b:Expected ints", &self->buf.asbyte[i]) ? 0:-1;
|
||||
case GL_SHORT:
|
||||
return PyArg_Parse(v, "h:Expected ints", &self->buf.asshort[i]) ? 0:-1;
|
||||
case GL_INT:
|
||||
return PyArg_Parse(v, "i:Expected ints", &self->buf.asint[i]) ? 0:-1;
|
||||
case GL_FLOAT:
|
||||
return PyArg_Parse(v, "f:Expected floats", &self->buf.asfloat[i]) ? 0:-1;
|
||||
case GL_DOUBLE:
|
||||
return PyArg_Parse(v, "d:Expected floats", &self->buf.asdouble[i]) ? 0:-1;
|
||||
default:
|
||||
return 0; /* should never happen */
|
||||
case GL_BYTE: return PyArg_Parse(v, "b:Expected ints", &self->buf.asbyte[i]) ? 0 : -1;
|
||||
case GL_SHORT: return PyArg_Parse(v, "h:Expected ints", &self->buf.asshort[i]) ? 0 : -1;
|
||||
case GL_INT: return PyArg_Parse(v, "i:Expected ints", &self->buf.asint[i]) ? 0 : -1;
|
||||
case GL_FLOAT: return PyArg_Parse(v, "f:Expected floats", &self->buf.asfloat[i]) ? 0 : -1;
|
||||
case GL_DOUBLE: return PyArg_Parse(v, "d:Expected floats", &self->buf.asdouble[i]) ? 0 : -1;
|
||||
default: return 0; /* should never happen */
|
||||
}
|
||||
}
|
||||
|
||||
static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq)
|
||||
{
|
||||
PyObject *item;
|
||||
int count, err=0;
|
||||
int count, err = 0;
|
||||
|
||||
if (begin < 0) begin= 0;
|
||||
if (end > self->dimensions[0]) end= self->dimensions[0];
|
||||
if (begin > end) begin= end;
|
||||
if (begin < 0) begin = 0;
|
||||
if (end > self->dimensions[0]) end = self->dimensions[0];
|
||||
if (begin > end) begin = end;
|
||||
|
||||
if (!PySequence_Check(seq)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
@@ -487,23 +482,25 @@ static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq)
|
||||
}
|
||||
|
||||
/* re-use count var */
|
||||
if ((count= PySequence_Size(seq)) != (end - begin)) {
|
||||
if ((count = PySequence_Size(seq)) != (end - begin)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"buffer[:] = value, size mismatch in assignment. "
|
||||
"Expected: %d (given: %d)", count, end - begin);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (count= begin; count < end; count++) {
|
||||
item= PySequence_GetItem(seq, count - begin);
|
||||
for (count = begin; count < end; count++) {
|
||||
item = PySequence_GetItem(seq, count - begin);
|
||||
if (item) {
|
||||
err= Buffer_ass_item(self, count, item);
|
||||
err = Buffer_ass_item(self, count, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
else {
|
||||
err= -1;
|
||||
err = -1;
|
||||
}
|
||||
if (err) {
|
||||
break;
|
||||
}
|
||||
if (err) break;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
@@ -580,8 +577,12 @@ static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value)
|
||||
|
||||
static void Buffer_dealloc(Buffer *self)
|
||||
{
|
||||
if (self->parent) Py_DECREF(self->parent);
|
||||
else MEM_freeN (self->buf.asvoid);
|
||||
if (self->parent) {
|
||||
Py_DECREF(self->parent);
|
||||
}
|
||||
else {
|
||||
MEM_freeN(self->buf.asvoid);
|
||||
}
|
||||
|
||||
MEM_freeN(self->dimensions);
|
||||
|
||||
@@ -591,19 +592,20 @@ static void Buffer_dealloc(Buffer *self)
|
||||
|
||||
static PyObject *Buffer_repr(Buffer *self)
|
||||
{
|
||||
PyObject *list= Buffer_to_list_recursive(self);
|
||||
PyObject *list = Buffer_to_list_recursive(self);
|
||||
PyObject *repr;
|
||||
const char *typestr= "UNKNOWN";
|
||||
const char *typestr;
|
||||
|
||||
switch (self->type) {
|
||||
case GL_BYTE: typestr= "GL_BYTE"; break;
|
||||
case GL_SHORT: typestr= "GL_SHORT"; break;
|
||||
case GL_INT: typestr= "GL_BYTE"; break;
|
||||
case GL_FLOAT: typestr= "GL_FLOAT"; break;
|
||||
case GL_DOUBLE: typestr= "GL_DOUBLE"; break;
|
||||
case GL_BYTE: typestr = "GL_BYTE"; break;
|
||||
case GL_SHORT: typestr = "GL_SHORT"; break;
|
||||
case GL_INT: typestr = "GL_BYTE"; break;
|
||||
case GL_FLOAT: typestr = "GL_FLOAT"; break;
|
||||
case GL_DOUBLE: typestr = "GL_DOUBLE"; break;
|
||||
default: typestr = "UNKNOWN"; break;
|
||||
}
|
||||
|
||||
repr= PyUnicode_FromFormat("Buffer(%s, %R)", typestr, list);
|
||||
repr = PyUnicode_FromFormat("Buffer(%s, %R)", typestr, list);
|
||||
Py_DECREF(list);
|
||||
|
||||
return repr;
|
||||
@@ -1296,21 +1298,20 @@ static struct PyModuleDef BGL_module_def = {
|
||||
PyObject *BPyInit_bgl(void)
|
||||
{
|
||||
PyObject *submodule, *dict, *item;
|
||||
submodule= PyModule_Create(&BGL_module_def);
|
||||
dict= PyModule_GetDict(submodule);
|
||||
|
||||
submodule = PyModule_Create(&BGL_module_def);
|
||||
dict = PyModule_GetDict(submodule);
|
||||
|
||||
if (PyType_Ready(&BGL_bufferType) < 0)
|
||||
return NULL; /* should never happen */
|
||||
|
||||
|
||||
PyModule_AddObject(submodule, "Buffer", (PyObject *)&BGL_bufferType);
|
||||
Py_INCREF((PyObject *)&BGL_bufferType);
|
||||
|
||||
#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, item=PyLong_FromLong((int)x)); Py_DECREF(item)
|
||||
#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, item = PyLong_FromLong((int)x)); Py_DECREF(item)
|
||||
|
||||
/* So, for example:
|
||||
* EXPP_ADDCONST(GL_CURRENT_BIT) becomes
|
||||
* PyDict_SetItemString(dict, "GL_CURRENT_BIT", item=PyLong_FromLong(GL_CURRENT_BIT)); Py_DECREF(item) */
|
||||
* PyDict_SetItemString(dict, "GL_CURRENT_BIT", item = PyLong_FromLong(GL_CURRENT_BIT)); Py_DECREF(item) */
|
||||
|
||||
EXPP_ADDCONST(GL_CURRENT_BIT);
|
||||
EXPP_ADDCONST(GL_POINT_BIT);
|
||||
@@ -1795,4 +1796,3 @@ PyObject *BPyInit_bgl(void)
|
||||
|
||||
return submodule;
|
||||
}
|
||||
|
||||
|
@@ -44,10 +44,10 @@ PyObject *BPyInit_bgl(void);
|
||||
/*@ Create a buffer object */
|
||||
/*@ dimensions is an array of ndimensions integers representing the size of each dimension */
|
||||
/*@ initbuffer if not NULL holds a contiguous buffer with the correct format from which the buffer will be initialized */
|
||||
struct _Buffer *BGL_MakeBuffer( int type, int ndimensions, int *dimensions, void *initbuffer );
|
||||
struct _Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuffer);
|
||||
/*@ Return the size of buffer element, type must be one of GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE */
|
||||
/*@ returns -1 otherwise */
|
||||
int BGL_typeSize( int type );
|
||||
int BGL_typeSize(int type);
|
||||
|
||||
/*@ Buffer Object */
|
||||
/*@ For Python access to OpenGL functions requiring a pointer. */
|
||||
@@ -312,23 +312,23 @@ extern PyTypeObject BGL_bufferType;
|
||||
#define ret_ret_void return Py_INCREF(Py_None), Py_None
|
||||
|
||||
#define ret_def_GLint int ret_int
|
||||
#define ret_set_GLint ret_int=
|
||||
#define ret_set_GLint ret_int =
|
||||
#define ret_ret_GLint return PyLong_FromLong(ret_int)
|
||||
|
||||
#define ret_def_GLuint unsigned int ret_uint
|
||||
#define ret_set_GLuint ret_uint=
|
||||
#define ret_set_GLuint ret_uint =
|
||||
#define ret_ret_GLuint return PyLong_FromLong((long) ret_uint)
|
||||
|
||||
#define ret_def_GLenum unsigned int ret_uint
|
||||
#define ret_set_GLenum ret_uint=
|
||||
#define ret_set_GLenum ret_uint =
|
||||
#define ret_ret_GLenum return PyLong_FromLong((long) ret_uint)
|
||||
|
||||
#define ret_def_GLboolean unsigned char ret_bool
|
||||
#define ret_set_GLboolean ret_bool=
|
||||
#define ret_set_GLboolean ret_bool =
|
||||
#define ret_ret_GLboolean return PyLong_FromLong((long) ret_bool)
|
||||
|
||||
#define ret_def_GLstring const unsigned char *ret_str;
|
||||
#define ret_set_GLstring ret_str=
|
||||
#define ret_set_GLstring ret_str =
|
||||
|
||||
#define ret_ret_GLstring \
|
||||
if (ret_str) { \
|
||||
|
@@ -182,7 +182,7 @@ static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args)
|
||||
|
||||
BLF_width_and_height(fontid, text, &r_width, &r_height);
|
||||
|
||||
ret= PyTuple_New(2);
|
||||
ret = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(r_width));
|
||||
PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(r_height));
|
||||
return ret;
|
||||
@@ -356,7 +356,7 @@ PyDoc_STRVAR(py_blf_load_doc,
|
||||
);
|
||||
static PyObject *py_blf_load(PyObject *UNUSED(self), PyObject *args)
|
||||
{
|
||||
char* filename;
|
||||
char *filename;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:blf.load", &filename))
|
||||
return NULL;
|
||||
@@ -374,7 +374,7 @@ PyDoc_STRVAR(py_blf_unload_doc,
|
||||
);
|
||||
static PyObject *py_blf_unload(PyObject *UNUSED(self), PyObject *args)
|
||||
{
|
||||
char* filename;
|
||||
char *filename;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:blf.unload", &filename))
|
||||
return NULL;
|
||||
|
@@ -101,7 +101,7 @@ void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
|
||||
PyObject *bpy_text_import(Text *text)
|
||||
{
|
||||
char *buf = NULL;
|
||||
char modulename[MAX_ID_NAME+2];
|
||||
char modulename[MAX_ID_NAME + 2];
|
||||
int len;
|
||||
|
||||
if (!text->compiled) {
|
||||
|
@@ -74,21 +74,21 @@ static PyObject *idprop_py_from_idp_int(IDProperty *prop)
|
||||
|
||||
static PyObject *idprop_py_from_idp_float(IDProperty *prop)
|
||||
{
|
||||
return PyFloat_FromDouble((double)(*(float*)(&prop->data.val)));
|
||||
return PyFloat_FromDouble((double)(*(float *)(&prop->data.val)));
|
||||
}
|
||||
|
||||
static PyObject *idprop_py_from_idp_double(IDProperty *prop)
|
||||
{
|
||||
return PyFloat_FromDouble((*(double*)(&prop->data.val)));
|
||||
return PyFloat_FromDouble((*(double *)(&prop->data.val)));
|
||||
}
|
||||
|
||||
static PyObject *idprop_py_from_idp_group(ID *id, IDProperty *prop, IDProperty *parent)
|
||||
{
|
||||
BPy_IDProperty *group= PyObject_New(BPy_IDProperty, &BPy_IDGroup_Type);
|
||||
BPy_IDProperty *group = PyObject_New(BPy_IDProperty, &BPy_IDGroup_Type);
|
||||
group->id = id;
|
||||
group->prop = prop;
|
||||
group->parent = parent; /* can be NULL */
|
||||
return (PyObject*) group;
|
||||
return (PyObject*)group;
|
||||
}
|
||||
|
||||
static PyObject *idprop_py_from_idp_array(ID *id, IDProperty *prop)
|
||||
@@ -96,13 +96,13 @@ static PyObject *idprop_py_from_idp_array(ID *id, IDProperty *prop)
|
||||
BPy_IDProperty *array = PyObject_New(BPy_IDProperty, &BPy_IDArray_Type);
|
||||
array->id = id;
|
||||
array->prop = prop;
|
||||
return (PyObject*) array;
|
||||
return (PyObject*)array;
|
||||
}
|
||||
|
||||
static PyObject *idprop_py_from_idp_idparray(ID *id, IDProperty *prop)
|
||||
{
|
||||
PyObject *seq = PyList_New(prop->len), *wrap;
|
||||
IDProperty *array= IDP_IDPArray(prop);
|
||||
IDProperty *array = IDP_IDPArray(prop);
|
||||
int i;
|
||||
|
||||
if (!seq) {
|
||||
@@ -112,8 +112,8 @@ static PyObject *idprop_py_from_idp_idparray(ID *id, IDProperty *prop)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<prop->len; i++) {
|
||||
wrap= BPy_IDGroup_WrapData(id, array++, prop);
|
||||
for (i = 0; i < prop->len; i++) {
|
||||
wrap = BPy_IDGroup_WrapData(id, array++, prop);
|
||||
|
||||
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
|
||||
return NULL;
|
||||
@@ -134,28 +134,20 @@ static Py_hash_t BPy_IDGroup_hash(BPy_IDProperty *self)
|
||||
|
||||
static PyObject *BPy_IDGroup_repr(BPy_IDProperty *self)
|
||||
{
|
||||
return PyUnicode_FromFormat( "<bpy id property from \"%s\">", self->id->name);
|
||||
return PyUnicode_FromFormat("<bpy id property from \"%s\">", self->id->name);
|
||||
}
|
||||
|
||||
PyObject *BPy_IDGroup_WrapData(ID *id, IDProperty *prop, IDProperty *parent)
|
||||
{
|
||||
switch (prop->type) {
|
||||
case IDP_STRING:
|
||||
return idprop_py_from_idp_string(prop);
|
||||
case IDP_INT:
|
||||
return idprop_py_from_idp_int(prop);
|
||||
case IDP_FLOAT:
|
||||
return idprop_py_from_idp_float(prop);
|
||||
case IDP_DOUBLE:
|
||||
return idprop_py_from_idp_double(prop);
|
||||
case IDP_GROUP:
|
||||
return idprop_py_from_idp_group(id, prop, parent);
|
||||
case IDP_ARRAY:
|
||||
return idprop_py_from_idp_array(id, prop);
|
||||
case IDP_IDPARRAY: /* this could be better a internal type */
|
||||
return idprop_py_from_idp_idparray(id, prop);
|
||||
default:
|
||||
Py_RETURN_NONE;
|
||||
case IDP_STRING: return idprop_py_from_idp_string(prop);
|
||||
case IDP_INT: return idprop_py_from_idp_int(prop);
|
||||
case IDP_FLOAT: return idprop_py_from_idp_float(prop);
|
||||
case IDP_DOUBLE: return idprop_py_from_idp_double(prop);
|
||||
case IDP_GROUP: return idprop_py_from_idp_group(id, prop, parent);
|
||||
case IDP_ARRAY: return idprop_py_from_idp_array(id, prop);
|
||||
case IDP_IDPARRAY: return idprop_py_from_idp_idparray(id, prop); /* this could be better a internal type */
|
||||
default: Py_RETURN_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,10 +166,10 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
|
||||
#ifdef USE_STRING_COERCE
|
||||
{
|
||||
int alloc_len;
|
||||
PyObject *value_coerce= NULL;
|
||||
PyObject *value_coerce = NULL;
|
||||
|
||||
st= (char *)PyC_UnicodeAsByte(value, &value_coerce);
|
||||
alloc_len= strlen(st) + 1;
|
||||
st = (char *)PyC_UnicodeAsByte(value, &value_coerce);
|
||||
alloc_len = strlen(st) + 1;
|
||||
|
||||
st = _PyUnicode_AsString(value);
|
||||
IDP_ResizeArray(prop, alloc_len);
|
||||
@@ -195,8 +187,8 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
|
||||
|
||||
case IDP_INT:
|
||||
{
|
||||
int ivalue= PyLong_AsSsize_t(value);
|
||||
if (ivalue==-1 && PyErr_Occurred()) {
|
||||
int ivalue = PyLong_AsSsize_t(value);
|
||||
if (ivalue == -1 && PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected an int type");
|
||||
return -1;
|
||||
}
|
||||
@@ -205,22 +197,22 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
|
||||
}
|
||||
case IDP_FLOAT:
|
||||
{
|
||||
float fvalue= (float)PyFloat_AsDouble(value);
|
||||
if (fvalue==-1 && PyErr_Occurred()) {
|
||||
float fvalue = (float)PyFloat_AsDouble(value);
|
||||
if (fvalue == -1 && PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a float");
|
||||
return -1;
|
||||
}
|
||||
*(float*)&self->prop->data.val = fvalue;
|
||||
*(float *)&self->prop->data.val = fvalue;
|
||||
break;
|
||||
}
|
||||
case IDP_DOUBLE:
|
||||
{
|
||||
double dvalue= PyFloat_AsDouble(value);
|
||||
if (dvalue==-1 && PyErr_Occurred()) {
|
||||
double dvalue = PyFloat_AsDouble(value);
|
||||
if (dvalue == -1 && PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a float");
|
||||
return -1;
|
||||
}
|
||||
*(double*)&self->prop->data.val = dvalue;
|
||||
*(double *)&self->prop->data.val = dvalue;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -289,16 +281,16 @@ static PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
name= _PyUnicode_AsString(item);
|
||||
name = _PyUnicode_AsString(item);
|
||||
|
||||
if (name == NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "only strings are allowed as keys of ID properties");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idprop= IDP_GetPropertyFromGroup(self->prop, name);
|
||||
idprop = IDP_GetPropertyFromGroup(self->prop, name);
|
||||
|
||||
if (idprop==NULL) {
|
||||
if (idprop == NULL) {
|
||||
PyErr_SetString(PyExc_KeyError, "key not in subgroup dict");
|
||||
return NULL;
|
||||
}
|
||||
@@ -306,21 +298,21 @@ static PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
|
||||
return BPy_IDGroup_WrapData(self->id, idprop, self->prop);
|
||||
}
|
||||
|
||||
/*returns NULL on success, error string on failure*/
|
||||
/* returns NULL on success, error string on failure */
|
||||
static int idp_sequence_type(PyObject *seq)
|
||||
{
|
||||
PyObject *item;
|
||||
int type= IDP_INT;
|
||||
int type = IDP_INT;
|
||||
|
||||
Py_ssize_t i, len = PySequence_Size(seq);
|
||||
for (i=0; i < len; i++) {
|
||||
for (i = 0; i < len; i++) {
|
||||
item = PySequence_GetItem(seq, i);
|
||||
if (PyFloat_Check(item)) {
|
||||
if (type == IDP_IDPARRAY) { /* mixed dict/int */
|
||||
Py_DECREF(item);
|
||||
return -1;
|
||||
}
|
||||
type= IDP_DOUBLE;
|
||||
type = IDP_DOUBLE;
|
||||
}
|
||||
else if (PyLong_Check(item)) {
|
||||
if (type == IDP_IDPARRAY) { /* mixed dict/int */
|
||||
@@ -333,7 +325,7 @@ static int idp_sequence_type(PyObject *seq)
|
||||
Py_DECREF(item);
|
||||
return -1;
|
||||
}
|
||||
type= IDP_IDPARRAY;
|
||||
type = IDP_IDPARRAY;
|
||||
}
|
||||
else {
|
||||
Py_XDECREF(item);
|
||||
@@ -353,7 +345,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
|
||||
IDProperty *prop = NULL;
|
||||
IDPropertyTemplate val = {0};
|
||||
|
||||
const char *name= "";
|
||||
const char *name = "";
|
||||
|
||||
if (name_obj) {
|
||||
Py_ssize_t name_size;
|
||||
@@ -373,7 +365,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
|
||||
}
|
||||
else if (PyUnicode_Check(ob)) {
|
||||
#ifdef USE_STRING_COERCE
|
||||
PyObject *value_coerce= NULL;
|
||||
PyObject *value_coerce = NULL;
|
||||
val.string.str = (char *)PyC_UnicodeAsByte(ob, &value_coerce);
|
||||
val.string.subtype = IDP_STRING_SUB_UTF8;
|
||||
prop = IDP_New(IDP_STRING, &val, name);
|
||||
@@ -384,19 +376,19 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
|
||||
#endif
|
||||
}
|
||||
else if (PyBytes_Check(ob)) {
|
||||
val.string.str= PyBytes_AS_STRING(ob);
|
||||
val.string.len= PyBytes_GET_SIZE(ob);
|
||||
val.string.subtype= IDP_STRING_SUB_BYTE;
|
||||
val.string.str = PyBytes_AS_STRING(ob);
|
||||
val.string.len = PyBytes_GET_SIZE(ob);
|
||||
val.string.subtype = IDP_STRING_SUB_BYTE;
|
||||
|
||||
prop = IDP_New(IDP_STRING, &val, name);
|
||||
//prop = IDP_NewString(PyBytes_AS_STRING(ob), name, PyBytes_GET_SIZE(ob));
|
||||
//prop->subtype= IDP_STRING_SUB_BYTE;
|
||||
//prop->subtype = IDP_STRING_SUB_BYTE;
|
||||
}
|
||||
else if (PySequence_Check(ob)) {
|
||||
PyObject *item;
|
||||
int i;
|
||||
|
||||
if ((val.array.type= idp_sequence_type(ob)) == -1)
|
||||
if ((val.array.type = idp_sequence_type(ob)) == -1)
|
||||
return "only floats, ints and dicts are allowed in ID property arrays";
|
||||
|
||||
/* validate sequence and derive type.
|
||||
@@ -406,34 +398,34 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
|
||||
val.array.len = PySequence_Size(ob);
|
||||
|
||||
switch (val.array.type) {
|
||||
case IDP_DOUBLE:
|
||||
prop = IDP_New(IDP_ARRAY, &val, name);
|
||||
for (i=0; i<val.array.len; i++) {
|
||||
item = PySequence_GetItem(ob, i);
|
||||
((double*)IDP_Array(prop))[i] = (float)PyFloat_AsDouble(item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
break;
|
||||
case IDP_INT:
|
||||
prop = IDP_New(IDP_ARRAY, &val, name);
|
||||
for (i=0; i<val.array.len; i++) {
|
||||
item = PySequence_GetItem(ob, i);
|
||||
((int*)IDP_Array(prop))[i] = (int)PyLong_AsSsize_t(item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
break;
|
||||
case IDP_IDPARRAY:
|
||||
prop= IDP_NewIDPArray(name);
|
||||
for (i=0; i<val.array.len; i++) {
|
||||
const char *error;
|
||||
item = PySequence_GetItem(ob, i);
|
||||
error= BPy_IDProperty_Map_ValidateAndCreate(NULL, prop, item);
|
||||
Py_DECREF(item);
|
||||
case IDP_DOUBLE:
|
||||
prop = IDP_New(IDP_ARRAY, &val, name);
|
||||
for (i = 0; i < val.array.len; i++) {
|
||||
item = PySequence_GetItem(ob, i);
|
||||
((double *)IDP_Array(prop))[i] = (float)PyFloat_AsDouble(item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
break;
|
||||
case IDP_INT:
|
||||
prop = IDP_New(IDP_ARRAY, &val, name);
|
||||
for (i = 0; i < val.array.len; i++) {
|
||||
item = PySequence_GetItem(ob, i);
|
||||
((int *)IDP_Array(prop))[i] = (int)PyLong_AsSsize_t(item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
break;
|
||||
case IDP_IDPARRAY:
|
||||
prop = IDP_NewIDPArray(name);
|
||||
for (i = 0; i < val.array.len; i++) {
|
||||
const char *error;
|
||||
item = PySequence_GetItem(ob, i);
|
||||
error = BPy_IDProperty_Map_ValidateAndCreate(NULL, prop, item);
|
||||
Py_DECREF(item);
|
||||
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
break;
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (PyMapping_Check(ob)) {
|
||||
@@ -447,7 +439,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
|
||||
* we can delete it easily enough.*/
|
||||
prop = IDP_New(IDP_GROUP, &val, name);
|
||||
len = PyMapping_Length(ob);
|
||||
for (i=0; i<len; i++) {
|
||||
for (i = 0; i < len; i++) {
|
||||
key = PySequence_GetItem(keys, i);
|
||||
pval = PySequence_GetItem(vals, i);
|
||||
if (!PyUnicode_Check(key)) {
|
||||
@@ -476,7 +468,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
|
||||
}
|
||||
else return "invalid property value";
|
||||
|
||||
if (group->type==IDP_IDPARRAY) {
|
||||
if (group->type == IDP_IDPARRAY) {
|
||||
IDP_AppendArray(group, prop);
|
||||
// IDP_FreeProperty(item); // IDP_AppendArray does a shallow copy (memcpy), only free memory
|
||||
MEM_freeN(prop);
|
||||
@@ -518,7 +510,7 @@ int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val)
|
||||
|
||||
err = BPy_IDProperty_Map_ValidateAndCreate(key, prop, val);
|
||||
if (err) {
|
||||
PyErr_SetString(PyExc_KeyError, err );
|
||||
PyErr_SetString(PyExc_KeyError, err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -538,107 +530,107 @@ static PyObject *BPy_IDGroup_iter(BPy_IDProperty *self)
|
||||
iter->mode = IDPROP_ITER_KEYS;
|
||||
iter->cur = self->prop->data.group.first;
|
||||
Py_XINCREF(iter);
|
||||
return (PyObject*) iter;
|
||||
return (PyObject*)iter;
|
||||
}
|
||||
|
||||
/* for simple, non nested types this is the same as BPy_IDGroup_WrapData */
|
||||
static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
|
||||
{
|
||||
switch (prop->type) {
|
||||
case IDP_STRING:
|
||||
return idprop_py_from_idp_string(prop);
|
||||
case IDP_INT:
|
||||
return idprop_py_from_idp_int(prop);
|
||||
case IDP_FLOAT:
|
||||
return idprop_py_from_idp_float(prop);
|
||||
case IDP_DOUBLE:
|
||||
return idprop_py_from_idp_double(prop);
|
||||
case IDP_ARRAY:
|
||||
{
|
||||
PyObject *seq = PyList_New(prop->len);
|
||||
int i;
|
||||
|
||||
if (!seq) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"%s: IDP_ARRAY: PyList_New(%d) failed",
|
||||
__func__, prop->len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (prop->subtype) {
|
||||
case IDP_FLOAT:
|
||||
{
|
||||
float *array= (float*)IDP_Array(prop);
|
||||
for (i=0; i<prop->len; i++) {
|
||||
PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IDP_DOUBLE:
|
||||
{
|
||||
double *array= (double*)IDP_Array(prop);
|
||||
for (i=0; i<prop->len; i++) {
|
||||
PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IDP_STRING:
|
||||
return idprop_py_from_idp_string(prop);
|
||||
case IDP_INT:
|
||||
return idprop_py_from_idp_int(prop);
|
||||
case IDP_FLOAT:
|
||||
return idprop_py_from_idp_float(prop);
|
||||
case IDP_DOUBLE:
|
||||
return idprop_py_from_idp_double(prop);
|
||||
case IDP_ARRAY:
|
||||
{
|
||||
int *array= (int*)IDP_Array(prop);
|
||||
for (i=0; i<prop->len; i++) {
|
||||
PyList_SET_ITEM(seq, i, PyLong_FromLong(array[i]));
|
||||
PyObject *seq = PyList_New(prop->len);
|
||||
int i;
|
||||
|
||||
if (!seq) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"%s: IDP_ARRAY: PyList_New(%d) failed",
|
||||
__func__, prop->len);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"%s: invalid/corrupt array type '%d'!",
|
||||
__func__, prop->subtype);
|
||||
Py_DECREF(seq);
|
||||
return NULL;
|
||||
|
||||
switch (prop->subtype) {
|
||||
case IDP_FLOAT:
|
||||
{
|
||||
float *array = (float *)IDP_Array(prop);
|
||||
for (i = 0; i < prop->len; i++) {
|
||||
PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IDP_DOUBLE:
|
||||
{
|
||||
double *array = (double *)IDP_Array(prop);
|
||||
for (i = 0; i < prop->len; i++) {
|
||||
PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IDP_INT:
|
||||
{
|
||||
int *array = (int *)IDP_Array(prop);
|
||||
for (i = 0; i < prop->len; i++) {
|
||||
PyList_SET_ITEM(seq, i, PyLong_FromLong(array[i]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"%s: invalid/corrupt array type '%d'!",
|
||||
__func__, prop->subtype);
|
||||
Py_DECREF(seq);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return seq;
|
||||
}
|
||||
case IDP_IDPARRAY:
|
||||
{
|
||||
PyObject *seq = PyList_New(prop->len), *wrap;
|
||||
IDProperty *array = IDP_IDPArray(prop);
|
||||
int i;
|
||||
|
||||
return seq;
|
||||
}
|
||||
case IDP_IDPARRAY:
|
||||
{
|
||||
PyObject *seq = PyList_New(prop->len), *wrap;
|
||||
IDProperty *array= IDP_IDPArray(prop);
|
||||
int i;
|
||||
|
||||
if (!seq) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"%s: IDP_IDPARRAY: PyList_New(%d) failed",
|
||||
__func__, prop->len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<prop->len; i++) {
|
||||
wrap= BPy_IDGroup_MapDataToPy(array++);
|
||||
|
||||
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
|
||||
if (!seq) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"%s: IDP_IDPARRAY: PyList_New(%d) failed",
|
||||
__func__, prop->len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyList_SET_ITEM(seq, i, wrap);
|
||||
for (i = 0; i < prop->len; i++) {
|
||||
wrap = BPy_IDGroup_MapDataToPy(array++);
|
||||
|
||||
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
|
||||
return NULL;
|
||||
|
||||
PyList_SET_ITEM(seq, i, wrap);
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
case IDP_GROUP:
|
||||
{
|
||||
PyObject *dict = PyDict_New(), *wrap;
|
||||
IDProperty *loop;
|
||||
case IDP_GROUP:
|
||||
{
|
||||
PyObject *dict = PyDict_New(), *wrap;
|
||||
IDProperty *loop;
|
||||
|
||||
for (loop=prop->data.group.first; loop; loop=loop->next) {
|
||||
wrap = BPy_IDGroup_MapDataToPy(loop);
|
||||
for (loop = prop->data.group.first; loop; loop = loop->next) {
|
||||
wrap = BPy_IDGroup_MapDataToPy(loop);
|
||||
|
||||
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
|
||||
return NULL;
|
||||
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
|
||||
return NULL;
|
||||
|
||||
PyDict_SetItemString(dict, loop->name, wrap);
|
||||
Py_DECREF(wrap);
|
||||
PyDict_SetItemString(dict, loop->name, wrap);
|
||||
Py_DECREF(wrap);
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
@@ -660,7 +652,7 @@ static PyObject *BPy_IDGroup_Pop(BPy_IDProperty *self, PyObject *value)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idprop= IDP_GetPropertyFromGroup(self->prop, name);
|
||||
idprop = IDP_GetPropertyFromGroup(self->prop, name);
|
||||
|
||||
if (idprop) {
|
||||
pyform = BPy_IDGroup_MapDataToPy(idprop);
|
||||
@@ -687,7 +679,7 @@ static PyObject *BPy_IDGroup_IterItems(BPy_IDProperty *self)
|
||||
iter->mode = IDPROP_ITER_ITEMS;
|
||||
iter->cur = self->prop->data.group.first;
|
||||
Py_XINCREF(iter);
|
||||
return (PyObject*) iter;
|
||||
return (PyObject*)iter;
|
||||
}
|
||||
|
||||
/* utility function */
|
||||
@@ -698,7 +690,7 @@ static void BPy_IDGroup_CorrectListLen(IDProperty *prop, PyObject *seq, int len,
|
||||
printf("%s: ID Property Error found and corrected!\n", func);
|
||||
|
||||
/*fill rest of list with valid references to None*/
|
||||
for (j=len; j<prop->len; j++) {
|
||||
for (j = len; j < prop->len; j++) {
|
||||
Py_INCREF(Py_None);
|
||||
PyList_SET_ITEM(seq, j, Py_None);
|
||||
}
|
||||
@@ -713,11 +705,13 @@ PyObject *BPy_Wrap_GetKeys(IDProperty *prop)
|
||||
IDProperty *loop;
|
||||
int i;
|
||||
|
||||
for (i=0, loop=prop->data.group.first; loop && (i < prop->len); loop=loop->next, i++)
|
||||
for (i = 0, loop = prop->data.group.first; loop && (i < prop->len); loop = loop->next, i++)
|
||||
PyList_SET_ITEM(list, i, PyUnicode_FromString(loop->name));
|
||||
|
||||
/* if the id prop is corrupt, count the remaining */
|
||||
for (; loop; loop=loop->next, i++) {}
|
||||
for ( ; loop; loop = loop->next, i++) {
|
||||
/* pass */
|
||||
}
|
||||
|
||||
if (i != prop->len) { /* if the loop didnt finish, we know the length is wrong */
|
||||
BPy_IDGroup_CorrectListLen(prop, list, i, __func__);
|
||||
@@ -735,7 +729,7 @@ PyObject *BPy_Wrap_GetValues(ID *id, IDProperty *prop)
|
||||
IDProperty *loop;
|
||||
int i;
|
||||
|
||||
for (i=0, loop=prop->data.group.first; loop; loop=loop->next, i++) {
|
||||
for (i = 0, loop = prop->data.group.first; loop; loop = loop->next, i++) {
|
||||
PyList_SET_ITEM(list, i, BPy_IDGroup_WrapData(id, loop, prop));
|
||||
}
|
||||
|
||||
@@ -755,8 +749,8 @@ PyObject *BPy_Wrap_GetItems(ID *id, IDProperty *prop)
|
||||
IDProperty *loop;
|
||||
int i;
|
||||
|
||||
for (i=0, loop=prop->data.group.first; loop; loop=loop->next, i++) {
|
||||
PyObject *item= PyTuple_New(2);
|
||||
for (i = 0, loop = prop->data.group.first; loop; loop = loop->next, i++) {
|
||||
PyObject *item = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(item, 0, PyUnicode_FromString(loop->name));
|
||||
PyTuple_SET_ITEM(item, 1, BPy_IDGroup_WrapData(id, loop, prop));
|
||||
PyList_SET_ITEM(seq, i, item);
|
||||
@@ -805,7 +799,7 @@ static int BPy_IDGroup_Contains(BPy_IDProperty *self, PyObject *value)
|
||||
static PyObject *BPy_IDGroup_Update(BPy_IDProperty *self, PyObject *value)
|
||||
{
|
||||
PyObject *pkey, *pval;
|
||||
Py_ssize_t i=0;
|
||||
Py_ssize_t i = 0;
|
||||
|
||||
if (!PyDict_Check(value)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
@@ -829,18 +823,18 @@ static PyObject *BPy_IDGroup_to_dict(BPy_IDProperty *self)
|
||||
|
||||
|
||||
/* Matches python dict.get(key, [default]) */
|
||||
static PyObject* BPy_IDGroup_Get(BPy_IDProperty *self, PyObject *args)
|
||||
static PyObject *BPy_IDGroup_Get(BPy_IDProperty *self, PyObject *args)
|
||||
{
|
||||
IDProperty *idprop;
|
||||
char *key;
|
||||
PyObject* def = Py_None;
|
||||
PyObject *def = Py_None;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s|O:get", &key, &def))
|
||||
return NULL;
|
||||
|
||||
idprop= IDP_GetPropertyFromGroup(self->prop, key);
|
||||
idprop = IDP_GetPropertyFromGroup(self->prop, key);
|
||||
if (idprop) {
|
||||
PyObject* pyobj = BPy_IDGroup_WrapData(self->id, idprop, self->prop);
|
||||
PyObject *pyobj = BPy_IDGroup_WrapData(self->id, idprop, self->prop);
|
||||
if (pyobj)
|
||||
return pyobj;
|
||||
}
|
||||
@@ -955,17 +949,17 @@ static PyTypeObject *idp_array_py_type(BPy_IDArray *self, short *is_double)
|
||||
{
|
||||
switch (self->prop->subtype) {
|
||||
case IDP_FLOAT:
|
||||
*is_double= 0;
|
||||
*is_double = 0;
|
||||
return &PyFloat_Type;
|
||||
case IDP_DOUBLE:
|
||||
*is_double= 1;
|
||||
*is_double = 1;
|
||||
return &PyFloat_Type;
|
||||
case IDP_INT:
|
||||
*is_double= 0;
|
||||
*is_double = 0;
|
||||
return &PyLong_Type;
|
||||
}
|
||||
|
||||
*is_double= 0;
|
||||
*is_double = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -977,12 +971,9 @@ static PyObject *BPy_IDArray_repr(BPy_IDArray *self)
|
||||
static PyObject *BPy_IDArray_GetType(BPy_IDArray *self)
|
||||
{
|
||||
switch (self->prop->subtype) {
|
||||
case IDP_FLOAT:
|
||||
return PyUnicode_FromString("f");
|
||||
case IDP_DOUBLE:
|
||||
return PyUnicode_FromString("d");
|
||||
case IDP_INT:
|
||||
return PyUnicode_FromString("i");
|
||||
case IDP_FLOAT: return PyUnicode_FromString("f");
|
||||
case IDP_DOUBLE: return PyUnicode_FromString("d");
|
||||
case IDP_INT: return PyUnicode_FromString("i");
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
@@ -1023,11 +1014,11 @@ static PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, int index)
|
||||
|
||||
switch (self->prop->subtype) {
|
||||
case IDP_FLOAT:
|
||||
return PyFloat_FromDouble(((float*)IDP_Array(self->prop))[index]);
|
||||
return PyFloat_FromDouble(((float *)IDP_Array(self->prop))[index]);
|
||||
case IDP_DOUBLE:
|
||||
return PyFloat_FromDouble(((double*)IDP_Array(self->prop))[index]);
|
||||
return PyFloat_FromDouble(((double *)IDP_Array(self->prop))[index]);
|
||||
case IDP_INT:
|
||||
return PyLong_FromLong((long)((int*)IDP_Array(self->prop))[index]);
|
||||
return PyLong_FromLong((long)((int *)IDP_Array(self->prop))[index]);
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
@@ -1050,29 +1041,29 @@ static int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *value)
|
||||
|
||||
switch (self->prop->subtype) {
|
||||
case IDP_FLOAT:
|
||||
f= (float)PyFloat_AsDouble(value);
|
||||
if (f==-1 && PyErr_Occurred()) {
|
||||
f = (float)PyFloat_AsDouble(value);
|
||||
if (f == -1 && PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a float");
|
||||
return -1;
|
||||
}
|
||||
((float*)IDP_Array(self->prop))[index] = f;
|
||||
((float *)IDP_Array(self->prop))[index] = f;
|
||||
break;
|
||||
case IDP_DOUBLE:
|
||||
d= PyFloat_AsDouble(value);
|
||||
if (d==-1 && PyErr_Occurred()) {
|
||||
d = PyFloat_AsDouble(value);
|
||||
if (d == -1 && PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a float");
|
||||
return -1;
|
||||
}
|
||||
((double*)IDP_Array(self->prop))[index] = d;
|
||||
((double *)IDP_Array(self->prop))[index] = d;
|
||||
break;
|
||||
case IDP_INT:
|
||||
i= PyLong_AsSsize_t(value);
|
||||
if (i==-1 && PyErr_Occurred()) {
|
||||
i = PyLong_AsSsize_t(value);
|
||||
if (i == -1 && PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected an int type");
|
||||
return -1;
|
||||
}
|
||||
|
||||
((int*)IDP_Array(self->prop))[index] = i;
|
||||
((int *)IDP_Array(self->prop))[index] = i;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
@@ -1097,21 +1088,21 @@ static PySequenceMethods BPy_IDArray_Seq = {
|
||||
/* sequence slice (get): idparr[a:b] */
|
||||
static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
|
||||
{
|
||||
IDProperty *prop= self->prop;
|
||||
IDProperty *prop = self->prop;
|
||||
PyObject *tuple;
|
||||
int count;
|
||||
|
||||
CLAMP(begin, 0, prop->len);
|
||||
if (end<0) end= prop->len+end+1;
|
||||
if (end < 0) end = prop->len + end + 1;
|
||||
CLAMP(end, 0, prop->len);
|
||||
begin= MIN2(begin, end);
|
||||
begin = MIN2(begin, end);
|
||||
|
||||
tuple= PyTuple_New(end - begin);
|
||||
tuple = PyTuple_New(end - begin);
|
||||
|
||||
switch (prop->subtype) {
|
||||
case IDP_FLOAT:
|
||||
{
|
||||
float *array= (float*)IDP_Array(prop);
|
||||
float *array = (float *)IDP_Array(prop);
|
||||
for (count = begin; count < end; count++) {
|
||||
PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(array[count]));
|
||||
}
|
||||
@@ -1119,7 +1110,7 @@ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
|
||||
}
|
||||
case IDP_DOUBLE:
|
||||
{
|
||||
double *array= (double*)IDP_Array(prop);
|
||||
double *array = (double *)IDP_Array(prop);
|
||||
for (count = begin; count < end; count++) {
|
||||
PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(array[count]));
|
||||
}
|
||||
@@ -1127,7 +1118,7 @@ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
|
||||
}
|
||||
case IDP_INT:
|
||||
{
|
||||
int *array= (int*)IDP_Array(prop);
|
||||
int *array = (int *)IDP_Array(prop);
|
||||
for (count = begin; count < end; count++) {
|
||||
PyTuple_SET_ITEM(tuple, count - begin, PyLong_FromLong(array[count]));
|
||||
}
|
||||
@@ -1140,10 +1131,10 @@ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
|
||||
/* sequence slice (set): idparr[a:b] = value */
|
||||
static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject *seq)
|
||||
{
|
||||
IDProperty *prop= self->prop;
|
||||
short is_double= 0;
|
||||
const PyTypeObject *py_type= idp_array_py_type(self, &is_double);
|
||||
const size_t elem_size= is_double ? sizeof(double) : sizeof(float);
|
||||
IDProperty *prop = self->prop;
|
||||
short is_double = 0;
|
||||
const PyTypeObject *py_type = idp_array_py_type(self, &is_double);
|
||||
const size_t elem_size = is_double ? sizeof(double) : sizeof(float);
|
||||
size_t alloc_len;
|
||||
size_t size;
|
||||
void *vec;
|
||||
@@ -1153,9 +1144,9 @@ static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject
|
||||
begin = MIN2(begin, end);
|
||||
|
||||
size = (end - begin);
|
||||
alloc_len= size * elem_size;
|
||||
alloc_len = size * elem_size;
|
||||
|
||||
vec= MEM_mallocN(alloc_len, "array assignment"); /* NOTE: we count on int/float being the same size here */
|
||||
vec = MEM_mallocN(alloc_len, "array assignment"); /* NOTE: we count on int/float being the same size here */
|
||||
if (PyC_AsArray(vec, seq, size, py_type, is_double, "slice assignment: ") == -1) {
|
||||
MEM_freeN(vec);
|
||||
return -1;
|
||||
@@ -1167,7 +1158,7 @@ static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *BPy_IDArray_subscript(BPy_IDArray* self, PyObject* item)
|
||||
static PyObject *BPy_IDArray_subscript(BPy_IDArray *self, PyObject *item)
|
||||
{
|
||||
if (PyIndex_Check(item)) {
|
||||
Py_ssize_t i;
|
||||
@@ -1203,7 +1194,7 @@ static PyObject *BPy_IDArray_subscript(BPy_IDArray* self, PyObject* item)
|
||||
}
|
||||
}
|
||||
|
||||
static int BPy_IDArray_ass_subscript(BPy_IDArray* self, PyObject* item, PyObject* value)
|
||||
static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject *value)
|
||||
{
|
||||
if (PyIndex_Check(item)) {
|
||||
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
|
||||
@@ -1331,12 +1322,14 @@ static PyObject *IDGroup_Iter_repr(BPy_IDGroup_Iter *self)
|
||||
|
||||
static PyObject *BPy_Group_Iter_Next(BPy_IDGroup_Iter *self)
|
||||
{
|
||||
IDProperty *cur=NULL;
|
||||
PyObject *ret;
|
||||
|
||||
if (self->cur) {
|
||||
PyObject *ret;
|
||||
IDProperty *cur;
|
||||
|
||||
cur = self->cur;
|
||||
self->cur = self->cur->next;
|
||||
|
||||
if (self->mode == IDPROP_ITER_ITEMS) {
|
||||
ret = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(cur->name));
|
||||
@@ -1357,7 +1350,7 @@ PyTypeObject BPy_IDGroup_Iter_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
/* For printing, in format "<module>.<name>" */
|
||||
"Blender IDGroup_Iter", /* char *tp_name; */
|
||||
sizeof( BPy_IDGroup_Iter ), /* int tp_basicsize; */
|
||||
sizeof(BPy_IDGroup_Iter), /* int tp_basicsize; */
|
||||
0, /* tp_itemsize; For allocation */
|
||||
|
||||
/* Methods to implement standard operations */
|
||||
@@ -1367,7 +1360,7 @@ PyTypeObject BPy_IDGroup_Iter_Type = {
|
||||
NULL, /* getattrfunc tp_getattr; */
|
||||
NULL, /* setattrfunc tp_setattr; */
|
||||
NULL, /* cmpfunc tp_compare; */
|
||||
( reprfunc ) IDGroup_Iter_repr, /* reprfunc tp_repr; */
|
||||
(reprfunc) IDGroup_Iter_repr, /* reprfunc tp_repr; */
|
||||
|
||||
/* Method suites for standard classes */
|
||||
|
||||
|
@@ -67,28 +67,28 @@ int PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length,
|
||||
/* for each type */
|
||||
if (type == &PyFloat_Type) {
|
||||
if (is_double) {
|
||||
double *array_double= array;
|
||||
for (i=0; i<length; i++) {
|
||||
double *array_double = array;
|
||||
for (i = 0; i < length; i++) {
|
||||
array_double[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i));
|
||||
}
|
||||
}
|
||||
else {
|
||||
float *array_float= array;
|
||||
for (i=0; i<length; i++) {
|
||||
float *array_float = array;
|
||||
for (i = 0; i < length; i++) {
|
||||
array_float[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == &PyLong_Type) {
|
||||
/* could use is_double for 'long int' but no use now */
|
||||
int *array_int= array;
|
||||
for (i=0; i<length; i++) {
|
||||
int *array_int = array;
|
||||
for (i = 0; i < length; i++) {
|
||||
array_int[i] = PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i));
|
||||
}
|
||||
}
|
||||
else if (type == &PyBool_Type) {
|
||||
int *array_bool= array;
|
||||
for (i=0; i<length; i++) {
|
||||
int *array_bool = array;
|
||||
for (i = 0; i < length; i++) {
|
||||
array_bool[i] = (PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i)) != 0);
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ int PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length,
|
||||
void PyC_ObSpit(const char *name, PyObject *var)
|
||||
{
|
||||
fprintf(stderr, "<%s> : ", name);
|
||||
if (var==NULL) {
|
||||
if (var == NULL) {
|
||||
fprintf(stderr, "<NIL>");
|
||||
}
|
||||
else {
|
||||
@@ -156,10 +156,10 @@ void PyC_FileAndNum(const char **filename, int *lineno)
|
||||
{
|
||||
PyFrameObject *frame;
|
||||
|
||||
if (filename) *filename= NULL;
|
||||
if (filename) *filename = NULL;
|
||||
if (lineno) *lineno = -1;
|
||||
|
||||
if (!(frame= PyThreadState_GET()->frame)) {
|
||||
if (!(frame = PyThreadState_GET()->frame)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -172,16 +172,16 @@ void PyC_FileAndNum(const char **filename, int *lineno)
|
||||
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__");
|
||||
PyObject *mod_name = PyDict_GetItemString(PyEval_GetGlobals(), "__name__");
|
||||
if (mod_name) {
|
||||
PyObject *mod= PyDict_GetItem(PyImport_GetModuleDict(), mod_name);
|
||||
PyObject *mod = PyDict_GetItem(PyImport_GetModuleDict(), mod_name);
|
||||
if (mod) {
|
||||
*filename= PyModule_GetFilename(mod);
|
||||
*filename = PyModule_GetFilename(mod);
|
||||
}
|
||||
|
||||
/* unlikely, fallback */
|
||||
if (*filename == NULL) {
|
||||
*filename= _PyUnicode_AsString(mod_name);
|
||||
*filename = _PyUnicode_AsString(mod_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,13 +204,13 @@ void PyC_FileAndNum_Safe(const char **filename, int *lineno)
|
||||
PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...)
|
||||
{
|
||||
Py_ssize_t i;
|
||||
PyObject *item= o;
|
||||
PyObject *item = o;
|
||||
char *attr;
|
||||
|
||||
va_list vargs;
|
||||
|
||||
va_start(vargs, n);
|
||||
for (i=0; i<n; i++) {
|
||||
for (i = 0; i < n; i++) {
|
||||
attr = va_arg(vargs, char *);
|
||||
item = PyObject_GetAttrString(item, attr);
|
||||
|
||||
@@ -238,7 +238,7 @@ PyObject *PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *for
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
error_value_prefix= PyUnicode_FromFormatV(format, args); /* can fail and be NULL */
|
||||
error_value_prefix = PyUnicode_FromFormatV(format, args); /* can fail and be NULL */
|
||||
va_end(args);
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
@@ -271,22 +271,22 @@ PyObject *PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *for
|
||||
|
||||
PyObject *PyC_ExceptionBuffer(void)
|
||||
{
|
||||
PyObject *traceback_mod= NULL;
|
||||
PyObject *format_tb_func= NULL;
|
||||
PyObject *ret= NULL;
|
||||
PyObject *traceback_mod = NULL;
|
||||
PyObject *format_tb_func = NULL;
|
||||
PyObject *ret = NULL;
|
||||
|
||||
if (! (traceback_mod= PyImport_ImportModule("traceback")) ) {
|
||||
if (!(traceback_mod = PyImport_ImportModule("traceback"))) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
else if (! (format_tb_func= PyObject_GetAttrString(traceback_mod, "format_exc"))) {
|
||||
else if (!(format_tb_func = PyObject_GetAttrString(traceback_mod, "format_exc"))) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
ret= PyObject_CallObject(format_tb_func, NULL);
|
||||
ret = PyObject_CallObject(format_tb_func, NULL);
|
||||
|
||||
if (ret == Py_None) {
|
||||
Py_DECREF(ret);
|
||||
ret= NULL;
|
||||
ret = NULL;
|
||||
}
|
||||
|
||||
error_cleanup:
|
||||
@@ -303,8 +303,8 @@ PyObject *PyC_ExceptionBuffer(void)
|
||||
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 *string_io_mod = NULL;
|
||||
PyObject *string_io_getvalue = NULL;
|
||||
|
||||
PyObject *error_type, *error_value, *error_traceback;
|
||||
|
||||
@@ -319,13 +319,13 @@ PyObject *PyC_ExceptionBuffer(void)
|
||||
* string_io = io.StringIO()
|
||||
*/
|
||||
|
||||
if (! (string_io_mod= PyImport_ImportModule("io")) ) {
|
||||
if (!(string_io_mod = PyImport_ImportModule("io"))) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
else if (! (string_io = PyObject_CallMethod(string_io_mod, (char *)"StringIO", NULL))) {
|
||||
else if (!(string_io = PyObject_CallMethod(string_io_mod, (char *)"StringIO", NULL))) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
else if (! (string_io_getvalue= PyObject_GetAttrString(string_io, "getvalue"))) {
|
||||
else if (!(string_io_getvalue = PyObject_GetAttrString(string_io, "getvalue"))) {
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
|
||||
{
|
||||
const char *result;
|
||||
|
||||
result= _PyUnicode_AsString(py_str);
|
||||
result = _PyUnicode_AsString(py_str);
|
||||
|
||||
if (result) {
|
||||
/* 99% of the time this is enough but we better support non unicode
|
||||
@@ -387,7 +387,7 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
|
||||
if (PyBytes_Check(py_str)) {
|
||||
return PyBytes_AS_STRING(py_str);
|
||||
}
|
||||
else if ((*coerce= PyUnicode_EncodeFSDefault(py_str))) {
|
||||
else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) {
|
||||
return PyBytes_AS_STRING(*coerce);
|
||||
}
|
||||
else {
|
||||
@@ -399,7 +399,7 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
|
||||
|
||||
PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size)
|
||||
{
|
||||
PyObject *result= PyUnicode_FromStringAndSize(str, size);
|
||||
PyObject *result = PyUnicode_FromStringAndSize(str, size);
|
||||
if (result) {
|
||||
/* 99% of the time this is enough but we better support non unicode
|
||||
* chars since blender doesnt limit this */
|
||||
@@ -408,7 +408,7 @@ PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size)
|
||||
else {
|
||||
PyErr_Clear();
|
||||
/* this means paths will always be accessible once converted, on all OS's */
|
||||
result= PyUnicode_DecodeFSDefaultAndSize(str, size);
|
||||
result = PyUnicode_DecodeFSDefaultAndSize(str, size);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -432,8 +432,8 @@ PyObject *PyC_UnicodeFromByte(const char *str)
|
||||
****************************************************************************/
|
||||
PyObject *PyC_DefaultNameSpace(const char *filename)
|
||||
{
|
||||
PyInterpreterState *interp= PyThreadState_GET()->interp;
|
||||
PyObject *mod_main= PyModule_New("__main__");
|
||||
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 */
|
||||
PyModule_AddStringConstant(mod_main, "__name__", "__main__");
|
||||
@@ -447,14 +447,14 @@ PyObject *PyC_DefaultNameSpace(const char *filename)
|
||||
/* restore MUST be called after this */
|
||||
void PyC_MainModule_Backup(PyObject **main_mod)
|
||||
{
|
||||
PyInterpreterState *interp= PyThreadState_GET()->interp;
|
||||
*main_mod= PyDict_GetItemString(interp->modules, "__main__");
|
||||
PyInterpreterState *interp = PyThreadState_GET()->interp;
|
||||
*main_mod = PyDict_GetItemString(interp->modules, "__main__");
|
||||
Py_XINCREF(*main_mod); /* dont free */
|
||||
}
|
||||
|
||||
void PyC_MainModule_Restore(PyObject *main_mod)
|
||||
{
|
||||
PyInterpreterState *interp= PyThreadState_GET()->interp;
|
||||
PyInterpreterState *interp = PyThreadState_GET()->interp;
|
||||
PyDict_SetItemString(interp->modules, "__main__", main_mod);
|
||||
Py_XDECREF(main_mod);
|
||||
}
|
||||
@@ -462,7 +462,7 @@ void PyC_MainModule_Restore(PyObject *main_mod)
|
||||
/* must be called before Py_Initialize, expects output of BLI_get_folder(BLENDER_PYTHON, NULL) */
|
||||
void PyC_SetHomePath(const char *py_path_bundle)
|
||||
{
|
||||
if (py_path_bundle==NULL) {
|
||||
if (py_path_bundle == NULL) {
|
||||
/* Common enough to have bundled *nix python but complain on OSX/Win */
|
||||
#if defined(__APPLE__) || defined(_WIN32)
|
||||
fprintf(stderr, "Warning! bundled python not found and is expected on this platform. "
|
||||
@@ -506,34 +506,34 @@ void PyC_SetHomePath(const char *py_path_bundle)
|
||||
/* Would be nice if python had this built in */
|
||||
void PyC_RunQuicky(const char *filepath, int n, ...)
|
||||
{
|
||||
FILE *fp= fopen(filepath, "r");
|
||||
FILE *fp = fopen(filepath, "r");
|
||||
|
||||
if (fp) {
|
||||
PyGILState_STATE gilstate= PyGILState_Ensure();
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
|
||||
va_list vargs;
|
||||
|
||||
int *sizes= PyMem_MALLOC(sizeof(int) * (n / 2));
|
||||
int *sizes = PyMem_MALLOC(sizeof(int) * (n / 2));
|
||||
int i;
|
||||
|
||||
PyObject *py_dict = PyC_DefaultNameSpace(filepath);
|
||||
PyObject *values= PyList_New(n / 2); /* namespace owns this, dont free */
|
||||
PyObject *values = PyList_New(n / 2); /* namespace owns this, dont free */
|
||||
|
||||
PyObject *py_result, *ret;
|
||||
|
||||
PyObject *struct_mod= PyImport_ImportModule("struct");
|
||||
PyObject *calcsize= PyObject_GetAttrString(struct_mod, "calcsize"); /* struct.calcsize */
|
||||
PyObject *pack= PyObject_GetAttrString(struct_mod, "pack"); /* struct.pack */
|
||||
PyObject *unpack= PyObject_GetAttrString(struct_mod, "unpack"); /* struct.unpack */
|
||||
PyObject *struct_mod = PyImport_ImportModule("struct");
|
||||
PyObject *calcsize = PyObject_GetAttrString(struct_mod, "calcsize"); /* struct.calcsize */
|
||||
PyObject *pack = PyObject_GetAttrString(struct_mod, "pack"); /* struct.pack */
|
||||
PyObject *unpack = PyObject_GetAttrString(struct_mod, "unpack"); /* struct.unpack */
|
||||
|
||||
Py_DECREF(struct_mod);
|
||||
|
||||
va_start(vargs, n);
|
||||
for (i=0; i * 2<n; i++) {
|
||||
for (i = 0; i * 2 < n; i++) {
|
||||
char *format = va_arg(vargs, char *);
|
||||
void *ptr = va_arg(vargs, void *);
|
||||
|
||||
ret= PyObject_CallFunction(calcsize, (char *)"s", format);
|
||||
ret = PyObject_CallFunction(calcsize, (char *)"s", format);
|
||||
|
||||
if (ret) {
|
||||
sizes[i]= PyLong_AsSsize_t(ret);
|
||||
@@ -554,7 +554,7 @@ void PyC_RunQuicky(const char *filepath, int n, ...)
|
||||
else {
|
||||
if (PyTuple_GET_SIZE(ret) == 1) {
|
||||
/* convenience, convert single tuples into single values */
|
||||
PyObject *tmp= PyTuple_GET_ITEM(ret, 0);
|
||||
PyObject *tmp = PyTuple_GET_ITEM(ret, 0);
|
||||
Py_INCREF(tmp);
|
||||
Py_DECREF(ret);
|
||||
ret = tmp;
|
||||
@@ -576,29 +576,29 @@ void PyC_RunQuicky(const char *filepath, int n, ...)
|
||||
|
||||
/* we could skip this but then only slice assignment would work
|
||||
* better not be so strict */
|
||||
values= PyDict_GetItemString(py_dict, "values");
|
||||
values = PyDict_GetItemString(py_dict, "values");
|
||||
|
||||
if (values && PyList_Check(values)) {
|
||||
|
||||
/* dont use the result */
|
||||
Py_DECREF(py_result);
|
||||
py_result= NULL;
|
||||
py_result = NULL;
|
||||
|
||||
/* now get the values back */
|
||||
va_start(vargs, n);
|
||||
for (i=0; i*2 <n; i++) {
|
||||
for (i = 0; i * 2 < n; i++) {
|
||||
char *format = va_arg(vargs, char *);
|
||||
void *ptr = va_arg(vargs, void *);
|
||||
|
||||
PyObject *item;
|
||||
PyObject *item_new;
|
||||
/* prepend the string formatting and remake the tuple */
|
||||
item= PyList_GET_ITEM(values, i);
|
||||
item = PyList_GET_ITEM(values, i);
|
||||
if (PyTuple_CheckExact(item)) {
|
||||
int ofs= PyTuple_GET_SIZE(item);
|
||||
item_new= PyTuple_New(ofs + 1);
|
||||
int ofs = PyTuple_GET_SIZE(item);
|
||||
item_new = PyTuple_New(ofs + 1);
|
||||
while (ofs--) {
|
||||
PyObject *member= PyTuple_GET_ITEM(item, ofs);
|
||||
PyObject *member = PyTuple_GET_ITEM(item, ofs);
|
||||
PyTuple_SET_ITEM(item_new, ofs + 1, member);
|
||||
Py_INCREF(member);
|
||||
}
|
||||
@@ -606,7 +606,7 @@ void PyC_RunQuicky(const char *filepath, int n, ...)
|
||||
PyTuple_SET_ITEM(item_new, 0, PyUnicode_FromString(format));
|
||||
}
|
||||
else {
|
||||
item_new= Py_BuildValue("sO", format, item);
|
||||
item_new = Py_BuildValue("sO", format, item);
|
||||
}
|
||||
|
||||
ret = PyObject_Call(pack, item_new, NULL);
|
||||
@@ -650,8 +650,8 @@ void PyC_RunQuicky(const char *filepath, int n, ...)
|
||||
/* generic function to avoid depending on RNA */
|
||||
void *PyC_RNA_AsPointer(PyObject *value, const char *type_name)
|
||||
{
|
||||
PyObject* as_pointer;
|
||||
PyObject* pointer;
|
||||
PyObject *as_pointer;
|
||||
PyObject *pointer;
|
||||
|
||||
if (!strcmp(Py_TYPE(value)->tp_name, type_name) &&
|
||||
(as_pointer = PyObject_GetAttrString(value, "as_pointer")) != NULL &&
|
||||
@@ -706,7 +706,7 @@ char *PyC_FlagSet_AsString(PyC_FlagSet *item)
|
||||
int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *value)
|
||||
{
|
||||
for( ; item->identifier; item++) {
|
||||
if(strcmp(item->identifier, identifier) == 0) {
|
||||
if (strcmp(item->identifier, identifier) == 0) {
|
||||
*value = item->value;
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user