diff --git a/.travis.yml b/.travis.yml index a77e4bf2..8e909e9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ dist: trusty language: python python: - "2.7" + - "3.4" - "3.5" - "3.6" before_install: diff --git a/Inventor/Qt/SoQtRenderArea.i b/Inventor/Qt/SoQtRenderArea.i index 50b49b19..9f51f82b 100644 --- a/Inventor/Qt/SoQtRenderArea.i +++ b/Inventor/Qt/SoQtRenderArea.i @@ -3,13 +3,12 @@ static SbBool SoQtRenderAreaEventPythonCB(void * closure, QEvent * event) { - PyObject *func, *arglist; - PyObject *result, *shiboken, *qt, *qev = NULL; - int ret = 0; + PyObject *func = NULL, *arglist = NULL; + PyObject *result = NULL, *shiboken, *qt = NULL, *qev = NULL; + SbBool ret = TRUE; // assume success as default /* try to create a QEvent PySide instance over shiboken */ - /* check if the shiboken module is available and import it */ shiboken = getShiboken(); @@ -21,24 +20,24 @@ SoQtRenderAreaEventPythonCB(void * closure, QEvent * event) if (qt && PyModule_Check(qt)) { /* grab the wrapinstance(addr, type) function */ - PyObject *shiboken_wrapinst_func; + PyObject *shiboken_wrapinst_func = NULL; shiboken_wrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "wrapInstance"); - if (PyCallable_Check(shiboken_wrapinst_func)) { - PyObject *qevent_type; + PyObject *qevent_type = NULL; qevent_type = PyDict_GetItemString(PyModule_GetDict(qt), get_typename(*event)); // TODO: find better solution for QKeyEvent if (!qevent_type){ - if (strcmp(get_typename(*event), "QKeyEventEx") == 0) + if (strcmp(get_typename(*event), "QKeyEventEx") == 0) { qevent_type = PyDict_GetItemString(PyModule_GetDict(qt), "QKeyEvent"); - else + } else { qevent_type = PyDict_GetItemString(PyModule_GetDict(qt), "QEvent"); + } } if (qevent_type) { - arglist = Py_BuildValue("(lO)", event, qevent_type); + arglist = Py_BuildValue("(nO)", event, qevent_type); if (!(qev = PyEval_CallObject(shiboken_wrapinst_func, arglist))) { PyErr_Print(); @@ -63,10 +62,12 @@ SoQtRenderAreaEventPythonCB(void * closure, QEvent * event) if (!(result = PyEval_CallObject(func, arglist))) { PyErr_Print(); } else { - ret = PyInt_AsLong(result); + ret = FALSE; } - if (shiboken) {Py_DECREF(shiboken); } + if (shiboken) { + Py_DECREF(shiboken); + } Py_DECREF(arglist); Py_DECREF(qev); Py_XDECREF(result); diff --git a/interfaces/soqt.i b/interfaces/soqt.i index 0629ce17..9ebb8767 100644 --- a/interfaces/soqt.i +++ b/interfaces/soqt.i @@ -31,7 +31,7 @@ otherwise it will fall back to regular SWIG structures." Coppied from: https://github.com/Kagami/pygraphviz/commit/fe442dc16accb629c3feaf157af75f67ccabbd6e */ #if PY_MAJOR_VERSION >= 3 -static PyObject *PyIOBase_TypeObj; +static PyObject *PyIOBase_TypeObj = NULL; static int init_file_emulator(void) { @@ -111,9 +111,7 @@ template const char* get_typename(T& object) #else template const char* get_typename(T& object) { - const char* simpleNonUnicodeAsciiCStyleString = typeid(object).name(); - const char* shortenedVersion = simpleNonUnicodeAsciiCStyleString + 6; - return shortenedVersion; + return (typeid(object).name() + 6); // the +6 advanced the pointer 6 bytes (6 asc ii characters) to cut off prefix "class " from the object's class name } #endif ///////////////////////////////////////////////////// @@ -126,10 +124,10 @@ static PyObject* getShiboken() // this function asumes shiboken is available directly // pip installs it in a wrong place // if you have installed shiboken with pip please symlink to correct directory - PyObject * shiboken; + PyObject * shiboken = NULL; if (!(shiboken = PyDict_GetItemString(PyModule_GetDict(PyImport_AddModule("__main__")), "shiboken"))) { // simple import shiboken from python. - shiboken = PyImport_ImportModule("shiboken"); + shiboken = PyImport_ImportModule("shiboken"); } return shiboken; } @@ -146,7 +144,7 @@ static PyObject* getShiboken() %typemap(out) QEvent * { $result = NULL; { - PyObject *qt; + PyObject *qt = NULL; /* try to create a PySide QEvent instance through shiboken */ @@ -160,14 +158,14 @@ static PyObject* getShiboken() if (qt && PyModule_Check(qt)) { /* grab the wrapInstance(addr, type) function */ - PyObject *shiboken_wrapinst_func; + PyObject *shiboken_wrapinst_func = NULL; shiboken_wrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "wrapInstance"); if (PyCallable_Check(shiboken_wrapinst_func)) { - PyObject *qevent_type, *arglist; + PyObject *qevent_type = NULL, *arglist = NULL; qevent_type = PyDict_GetItemString(PyModule_GetDict(qt), "QEvent"); - arglist = Py_BuildValue("(lO)", $1, qevent_type); + arglist = Py_BuildValue("(nO)", $1, qevent_type); if (!($result = PyEval_CallObject(shiboken_wrapinst_func, arglist))) { PyErr_Print(); @@ -189,7 +187,7 @@ static PyObject* getShiboken() %typemap(out) QWidget * { $result = NULL; { - PyObject *qt; + PyObject *qt = NULL; /* try to create a PySide QWidget instance through shiboken */ @@ -203,14 +201,14 @@ static PyObject* getShiboken() if (qt && PyModule_Check(qt)) { /* grab the wrapInstance(addr, type) function */ - PyObject *shiboken_wrapinst_func; + PyObject *shiboken_wrapinst_func = NULL; shiboken_wrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "wrapInstance"); if (PyCallable_Check(shiboken_wrapinst_func)) { - PyObject *qwidget_type, *arglist; + PyObject *qwidget_type = NULL, *arglist = NULL; qwidget_type = PyDict_GetItemString(PyModule_GetDict(qt), "QWidget"); - arglist = Py_BuildValue("(lO)", $1, qwidget_type); + arglist = Py_BuildValue("(nO)", $1, qwidget_type); if (!($result = PyEval_CallObject(shiboken_wrapinst_func, arglist))) { PyErr_Print(); @@ -235,11 +233,11 @@ static PyObject* getShiboken() if (shiboken && PyModule_Check(shiboken)) { /* grab the unwrapInstance(obj) function */ - PyObject *shiboken_unwrapinst_func; + PyObject *shiboken_unwrapinst_func = NULL; shiboken_unwrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "getCppPointer"); if (PyCallable_Check(shiboken_unwrapinst_func)) { - PyObject *arglist, *address; + PyObject *arglist = NULL, *address = NULL; arglist = Py_BuildValue("(O)", $input); if (!(address = PyEval_CallObject(shiboken_unwrapinst_func, arglist))) { PyErr_Print(); @@ -270,11 +268,11 @@ static PyObject* getShiboken() if (shiboken && PyModule_Check(shiboken)) { /* grab the unwrapInstance(obj) function */ - PyObject *shiboken_unwrapinst_func; + PyObject *shiboken_unwrapinst_func = NULL; shiboken_unwrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "getCppPointer"); if (PyCallable_Check(shiboken_unwrapinst_func)) { - PyObject *arglist, *address; + PyObject *arglist = NULL, *address = NULL; arglist = Py_BuildValue("(O)", $input); if (!(address = PyEval_CallObject(shiboken_unwrapinst_func, arglist))) { PyErr_Print(); @@ -307,11 +305,11 @@ class QWidget { QWidget(QWidget* parent=0, const char* name=0, WFlags f=0); }; if (shiboken && PyModule_Check(shiboken)) { /* grab the unwrapInstance(obj) function */ - PyObject *shiboken_unwrapinst_func; + PyObject *shiboken_unwrapinst_func = NULL; shiboken_unwrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "getCppPointer"); if (PyCallable_Check(shiboken_unwrapinst_func)) { - PyObject *arglist, *address; + PyObject *arglist = NULL, *address = NULL; arglist = Py_BuildValue("(O)", $input); if (!(address = PyEval_CallObject(shiboken_unwrapinst_func, arglist))) { PyErr_Print(); @@ -343,11 +341,11 @@ class QWidget { QWidget(QWidget* parent=0, const char* name=0, WFlags f=0); }; if (shiboken && PyModule_Check(shiboken)) { /* grab the unwrapInstance(obj) function */ - PyObject *shiboken_unwrapinst_func; + PyObject *shiboken_unwrapinst_func = NULL; shiboken_unwrapinst_func = PyDict_GetItemString(PyModule_GetDict(shiboken), "getCppPointer"); if (PyCallable_Check(shiboken_unwrapinst_func)) { - PyObject *arglist, *address; + PyObject *arglist = NULL, *address = NULL; arglist = Py_BuildValue("(O)", $input); if (!(address = PyEval_CallObject(shiboken_unwrapinst_func, arglist))) { PyErr_Print(); diff --git a/tests/coin_tests.py b/tests/coin_tests.py index 1e8535cf..4e53a63f 100755 --- a/tests/coin_tests.py +++ b/tests/coin_tests.py @@ -233,11 +233,7 @@ def testSFVec3f(self): s.setValue(t) self.failUnless(t.getValue() == s.getValue(), 'setValue other SoSFVec3f on SoSFVec3f failed') - # test division support - s.setValue(1, 1, 1) - self.failUnless(s / 2. == SoSFVec3f(0.5, 0.5, 0.5), - 'divison does not give correct solution') - # TODO: support ints! + def testSFVec2f(self): """check setValue for SoSFVec2f""" @@ -1199,6 +1195,15 @@ def setUp(self): def testSetBuffer(self): self.input.setBuffer(self.text) + +class SbVecTests(unittest.TestCase): + def setUp(self): + self.sbvec3f = coin.SbVec3f(1, 1, 1) + + def multDivTest(self): + self.assertEqual(self.sbvec3f, self.sbvec3f * 2. / 2.) + # TODO: also support ints + class SbPLaneTests(unittest.TestCase): def setUp(self):