99#include < stdexcept>
1010#include < vector>
1111
12- // static std::mutex g_py_mutex;
13-
1412#ifdef PHLEX_HAVE_NUMPY
1513#define NO_IMPORT_ARRAY
1614#define PY_ARRAY_UNIQUE_SYMBOL phlex_ARRAY_API
@@ -111,7 +109,6 @@ namespace {
111109 static_assert (sizeof ...(Args) == N, " Argument count mismatch" );
112110
113111 PyGILRAII gil;
114- // std::lock_guard<std::mutex> lock(g_py_mutex);
115112
116113 PyObject* result = PyObject_CallFunctionObjArgs (
117114 (PyObject*)m_callable, lifeline_transform (args.get ())..., nullptr );
@@ -134,7 +131,6 @@ namespace {
134131 static_assert (sizeof ...(Args) == N, " Argument count mismatch" );
135132
136133 PyGILRAII gil;
137- // std::lock_guard<std::mutex> lock(g_py_mutex);
138134
139135 PyObject* result =
140136 PyObject_CallFunctionObjArgs ((PyObject*)m_callable, (PyObject*)args.get ()..., nullptr );
@@ -372,7 +368,6 @@ namespace {
372368 static PyObjectPtr vint_to_py (std::shared_ptr<std::vector<int >> const & v)
373369 {
374370 PyGILRAII gil;
375- // std::lock_guard<std::mutex> lock(g_py_mutex);
376371 if (!v)
377372 return PyObjectPtr ();
378373 PyObject* list = PyList_New (v->size ());
@@ -395,7 +390,6 @@ namespace {
395390 static PyObjectPtr vuint_to_py (std::shared_ptr<std::vector<unsigned int >> const & v)
396391 {
397392 PyGILRAII gil;
398- // std::lock_guard<std::mutex> lock(g_py_mutex);
399393 if (!v)
400394 return PyObjectPtr ();
401395 PyObject* list = PyList_New (v->size ());
@@ -418,7 +412,6 @@ namespace {
418412 static PyObjectPtr vlong_to_py (std::shared_ptr<std::vector<long >> const & v)
419413 {
420414 PyGILRAII gil;
421- // std::lock_guard<std::mutex> lock(g_py_mutex);
422415 if (!v)
423416 return PyObjectPtr ();
424417 PyObject* list = PyList_New (v->size ());
@@ -441,7 +434,6 @@ namespace {
441434 static PyObjectPtr vulong_to_py (std::shared_ptr<std::vector<unsigned long >> const & v)
442435 {
443436 PyGILRAII gil;
444- // std::lock_guard<std::mutex> lock(g_py_mutex);
445437 if (!v)
446438 return PyObjectPtr ();
447439 PyObject* list = PyList_New (v->size ());
@@ -497,7 +489,6 @@ namespace {
497489 static std::shared_ptr<std::vector<int >> py_to_vint (PyObjectPtr pyobj)
498490 {
499491 PyGILRAII gil;
500- // std::lock_guard<std::mutex> lock(g_py_mutex);
501492 auto vec = std::make_shared<std::vector<int >>();
502493 PyObject* obj = pyobj.get ();
503494
@@ -537,7 +528,6 @@ namespace {
537528 static std::shared_ptr<std::vector<unsigned int >> py_to_vuint (PyObjectPtr pyobj)
538529 {
539530 PyGILRAII gil;
540- // std::lock_guard<std::mutex> lock(g_py_mutex);
541531 auto vec = std::make_shared<std::vector<unsigned int >>();
542532 PyObject* obj = pyobj.get ();
543533
@@ -577,7 +567,6 @@ namespace {
577567 static std::shared_ptr<std::vector<long >> py_to_vlong (PyObjectPtr pyobj)
578568 {
579569 PyGILRAII gil;
580- // std::lock_guard<std::mutex> lock(g_py_mutex);
581570 auto vec = std::make_shared<std::vector<long >>();
582571 PyObject* obj = pyobj.get ();
583572
@@ -617,7 +606,6 @@ namespace {
617606 static std::shared_ptr<std::vector<unsigned long >> py_to_vulong (PyObjectPtr pyobj)
618607 {
619608 PyGILRAII gil;
620- // std::lock_guard<std::mutex> lock(g_py_mutex);
621609 auto vec = std::make_shared<std::vector<unsigned long >>();
622610 PyObject* obj = pyobj.get ();
623611
@@ -657,7 +645,6 @@ namespace {
657645 static std::shared_ptr<std::vector<float >> py_to_vfloat (PyObjectPtr pyobj)
658646 {
659647 PyGILRAII gil;
660- // std::lock_guard<std::mutex> lock(g_py_mutex);
661648 auto vec = std::make_shared<std::vector<float >>();
662649 PyObject* obj = pyobj.get ();
663650
@@ -697,7 +684,6 @@ namespace {
697684 static std::shared_ptr<std::vector<double >> py_to_vdouble (PyObjectPtr pyobj)
698685 {
699686 PyGILRAII gil;
700- // std::lock_guard<std::mutex> lock(g_py_mutex);
701687 auto vec = std::make_shared<std::vector<double >>();
702688 PyObject* obj = pyobj.get ();
703689
@@ -863,8 +849,18 @@ static PyObject* parse_args(PyObject* args,
863849 return nullptr ;
864850 }
865851
852+ // special case of Phlex Variant wrapper
853+ PyObject* wrapped_callable = PyObject_GetAttrString (callable, " phlex_callable" );
854+ if (wrapped_callable) {
855+ // PyObject_GetAttrString returns a new reference, which we return
856+ callable = wrapped_callable;
857+ } else {
858+ // No wrapper, use the original callable with incremented reference count
859+ PyErr_Clear ();
860+ Py_INCREF (callable);
861+ }
862+
866863 // no common errors detected; actual registration may have more checks
867- Py_INCREF (callable);
868864 return callable;
869865}
870866
0 commit comments