diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-01-21 13:33:26 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-01-21 13:51:02 -0300 |
commit | 62bd3820c222cfb6af57c2ff4b23b8b819743bbf (patch) | |
tree | 26325d0b6ada5d79334f4ede59fc7432e9cfd482 /libshiboken/bindingmanager.cpp | |
parent | cd12b72f152f970a86cac12f62a0f9d1edd3f6d8 (diff) |
Adds support for Duck Punching (aka Monkey Patching).
The simplest definition of duck punching for our purposes is
the ability to change the definition of a method in an instance of
a class.
To allow this behaviour the SbkBaseWrapper structure had to be
extended with a 'ob_dict' which is a PyObject pointer to the instance
dictionary. It is originally set to NULL until the user tries to access
it. This dictionary could be accessed through the '__dict__' instance
property. For now it is read-only.
The generator was updated to handle the instance dictionary, and an
extensive duck punching test was also added.
Reviewed by Hugo Parente Lima <hugo.lima@openbossa.org>
Diffstat (limited to 'libshiboken/bindingmanager.cpp')
-rw-r--r-- | libshiboken/bindingmanager.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp index 786dade29..bce8d3656 100644 --- a/libshiboken/bindingmanager.cpp +++ b/libshiboken/bindingmanager.cpp @@ -131,6 +131,14 @@ PyObject* BindingManager::getOverride(const void* cptr, const char* methodName) if (!wrapper) return 0; + if (SbkBaseWrapper_instanceDict(wrapper)) { + PyObject* method = PyDict_GetItemString(SbkBaseWrapper_instanceDict(wrapper), methodName); + if (method) { + Py_INCREF(method); + return method; + } + } + PyObject* pyMethodName = PyString_FromString(methodName); PyObject* method = PyObject_GetAttr(wrapper, pyMethodName); |