Revision: 56867
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56867
Author:   kjym3
Date:     2013-05-16 23:49:05 +0000 (Thu, 16 May 2013)
Log Message:
-----------
Fix for Freestyle built-in style module sketchy_multiple_parameterization.py 
not working correctly.
Suitable for inclusion in 2.67a.

Logical AND, OR and XOR operations on freestyle.Nature instances gave an error 
in some cases.
The updated C implementation of these bitwise operations is intended to 
reproduce the following Python implementation:

class Nature(int):
    def __and__(self, other):
        return Nature(int(self) & int(other))
    def __or__(self, other):
        return Nature(int(self) | int(other))
    def __xor__(self, other):
        return Nature(int(self) ^ int(other))

The problem report was by plasmasolutions on IRC, thanks a lot!

Modified Paths:
--------------
    trunk/blender/source/blender/freestyle/intern/python/BPy_Nature.cpp

Modified: trunk/blender/source/blender/freestyle/intern/python/BPy_Nature.cpp
===================================================================
--- trunk/blender/source/blender/freestyle/intern/python/BPy_Nature.cpp 
2013-05-16 21:53:21 UTC (rev 56866)
+++ trunk/blender/source/blender/freestyle/intern/python/BPy_Nature.cpp 
2013-05-16 23:49:05 UTC (rev 56867)
@@ -263,41 +263,34 @@
 static PyObject *BPy_Nature_bitwise(PyObject *a, int op, PyObject *b)
 {
        BPy_Nature *result;
+       long op1, op2;
 
        if (!BPy_Nature_Check(a) || !BPy_Nature_Check(b)) {
                PyErr_SetString(PyExc_TypeError, "operands must be a Nature 
object");
                return NULL;
        }
-       if (Py_SIZE(a) != 1) {
-               stringstream msg;
-               msg << "operand 1: unexpected Nature byte length: " << 
Py_SIZE(a);
-               PyErr_SetString(PyExc_TypeError, msg.str().c_str());
+       op1 = PyLong_AsLong(a);
+       if (PyErr_Occurred()) {
+               PyErr_SetString(PyExc_ValueError, "operand 1: unexpected Nature 
value");
                return NULL;
        }
-       if (Py_SIZE(b) != 1) {
-               stringstream msg;
-               msg << "operand 2: unexpected Nature byte length: " << 
Py_SIZE(b);
-               PyErr_SetString(PyExc_TypeError, msg.str().c_str());
+       op2 = PyLong_AsLong(b);
+       if (PyErr_Occurred()) {
+               PyErr_SetString(PyExc_ValueError, "operand 2: unexpected Nature 
value");
                return NULL;
        }
        result = PyObject_NewVar(BPy_Nature, &Nature_Type, 1);
        if (!result)
                return NULL;
-       if (Py_SIZE(result) != 1) {
-               stringstream msg;
-               msg << "unexpected Nature byte length: " << Py_SIZE(result);
-               PyErr_SetString(PyExc_TypeError, msg.str().c_str());
-               return NULL;
-       }
        switch (op) {
        case '&':
-               result->i.ob_digit[0] = (((PyLongObject *)a)->ob_digit[0]) & 
(((PyLongObject *)b)->ob_digit)[0];
+               result->i.ob_digit[0] = op1 & op2;
                break;
        case '^':
-               result->i.ob_digit[0] = (((PyLongObject *)a)->ob_digit[0]) ^ 
(((PyLongObject *)b)->ob_digit)[0];
+               result->i.ob_digit[0] = op1 ^ op2;
                break;
        case '|':
-               result->i.ob_digit[0] = (((PyLongObject *)a)->ob_digit[0]) | 
(((PyLongObject *)b)->ob_digit)[0];
+               result->i.ob_digit[0] = op1 | op2;
                break;
        }
        return (PyObject *)result;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to