Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make __dict__ accessible for Python builtin classes #320

Merged
merged 3 commits into from Apr 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/python/builtin.swg
Expand Up @@ -9,6 +9,7 @@ SWIGINTERN void \
wrapper##_closure(PyObject *a) { \
SwigPyObject *sobj; \
sobj = (SwigPyObject *)a; \
Py_XDECREF(sobj->dict); \
if (sobj->own) { \
PyObject *o = wrapper(a, NULL); \
Py_XDECREF(o); \
Expand Down
26 changes: 23 additions & 3 deletions Lib/python/pyrun.swg
Expand Up @@ -381,6 +381,23 @@ typedef struct {
#endif
} SwigPyObject;


#ifdef SWIGPYTHON_BUILTIN

SWIGRUNTIME PyObject *
SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args))
{
SwigPyObject *sobj = (SwigPyObject *)v;

if (!sobj->dict)
sobj->dict = PyDict_New();

Py_INCREF(sobj->dict);
return sobj->dict;
}

#endif

SWIGRUNTIME PyObject *
SwigPyObject_long(SwigPyObject *v)
{
Expand Down Expand Up @@ -1420,18 +1437,21 @@ SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int f
newobj = (SwigPyObject *) newobj->next;
newobj->next = next_self;
newobj = (SwigPyObject *)next_self;
#ifdef SWIGPYTHON_BUILTIN
newobj->dict = 0;
#endif
}
} else {
newobj = PyObject_New(SwigPyObject, clientdata->pytype);
#ifdef SWIGPYTHON_BUILTIN
newobj->dict = 0;
#endif
}
if (newobj) {
newobj->ptr = ptr;
newobj->ty = type;
newobj->own = own;
newobj->next = 0;
#ifdef SWIGPYTHON_BUILTIN
newobj->dict = 0;
#endif
return (PyObject*) newobj;
}
return SWIG_Py_Void();
Expand Down
11 changes: 11 additions & 0 deletions Source/Modules/python.cxx
Expand Up @@ -3057,6 +3057,17 @@ class PYTHON:public Language {
}

/* If this is a builtin type, create a PyGetSetDef entry for this member variable. */
if (builtin) {
const char *memname = "__dict__";
Hash *h = Getattr(builtin_getset, memname);
if (!h) {
h = NewHash();
Setattr(builtin_getset, memname, h);
Delete(h);
}
Setattr(h, "getter", "SwigPyObject_get___dict__");
}

if (builtin_getter) {
String *memname = Getattr(n, "membervariableHandler:sym:name");
if (!memname)
Expand Down