Merged changes in the trunk up to revision 34201.
This commit is contained in:
@@ -261,7 +261,7 @@ static int idp_sequence_type(PyObject *seq)
|
||||
PyObject *item;
|
||||
int type= IDP_INT;
|
||||
|
||||
int i, len = PySequence_Length(seq);
|
||||
int i, len = PySequence_Size(seq);
|
||||
for (i=0; i < len; i++) {
|
||||
item = PySequence_GetItem(seq, i);
|
||||
if (PyFloat_Check(item)) {
|
||||
@@ -331,7 +331,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(const char *name, IDProperty *g
|
||||
we assume IDP_INT unless we hit a float
|
||||
number; then we assume it's */
|
||||
|
||||
val.array.len = PySequence_Length(ob);
|
||||
val.array.len = PySequence_Size(ob);
|
||||
|
||||
switch(val.array.type) {
|
||||
case IDP_DOUBLE:
|
||||
|
||||
@@ -207,7 +207,7 @@ static PyObject *Method_Buffer (PyObject *UNUSED(self), PyObject *args)
|
||||
ndimensions= 1;
|
||||
dimensions[0]= PyLong_AsLong(length_ob);
|
||||
} else if (PySequence_Check(length_ob)) {
|
||||
ndimensions= PySequence_Length(length_ob);
|
||||
ndimensions= PySequence_Size(length_ob);
|
||||
if (ndimensions > MAX_DIMENSIONS) {
|
||||
PyErr_SetString(PyExc_AttributeError, "too many dimensions, max is 256");
|
||||
return NULL;
|
||||
@@ -360,8 +360,8 @@ static int Buffer_ass_slice(PyObject *self, int begin, int end, PyObject *seq)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (PySequence_Length(seq)!=(end-begin)) {
|
||||
int seq_len = PySequence_Length(seq);
|
||||
if (PySequence_Size(seq)!=(end-begin)) {
|
||||
int seq_len = PySequence_Size(seq);
|
||||
char err_str[128];
|
||||
sprintf(err_str, "size mismatch in assignment. Expected size: %d (size provided: %d)", seq_len, (end-begin));
|
||||
PyErr_SetString(PyExc_TypeError, err_str);
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
|
||||
static int Matrix_ass_slice(MatrixObject * self, int begin, int end, PyObject *value);
|
||||
|
||||
/* matrix vector callbacks */
|
||||
int mathutils_matrix_vector_cb_index= -1;
|
||||
@@ -109,80 +109,42 @@ Mathutils_Callback mathutils_matrix_vector_cb = {
|
||||
//create a new matrix type
|
||||
static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyObject *argObject, *m, *s;
|
||||
MatrixObject *mat;
|
||||
int argSize, seqSize = 0, i, j;
|
||||
float matrix[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||
float scalar;
|
||||
|
||||
if(kwds && PyDict_Size(kwds)) {
|
||||
PyErr_SetString(PyExc_TypeError, "mathutils.Matrix(): takes no keyword args");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
argSize = PyTuple_GET_SIZE(args);
|
||||
if(argSize > MATRIX_MAX_DIM) { //bad arg nums
|
||||
PyErr_SetString(PyExc_AttributeError, "mathutils.Matrix(): expects 0-4 numeric sequences of the same size");
|
||||
return NULL;
|
||||
} else if (argSize == 0) { //return empty 4D matrix
|
||||
return (PyObject *) newMatrixObject(NULL, 4, 4, Py_NEW, type);
|
||||
}else if (argSize == 1){
|
||||
//copy constructor for matrix objects
|
||||
argObject = PyTuple_GET_ITEM(args, 0);
|
||||
if(MatrixObject_Check(argObject)){
|
||||
mat = (MatrixObject*)argObject;
|
||||
if(!BaseMath_ReadCallback(mat))
|
||||
return NULL;
|
||||
switch(PyTuple_GET_SIZE(args)) {
|
||||
case 0:
|
||||
return (PyObject *) newMatrixObject(NULL, 4, 4, Py_NEW, type);
|
||||
case 1:
|
||||
{
|
||||
PyObject *arg= PyTuple_GET_ITEM(args, 0);
|
||||
|
||||
memcpy(matrix, mat->contigPtr, sizeof(float) * mat->rowSize * mat->colSize);
|
||||
argSize = mat->rowSize;
|
||||
seqSize = mat->colSize;
|
||||
}
|
||||
}else{ //2-4 arguments (all seqs? all same size?)
|
||||
for(i =0; i < argSize; i++){
|
||||
argObject = PyTuple_GET_ITEM(args, i);
|
||||
if (PySequence_Check(argObject)) { //seq?
|
||||
if(seqSize){ //0 at first
|
||||
if(PySequence_Length(argObject) != seqSize){ //seq size not same
|
||||
PyErr_SetString(PyExc_AttributeError, "mathutils.Matrix(): expects 0-4 numeric sequences of the same size");
|
||||
return NULL;
|
||||
const unsigned short row_size= PySequence_Size(arg); /* -1 is an error, size checks will accunt for this */
|
||||
|
||||
if(IN_RANGE_INCL(row_size, 2, 4)) {
|
||||
PyObject *item= PySequence_GetItem(arg, 0);
|
||||
const unsigned short col_size= PySequence_Size(item);
|
||||
Py_XDECREF(item);
|
||||
|
||||
if(IN_RANGE_INCL(col_size, 2, 4)) {
|
||||
/* sane row & col size, new matrix and assign as slice */
|
||||
PyObject *matrix= newMatrixObject(NULL, row_size, col_size, Py_NEW, type);
|
||||
if(Matrix_ass_slice((MatrixObject *)matrix, 0, INT_MAX, arg) == 0) {
|
||||
return matrix;
|
||||
}
|
||||
else { /* matrix ok, slice assignment not */
|
||||
Py_DECREF(matrix);
|
||||
}
|
||||
}
|
||||
seqSize = PySequence_Length(argObject);
|
||||
}else{ //arg not a sequence
|
||||
PyErr_SetString(PyExc_TypeError, "mathutils.Matrix(): expects 0-4 numeric sequences of the same size");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
//all is well... let's continue parsing
|
||||
for (i = 0; i < argSize; i++){
|
||||
m = PyTuple_GET_ITEM(args, i);
|
||||
if (m == NULL) { // Failed to read sequence
|
||||
PyErr_SetString(PyExc_RuntimeError, "mathutils.Matrix(): failed to parse arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (j = 0; j < seqSize; j++) {
|
||||
s = PySequence_GetItem(m, j);
|
||||
if (s == NULL) { // Failed to read sequence
|
||||
PyErr_SetString(PyExc_RuntimeError, "mathutils.Matrix(): failed to parse arguments");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
scalar= (float)PyFloat_AsDouble(s);
|
||||
Py_DECREF(s);
|
||||
|
||||
if(scalar==-1 && PyErr_Occurred()) { // parsed item is not a number
|
||||
PyErr_SetString(PyExc_AttributeError, "mathutils.Matrix(): expects 0-4 numeric sequences of the same size");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
matrix[(seqSize*i)+j]= scalar;
|
||||
}
|
||||
}
|
||||
}
|
||||
return newMatrixObject(matrix, argSize, seqSize, Py_NEW, type);
|
||||
|
||||
/* will overwrite error */
|
||||
PyErr_SetString(PyExc_TypeError, "mathutils.Matrix(): expects no args or 2-4 numeric sequences");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*-----------------------CLASS-METHODS----------------------------*/
|
||||
@@ -1554,7 +1516,7 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
|
||||
}
|
||||
}
|
||||
else {
|
||||
BKE_assert(!"internal error");
|
||||
BLI_assert(!"internal error");
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "Matrix multiplication: not supported between '%.200s' and '%.200s' types", Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name);
|
||||
@@ -1847,7 +1809,7 @@ self->matrix[1][1] = self->contigPtr[4] */
|
||||
(i.e. it was allocated elsewhere by MEM_mallocN())
|
||||
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
||||
(i.e. it must be created here with PyMEM_malloc())*/
|
||||
PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type, PyTypeObject *base_type)
|
||||
PyObject *newMatrixObject(float *mat, const unsigned short rowSize, const unsigned short colSize, int type, PyTypeObject *base_type)
|
||||
{
|
||||
MatrixObject *self;
|
||||
int x, row, col;
|
||||
|
||||
@@ -49,7 +49,7 @@ be stored in py_data) or be a wrapper for data allocated through
|
||||
blender (stored in blend_data). This is an either/or struct not both*/
|
||||
|
||||
/*prototypes*/
|
||||
PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type, PyTypeObject *base_type);
|
||||
PyObject *newMatrixObject(float *mat, const unsigned short rowSize, const unsigned short colSize, int type, PyTypeObject *base_type);
|
||||
PyObject *newMatrixObject_cb(PyObject *user, int rowSize, int colSize, int cb_type, int cb_subtype);
|
||||
|
||||
extern int mathutils_matrix_vector_cb_index;
|
||||
|
||||
@@ -684,7 +684,7 @@ static PyObject *Quaternion_mul(PyObject * q1, PyObject * q2)
|
||||
}
|
||||
}
|
||||
else {
|
||||
BKE_assert(!"internal error");
|
||||
BLI_assert(!"internal error");
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "Quaternion multiplication: not supported between '%.200s' and '%.200s' types", Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name);
|
||||
|
||||
@@ -844,7 +844,7 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end,
|
||||
CLAMP(end, 0, self->size);
|
||||
begin = MIN2(begin,end);
|
||||
|
||||
size = PySequence_Length(seq);
|
||||
size = PySequence_Size(seq);
|
||||
if(size != (end - begin)){
|
||||
PyErr_SetString(PyExc_TypeError, "vector[begin:end] = []: size mismatch in slice assignment");
|
||||
return -1;
|
||||
@@ -1129,7 +1129,7 @@ static PyObject *Vector_mul(PyObject * v1, PyObject * v2)
|
||||
}
|
||||
}
|
||||
else {
|
||||
BKE_assert(!"internal error");
|
||||
BLI_assert(!"internal error");
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "Vector multiplication: not supported between '%.200s' and '%.200s' types", Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name);
|
||||
|
||||
@@ -269,7 +269,7 @@ void BPY_python_start( int argc, char **argv )
|
||||
Py_DECREF(mod);
|
||||
}
|
||||
else {
|
||||
BKE_assert(!"unable to load 'imp' module.");
|
||||
BLI_assert(!"unable to load 'imp' module.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -319,7 +319,7 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, st
|
||||
PyObject *py_dict= NULL, *py_result= NULL;
|
||||
PyGILState_STATE gilstate;
|
||||
|
||||
BKE_assert(fn || text);
|
||||
BLI_assert(fn || text);
|
||||
|
||||
if (fn==NULL && text==NULL) {
|
||||
return 0;
|
||||
|
||||
@@ -552,7 +552,7 @@ static EnumPropertyItem *enum_items_from_py(PyObject *value, PyObject *def, int
|
||||
return NULL;
|
||||
}
|
||||
|
||||
seq_len= PySequence_Length(value);
|
||||
seq_len= PySequence_Size(value);
|
||||
|
||||
if(is_enum_flag) {
|
||||
if(seq_len > RNA_ENUM_BITFLAG_SIZE) {
|
||||
|
||||
@@ -75,7 +75,7 @@ static int rna_id_write_error(PointerRNA *ptr, PyObject *key)
|
||||
else pyname= "<UNKNOWN>";
|
||||
|
||||
/* make a nice string error */
|
||||
BKE_assert(idtype != NULL);
|
||||
BLI_assert(idtype != NULL);
|
||||
PyErr_Format(PyExc_RuntimeError, "Writing to ID classes in this context is not allowed: %.200s, %.200s datablock, error setting %.200s.%.200s", id->name+2, idtype, RNA_struct_identifier(ptr->type), pyname);
|
||||
|
||||
return TRUE;
|
||||
@@ -1250,7 +1250,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
|
||||
return -1;
|
||||
}
|
||||
|
||||
seq_len = PySequence_Length(value);
|
||||
seq_len = PySequence_Size(value);
|
||||
for(i=0; i<seq_len; i++) {
|
||||
item= PySequence_GetItem(value, i);
|
||||
|
||||
@@ -1572,7 +1572,7 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BKE_assert(!"Invalid array type");
|
||||
BLI_assert(!"Invalid array type");
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "not an array type");
|
||||
Py_DECREF(tuple);
|
||||
@@ -2779,7 +2779,7 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname )
|
||||
break;
|
||||
default:
|
||||
/* should never happen */
|
||||
BKE_assert(!"Invalid context type");
|
||||
BLI_assert(!"Invalid context type");
|
||||
|
||||
PyErr_Format(PyExc_AttributeError, "bpy_struct: Context type invalid %d, can't get \"%.200s\" from context", newtype, name);
|
||||
ret= NULL;
|
||||
@@ -3279,7 +3279,7 @@ static int foreach_parse_args(
|
||||
return -1;
|
||||
}
|
||||
|
||||
*tot= PySequence_Length(*seq); // TODO - buffer may not be a sequence! array.array() is tho.
|
||||
*tot= PySequence_Size(*seq); // TODO - buffer may not be a sequence! array.array() is tho.
|
||||
|
||||
if(*tot>0) {
|
||||
foreach_attr_type(self, *attr, raw_type, attr_tot, attr_signed);
|
||||
@@ -3400,7 +3400,7 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
|
||||
break;
|
||||
case PROP_RAW_UNSET:
|
||||
/* should never happen */
|
||||
BKE_assert(!"Invalid array type - set");
|
||||
BLI_assert(!"Invalid array type - set");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3455,7 +3455,7 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
|
||||
break;
|
||||
case PROP_RAW_UNSET:
|
||||
/* should never happen */
|
||||
BKE_assert(!"Invalid array type - get");
|
||||
BLI_assert(!"Invalid array type - get");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3813,7 +3813,7 @@ static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
|
||||
void *retdata_single= NULL;
|
||||
|
||||
/* Should never happen but it does in rare cases */
|
||||
BKE_assert(self_ptr != NULL);
|
||||
BLI_assert(self_ptr != NULL);
|
||||
|
||||
if(self_ptr==NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "rna functions internal rna pointer is NULL, this is a bug. aborting");
|
||||
|
||||
@@ -57,7 +57,7 @@ static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[]
|
||||
if (dim + 1 < totdim) {
|
||||
/* check that a sequence contains dimsize[dim] items */
|
||||
|
||||
for (i= 0; i < PySequence_Length(seq); i++) {
|
||||
for (i= 0; i < PySequence_Size(seq); i++) {
|
||||
PyObject *item;
|
||||
int ok= 1;
|
||||
item= PySequence_GetItem(seq, i);
|
||||
@@ -72,7 +72,7 @@ static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[]
|
||||
dimsize[2]=5
|
||||
|
||||
dim=0 */
|
||||
else if (PySequence_Length(item) != dimsize[dim + 1]) {
|
||||
else if (PySequence_Size(item) != dimsize[dim + 1]) {
|
||||
/* BLI_snprintf(error_str, error_str_size, "sequences of dimension %d should contain %d items", (int)dim + 1, (int)dimsize[dim + 1]); */
|
||||
PyErr_Format(PyExc_ValueError, "%s sequences of dimension %d should contain %d items", error_prefix, (int)dim + 1, (int)dimsize[dim + 1]);
|
||||
ok= 0;
|
||||
@@ -89,7 +89,7 @@ static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[]
|
||||
}
|
||||
else {
|
||||
/* check that items are of correct type */
|
||||
for (i= 0; i < PySequence_Length(seq); i++) {
|
||||
for (i= 0; i < PySequence_Size(seq); i++) {
|
||||
PyObject *item= PySequence_GetItem(seq, i);
|
||||
|
||||
if (!check_item_type(item)) {
|
||||
@@ -114,7 +114,7 @@ static int count_items(PyObject *seq)
|
||||
|
||||
if (PySequence_Check(seq)) {
|
||||
int i;
|
||||
for (i= 0; i < PySequence_Length(seq); i++) {
|
||||
for (i= 0; i < PySequence_Size(seq); i++) {
|
||||
PyObject *item= PySequence_GetItem(seq, i);
|
||||
totitem += count_items(item);
|
||||
Py_DECREF(item);
|
||||
@@ -211,7 +211,7 @@ static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int
|
||||
unsigned int i;
|
||||
int totdim= RNA_property_array_dimension(ptr, prop, NULL);
|
||||
|
||||
for (i= 0; i < PySequence_Length(seq); i++) {
|
||||
for (i= 0; i < PySequence_Size(seq); i++) {
|
||||
PyObject *item= PySequence_GetItem(seq, i);
|
||||
|
||||
if (dim + 1 < totdim) {
|
||||
|
||||
Reference in New Issue
Block a user