99#include < stdexcept>
1010#include < vector>
1111
12- // static std::mutex g_py_mutex;
13-
1412#define NO_IMPORT_ARRAY
1513#define PY_ARRAY_UNIQUE_SYMBOL phlex_ARRAY_API
1614#include < numpy/arrayobject.h>
@@ -109,7 +107,6 @@ namespace {
109107 static_assert (sizeof ...(Args) == N, " Argument count mismatch" );
110108
111109 PyGILRAII gil;
112- // std::lock_guard<std::mutex> lock(g_py_mutex);
113110
114111 PyObject* result = PyObject_CallFunctionObjArgs (
115112 (PyObject*)m_callable, lifeline_transform (args.get ())..., nullptr );
@@ -132,7 +129,6 @@ namespace {
132129 static_assert (sizeof ...(Args) == N, " Argument count mismatch" );
133130
134131 PyGILRAII gil;
135- // std::lock_guard<std::mutex> lock(g_py_mutex);
136132
137133 PyObject* result =
138134 PyObject_CallFunctionObjArgs ((PyObject*)m_callable, (PyObject*)args.get ()..., nullptr );
@@ -369,7 +365,6 @@ namespace {
369365 static PyObjectPtr vint_to_py (std::shared_ptr<std::vector<int >> const & v)
370366 {
371367 PyGILRAII gil;
372- // std::lock_guard<std::mutex> lock(g_py_mutex);
373368 if (!v)
374369 return PyObjectPtr ();
375370 PyObject* list = PyList_New (v->size ());
@@ -392,7 +387,6 @@ namespace {
392387 static PyObjectPtr vuint_to_py (std::shared_ptr<std::vector<unsigned int >> const & v)
393388 {
394389 PyGILRAII gil;
395- // std::lock_guard<std::mutex> lock(g_py_mutex);
396390 if (!v)
397391 return PyObjectPtr ();
398392 PyObject* list = PyList_New (v->size ());
@@ -415,7 +409,6 @@ namespace {
415409 static PyObjectPtr vlong_to_py (std::shared_ptr<std::vector<long >> const & v)
416410 {
417411 PyGILRAII gil;
418- // std::lock_guard<std::mutex> lock(g_py_mutex);
419412 if (!v)
420413 return PyObjectPtr ();
421414 PyObject* list = PyList_New (v->size ());
@@ -438,7 +431,6 @@ namespace {
438431 static PyObjectPtr vulong_to_py (std::shared_ptr<std::vector<unsigned long >> const & v)
439432 {
440433 PyGILRAII gil;
441- // std::lock_guard<std::mutex> lock(g_py_mutex);
442434 if (!v)
443435 return PyObjectPtr ();
444436 PyObject* list = PyList_New (v->size ());
@@ -501,7 +493,6 @@ namespace {
501493 static std::shared_ptr<std::vector<int >> py_to_vint (PyObjectPtr pyobj)
502494 {
503495 PyGILRAII gil;
504- // std::lock_guard<std::mutex> lock(g_py_mutex);
505496 auto vec = std::make_shared<std::vector<int >>();
506497 PyObject* obj = pyobj.get ();
507498
@@ -541,7 +532,6 @@ namespace {
541532 static std::shared_ptr<std::vector<unsigned int >> py_to_vuint (PyObjectPtr pyobj)
542533 {
543534 PyGILRAII gil;
544- // std::lock_guard<std::mutex> lock(g_py_mutex);
545535 auto vec = std::make_shared<std::vector<unsigned int >>();
546536 PyObject* obj = pyobj.get ();
547537
@@ -581,7 +571,6 @@ namespace {
581571 static std::shared_ptr<std::vector<long >> py_to_vlong (PyObjectPtr pyobj)
582572 {
583573 PyGILRAII gil;
584- // std::lock_guard<std::mutex> lock(g_py_mutex);
585574 auto vec = std::make_shared<std::vector<long >>();
586575 PyObject* obj = pyobj.get ();
587576
@@ -621,7 +610,6 @@ namespace {
621610 static std::shared_ptr<std::vector<unsigned long >> py_to_vulong (PyObjectPtr pyobj)
622611 {
623612 PyGILRAII gil;
624- // std::lock_guard<std::mutex> lock(g_py_mutex);
625613 auto vec = std::make_shared<std::vector<unsigned long >>();
626614 PyObject* obj = pyobj.get ();
627615
@@ -661,7 +649,6 @@ namespace {
661649 static std::shared_ptr<std::vector<float >> py_to_vfloat (PyObjectPtr pyobj)
662650 {
663651 PyGILRAII gil;
664- // std::lock_guard<std::mutex> lock(g_py_mutex);
665652 auto vec = std::make_shared<std::vector<float >>();
666653 PyObject* obj = pyobj.get ();
667654
@@ -701,7 +688,6 @@ namespace {
701688 static std::shared_ptr<std::vector<double >> py_to_vdouble (PyObjectPtr pyobj)
702689 {
703690 PyGILRAII gil;
704- // std::lock_guard<std::mutex> lock(g_py_mutex);
705691 auto vec = std::make_shared<std::vector<double >>();
706692 PyObject* obj = pyobj.get ();
707693
@@ -866,8 +852,16 @@ static PyObject* parse_args(PyObject* args,
866852 return nullptr ;
867853 }
868854
855+ // special case of Phlex Variant wrapper
856+ PyObject* wrapped_callable = PyObject_GetAttrString (callable, " phlex_callable" );
857+ if (wrapped_callable) {
858+ callable = wrapped_callable;
859+ } else {
860+ PyErr_Clear ();
861+ Py_INCREF (callable);
862+ }
863+
869864 // no common errors detected; actual registration may have more checks
870- Py_INCREF (callable);
871865 return callable;
872866}
873867
0 commit comments