[pypy-svn] r75847 - in pypy/branch/reflex-support/pypy/module/cppyy: . include src test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Jul 5 19:09:54 CEST 2010
Author: cfbolz
Date: Mon Jul 5 19:09:53 2010
New Revision: 75847
Modified:
pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h
pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py
pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx
pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx
pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py
Log:
(antocuni, cfbolz, wlav, arigo): call the destructor too.
Modified: pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/include/reflexcwrapper.h Mon Jul 5 19:09:53 2010
@@ -4,8 +4,9 @@
extern "C" {
long callstatic_l(const char* class_name, const char* method_name, int numargs, void* args[]);
- void* construct(const char* class_name, int numargs, void* args[]);
long callmethod_l(const char* class_name, const char* method_name, void* self, int numargs, void* args[]);
+ void* construct(const char* class_name, int numargs, void* args[]);
+ void destruct(const char* class_name, void* self);
}
#endif // ifndef CPPYY_REFLEXCWRAPPER
Modified: pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py Mon Jul 5 19:09:53 2010
@@ -36,6 +36,10 @@
"callmethod_l",
[rffi.CCHARP, rffi.CCHARP, rffi.VOIDP, rffi.INT, rffi.VOIDPP], rffi.LONG,
compilation_info=eci)
+destruct = rffi.llexternal(
+ "destruct",
+ [rffi.CCHARP, rffi.VOIDP], lltype.Void,
+ compilation_info=eci)
@@ -111,8 +115,11 @@
free_arguments(args, len(args_w))
return self.space.wrap(result)
+ def destruct(self):
+ destruct(self.cppclass.name, self.rawobject)
W_CPPObject.typedef = TypeDef(
'CPPObject',
invoke = interp2app(W_CPPObject.invoke, unwrap_spec=['self', str, 'args_w']),
+ destruct = interp2app(W_CPPObject.destruct, unwrap_spec=['self']),
)
Modified: pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/src/reflexcwrapper.cxx Mon Jul 5 19:09:53 2010
@@ -33,12 +33,9 @@
Reflex::Type constructor_type = Reflex::FunctionTypeBuilder(
Reflex::Type::ByName("void"), argtypes);
return t.Construct(constructor_type, arguments).Address();
- void* mem = t.Allocate();
- memset(mem, 41, t.SizeOf());
- Reflex::Object r = Reflex::Object(t, mem);
- int i = 1;
- std::cout << t.FunctionMemberAt(i).Name() << std::endl;
- t.FunctionMemberAt(i).Invoke(r, 0, arguments);
- return r.Address();
}
+void destruct(const char* class_name, void* self) {
+ Reflex::Type t = Reflex::Type::ByName(class_name);
+ t.Destruct(self, true);
+}
Modified: pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx Mon Jul 5 19:09:53 2010
@@ -2,15 +2,40 @@
class example01 {
public:
+ static int count;
int somedata;
+
+ example01() : somedata(-99) {
+ count++;
+ }
example01(int a) : somedata(a) {
+ count++;
std::cout << "constructor called" << std::endl;
}
+ example01(const example01& e) : somedata(e.somedata) {
+ count++;
+ std::cout << "copy constructor called" << std::endl;
+ }
+ example01& operator=(const example01& e) {
+ if (this != &e) {
+ somedata = e.somedata;
+ }
+ return *this;
+ }
+ ~example01() {
+ count--;
+ }
static int add1(int a) {
return a + 1;
}
+ static int getcount() {
+ std::cout << "getcount called" << std::endl;
+ return count;
+ }
int add(int a) {
return somedata + a;
}
};
+
+int example01::count = 0;
Modified: pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py Mon Jul 5 19:09:53 2010
@@ -19,6 +19,13 @@
def test_example01method(self):
t = self.example01.type_byname("example01")
+ count = t.invoke("getcount")
+ assert count == 0
instance = t.construct(7)
+ count = t.invoke("getcount")
+ assert count == 1
res = instance.invoke("add", 4)
assert res == 11
+ instance.destruct()
+ count = t.invoke("getcount")
+ assert count == 0
More information about the Pypy-commit
mailing list