Skip to content

Commit 5f41464

Browse files
Fix handling python exposure of shared pointer objects
1 parent d9a2488 commit 5f41464

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

RESTProcessExample/RESTProcessExample.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct IPoly: public PolyRESTProcess<IPoly> {};
164164

165165
struct Poly: public PolyRESTProcess<Poly, IPoly>
166166
{
167-
int a;
167+
int a=5;
168168
};
169169

170170
// root type
@@ -175,7 +175,7 @@ struct Root
175175
Bar1 bar1;
176176

177177
std::shared_ptr<IPoly> spoly{new Poly};
178-
std::shared_ptr<Bar> sbar{new Bar};
178+
std::shared_ptr<Bar> sbar{new Bar(0)};
179179

180180
FooBar1& getFB1() {
181181
static FooBar1 m;

RESTProcessExample/example.py

+4
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,7 @@ def expectThrow(f):
220220
fb=FooBar1()
221221
assert foo.b()==2
222222
assert fb.f.b()==0
223+
224+
# shared pointer support
225+
assert root.sbar.f()==20
226+
assert root.spoly.a()==5

pythonBuffer.h

+9
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ namespace classdesc
571571
}
572572

573573
static PyObject* getAttro(PyObject* self, PyObject* attr)
574+
try
574575
{
575576
auto cppWrapper=static_cast<CppWrapper*>(self);
576577
auto i=cppWrapper->methods.find(PyUnicode_AsUTF8(attr));
@@ -579,8 +580,16 @@ namespace classdesc
579580
Py_INCREF(i->second);
580581
return i->second;
581582
}
583+
else
584+
{
585+
auto methods=cppWrapper->command->list();
586+
auto attribute=methods.find(string(".")+PyUnicode_AsUTF8(attr));
587+
if (attribute!=methods.end())
588+
return CppWrapper::create(attribute->second, false);
589+
}
582590
return PyObject_GenericGetAttr(self,attr);
583591
}
592+
CLASSDESC_PY_EXCEPTION_ABSORB(nullptr);
584593

585594
static int setAttro(PyObject* self, PyObject* name, PyObject* attr)
586595
{

0 commit comments

Comments
 (0)