|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62232 - in sandbox/python_extensions: . libs/python/src libs/python/test
From: talljimbo_at_[hidden]
Date: 2010-05-26 04:26:02
Author: jbosch
Date: 2010-05-26 04:26:00 EDT (Wed, 26 May 2010)
New Revision: 62232
URL: http://svn.boost.org/trac/boost/changeset/62232
Log:
python_extensions - disabled Python no-arg construction for const_aware::proxy_class, added a useful shallow constructor with type checking.
Text files modified:
sandbox/python_extensions/TODO | 2 +-
sandbox/python_extensions/libs/python/src/proxy_class.cpp | 12 +++++++++++-
sandbox/python_extensions/libs/python/test/const_aware.cpp | 1 +
sandbox/python_extensions/libs/python/test/const_aware.py | 12 ++++++++++++
4 files changed, 25 insertions(+), 2 deletions(-)
Modified: sandbox/python_extensions/TODO
==============================================================================
--- sandbox/python_extensions/TODO (original)
+++ sandbox/python_extensions/TODO 2010-05-26 04:26:00 EDT (Wed, 26 May 2010)
@@ -1,7 +1,7 @@
const_aware:
- - check for in-Python construction of proxies (maybe needs to be disabled with something like no_init)
- smarter shared_ptr converter registration (take held_type into account)
- test subclasses and back-reference wrappers
+ - devise better workarounds to deal with lack of visitor support
- documentation!
to_python:
Modified: sandbox/python_extensions/libs/python/src/proxy_class.cpp
==============================================================================
--- sandbox/python_extensions/libs/python/src/proxy_class.cpp (original)
+++ sandbox/python_extensions/libs/python/src/proxy_class.cpp 2010-05-26 04:26:00 EDT (Wed, 26 May 2010)
@@ -45,8 +45,18 @@
}
static PyObject *
- proxy_instance_new(PyTypeObject* type_, PyObject* /*args*/, PyObject* /*kw*/) {
+ proxy_instance_new(PyTypeObject* type_, PyObject* args, PyObject* kw) {
+ static char * kwds[] = {const_cast<char*>("target"), NULL};
+ PyObject * target_type = PyObject_GetAttrString((PyObject*)type_, "__proxy_target__");
+ if (target_type == 0) return 0;
+ PyObject * target = 0;
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O!", kwds, target_type, &target))
+ return 0;
proxy_instance* result = (proxy_instance*)type_->tp_alloc(type_, 0);
+ if (result != 0) {
+ Py_INCREF(target);
+ result->target = target;
+ }
return (PyObject*)result;
}
Modified: sandbox/python_extensions/libs/python/test/const_aware.cpp
==============================================================================
--- sandbox/python_extensions/libs/python/test/const_aware.cpp (original)
+++ sandbox/python_extensions/libs/python/test/const_aware.cpp 2010-05-26 04:26:00 EDT (Wed, 26 May 2010)
@@ -43,6 +43,7 @@
static void export_module() {
bp::class_<Example> pyExample("Example");
+ pyExample.def(bp::init<Example const &>());
bp::make_const_aware(pyExample, "FrozenExample")
.add_property("address", &Example::get_address)
Modified: sandbox/python_extensions/libs/python/test/const_aware.py
==============================================================================
--- sandbox/python_extensions/libs/python/test/const_aware.py (original)
+++ sandbox/python_extensions/libs/python/test/const_aware.py 2010-05-26 04:26:00 EDT (Wed, 26 May 2010)
@@ -75,5 +75,17 @@
self.checkNonConst(by_shared_ptr)
self.checkConst(by_const_shared_ptr)
+ def testConstruction(self):
+ original = self.owner.by_value()
+ proxy = const_aware.FrozenExample(original)
+ self.assertEqual(original.address, original.address)
+ self.checkConst(proxy)
+ original_copy = const_aware.Example(original)
+ proxy_copy = const_aware.Example(proxy)
+ self.assertNotEqual(original.address, original_copy.address)
+ self.assertNotEqual(proxyx.address, proxy_copy.address)
+ self.checkNonConst(original_copy)
+ self.checkNonConst(proxy_copy)
+
if __name__=="__main__":
unittest.main()
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk