comparison PyPlugin.cpp @ 71:40a01bb24209 vampyhost

Pull apart some type conversion classes for possible use in VamPy Host
author Chris Cannam
date Thu, 20 Nov 2014 13:02:50 +0000
parents 146d14ab15e7
children ffaa1fb3d7de
comparison
equal deleted inserted replaced
70:6c755f3e1173 71:40a01bb24209
85 else DSTREAM << "Debug messages OFF for Vampy plugin: " << m_class << endl; 85 else DSTREAM << "Debug messages OFF for Vampy plugin: " << m_class << endl;
86 86
87 if (m_debugFlag && m_quitOnErrorFlag) cerr << "Quit on type error ON for: " << m_class << endl; 87 if (m_debugFlag && m_quitOnErrorFlag) cerr << "Quit on type error ON for: " << m_class << endl;
88 88
89 if (m_debugFlag && st_flag) cerr << "Strict type conversion ON for: " << m_class << endl; 89 if (m_debugFlag && st_flag) cerr << "Strict type conversion ON for: " << m_class << endl;
90
90 m_ti.setStrictTypingFlag(st_flag); 91 m_ti.setStrictTypingFlag(st_flag);
92 m_tc.setStrictTypingFlag(st_flag);
93
91 m_ti.setNumpyInstalled(m_numpyInstalled); 94 m_ti.setNumpyInstalled(m_numpyInstalled);
95 m_tc.setNumpyInstalled(m_numpyInstalled);
92 96
93 } 97 }
94 98
95 PyPlugin::~PyPlugin() 99 PyPlugin::~PyPlugin()
96 { 100 {
316 PyObject *pyValue = PyObject_GetAttrString(m_pyInstance,flagName); 320 PyObject *pyValue = PyObject_GetAttrString(m_pyInstance,flagName);
317 if (!pyValue) 321 if (!pyValue)
318 { 322 {
319 if (PyErr_Occurred()) {PyErr_Print(); PyErr_Clear();} 323 if (PyErr_Occurred()) {PyErr_Print(); PyErr_Clear();}
320 } else { 324 } else {
321 rValue = m_ti.PyValue_To_Bool(pyValue); 325 rValue = m_tc.PyValue_To_Bool(pyValue);
322 if (m_ti.error) { 326 if (m_tc.error) {
323 Py_CLEAR(pyValue); 327 Py_CLEAR(pyValue);
324 typeErrorHandler(flagName); 328 typeErrorHandler(flagName);
325 rValue = defValue; 329 rValue = defValue;
326 } else Py_DECREF(pyValue); 330 } else Py_DECREF(pyValue);
327 } 331 }
339 PyObject *pyValue = PyObject_GetAttrString(m_pyInstance,flagName); 343 PyObject *pyValue = PyObject_GetAttrString(m_pyInstance,flagName);
340 if (!pyValue) 344 if (!pyValue)
341 { 345 {
342 if (PyErr_Occurred()) {PyErr_Print(); PyErr_Clear();} 346 if (PyErr_Occurred()) {PyErr_Print(); PyErr_Clear();}
343 } else { 347 } else {
344 rValue |= (int) m_ti.PyValue_To_Size_t(pyValue); 348 rValue |= (int) m_tc.PyValue_To_Size_t(pyValue);
345 if (m_ti.error) { 349 if (m_tc.error) {
346 Py_CLEAR(pyValue); 350 Py_CLEAR(pyValue);
347 typeErrorHandler(flagName); 351 typeErrorHandler(flagName);
348 rValue = defValue; 352 rValue = defValue;
349 } else Py_DECREF(pyValue); 353 } else Py_DECREF(pyValue);
350 } 354 }
428 432
429 void 433 void
430 PyPlugin::typeErrorHandler(const char *method, bool process) const 434 PyPlugin::typeErrorHandler(const char *method, bool process) const
431 { 435 {
432 bool strict = false; 436 bool strict = false;
433 while (m_ti.error) { 437 while (m_tc.error || m_ti.error) {
434 PyTypeInterface::ValueError e = m_ti.getError(); 438 ValueError e;
439 if (m_tc.error) e = m_tc.getError();
440 else e = m_ti.getError();
435 #ifdef HAVE_NUMPY 441 #ifdef HAVE_NUMPY
436 // disable the process completely if numpy types are returned 442 // disable the process completely if numpy types are returned
437 // but a compatible version was not loaded. 443 // but a compatible version was not loaded.
438 // This is required because if an object is returned from 444 // This is required because if an object is returned from
439 // the wrong build, malloc complains about its size 445 // the wrong build, malloc complains about its size