[pypy-commit] pypy reflex-support: From Rolf Aaij: test for a problem with basic_ostream instantation;
wlav
noreply at buildbot.pypy.org
Tue Aug 16 02:44:49 CEST 2011
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r46526:06817d10a83f
Date: 2011-08-15 15:24 -0700
http://bitbucket.org/pypy/pypy/changeset/06817d10a83f/
Log: From Rolf Aaij: test for a problem with basic_ostream instantation;
And a fix for said problem.
diff --git a/pypy/module/cppyy/capi/cint_capi.py b/pypy/module/cppyy/capi/cint_capi.py
--- a/pypy/module/cppyy/capi/cint_capi.py
+++ b/pypy/module/cppyy/capi/cint_capi.py
@@ -96,7 +96,7 @@
elidable_function=True)
c_base_offset = rffi.llexternal(
"cppyy_base_offset",
- [C_TYPEHANDLE, C_TYPEHANDLE], rffi.SIZE_T,
+ [C_TYPEHANDLE, C_TYPEHANDLE, C_OBJECT], rffi.SIZE_T,
compilation_info=eci,
elidable_function=True)
diff --git a/pypy/module/cppyy/capi/reflex_capi.py b/pypy/module/cppyy/capi/reflex_capi.py
--- a/pypy/module/cppyy/capi/reflex_capi.py
+++ b/pypy/module/cppyy/capi/reflex_capi.py
@@ -83,7 +83,7 @@
elidable_function=True)
c_base_offset = rffi.llexternal(
"cppyy_base_offset",
- [C_TYPEHANDLE, C_TYPEHANDLE], rffi.SIZE_T,
+ [C_TYPEHANDLE, C_TYPEHANDLE, C_OBJECT], rffi.SIZE_T,
compilation_info=eci,
elidable_function=True)
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -484,7 +484,8 @@
obj = space.interpclass_w(w_obj)
if isinstance(obj, W_CPPInstance):
if capi.c_is_subtype(obj.cppclass.handle, self.cpptype.handle):
- offset = capi.c_base_offset(obj.cppclass.handle, self.cpptype.handle)
+ offset = capi.c_base_offset(
+ obj.cppclass.handle, self.cpptype.handle, obj.rawobject)
obj_address = _direct_ptradd(obj.rawobject, offset)
return rffi.cast(rffi.VOIDP, obj_address)
raise OperationError(space.w_TypeError,
diff --git a/pypy/module/cppyy/include/capi.h b/pypy/module/cppyy/include/capi.h
--- a/pypy/module/cppyy/include/capi.h
+++ b/pypy/module/cppyy/include/capi.h
@@ -46,7 +46,7 @@
int cppyy_num_bases(cppyy_typehandle_t handle);
char* cppyy_base_name(cppyy_typehandle_t handle, int base_index);
int cppyy_is_subtype(cppyy_typehandle_t dh, cppyy_typehandle_t bh);
- size_t cppyy_base_offset(cppyy_typehandle_t dh, cppyy_typehandle_t bh);
+ size_t cppyy_base_offset(cppyy_typehandle_t dh, cppyy_typehandle_t bh, cppyy_object_t address);
/* method/function reflection information */
int cppyy_num_methods(cppyy_typehandle_t handle);
diff --git a/pypy/module/cppyy/interp_cppyy.py b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -281,10 +281,11 @@
class W_CPPDataMember(Wrappable):
- _immutable_fields_ = ["converter", "offset", "_is_static"]
+ _immutable_fields_ = ["scope", "converter", "offset", "_is_static"]
- def __init__(self, space, type_name, offset, is_static):
+ def __init__(self, space, scope, type_name, offset, is_static):
self.space = space
+ self.scope_handle = scope.handle
self.converter = converter.get_converter(self.space, type_name)
self.offset = offset
self._is_static = is_static
@@ -295,11 +296,22 @@
def is_static(self):
return self.space.newbool(self._is_static)
+ @jit.elidable_promote()
+ def _get_offset(self, w_cppinstance):
+ if self.space.is_true(w_cppinstance):
+ offset = self.offset + capi.c_base_offset(
+ w_cppinstance.cppclass.handle, self.scope_handle, w_cppinstance.rawobject)
+ else:
+ offset = self.offset
+ return offset
+
def get(self, w_cppinstance, w_type):
- return self.converter.from_memory(self.space, w_cppinstance, w_type, self.offset)
+ offset = self._get_offset(w_cppinstance)
+ return self.converter.from_memory(self.space, w_cppinstance, w_type, offset)
def set(self, w_cppinstance, w_value):
- self.converter.to_memory(self.space, w_cppinstance, w_value, self.offset)
+ offset = self._get_offset(w_cppinstance)
+ self.converter.to_memory(self.space, w_cppinstance, w_value, offset)
return self.space.w_None
W_CPPDataMember.typedef = TypeDef(
@@ -395,7 +407,7 @@
if not data_member_name in self.data_members:
type_name = capi.charp2str_free(capi.c_data_member_type(self.handle, i))
offset = capi.c_data_member_offset(self.handle, i)
- data_member = W_CPPDataMember(self.space, type_name, offset, True)
+ data_member = W_CPPDataMember(self.space, self, type_name, offset, True)
self.data_members[data_member_name] = data_member
def update(self):
@@ -445,7 +457,7 @@
type_name = capi.charp2str_free(capi.c_data_member_type(self.handle, i))
offset = capi.c_data_member_offset(self.handle, i)
is_static = bool(capi.c_is_staticdata(self.handle, i))
- data_member = W_CPPDataMember(self.space, type_name, offset, is_static)
+ data_member = W_CPPDataMember(self.space, self, type_name, offset, is_static)
self.data_members[data_member_name] = data_member
def is_namespace(self):
diff --git a/pypy/module/cppyy/src/cintcwrapper.cxx b/pypy/module/cppyy/src/cintcwrapper.cxx
--- a/pypy/module/cppyy/src/cintcwrapper.cxx
+++ b/pypy/module/cppyy/src/cintcwrapper.cxx
@@ -284,7 +284,7 @@
return crd->GetBaseClass(crb) != 0;
}
-size_t cppyy_base_offset(cppyy_typehandle_t dh, cppyy_typehandle_t bh) {
+size_t cppyy_base_offset(cppyy_typehandle_t dh, cppyy_typehandle_t bh, cppyy_object_t) {
if (dh == bh)
return 0;
TClassRef crd = type_from_handle(dh);
diff --git a/pypy/module/cppyy/src/reflexcwrapper.cxx b/pypy/module/cppyy/src/reflexcwrapper.cxx
--- a/pypy/module/cppyy/src/reflexcwrapper.cxx
+++ b/pypy/module/cppyy/src/reflexcwrapper.cxx
@@ -43,7 +43,7 @@
return arguments;
}
-static inline size_t base_offset(const Reflex::Type& td, const Reflex::Type& tb) {
+static inline size_t base_offset(const Reflex::Type& td, const Reflex::Type& tb, void* address) {
// when dealing with virtual inheritance the only (reasonably) well-defined info is
// in a Reflex internal base table, that contains all offsets within the hierarchy
Reflex::Member getbases = td.FunctionMemberByName(
@@ -56,13 +56,12 @@
for (Bases_t::iterator ibase = bases->begin(); ibase != bases->end(); ++ibase) {
if (ibase->first.ToType() == tb) {
- if (ibase->first.IsVirtual()) {
- Reflex::Object o = td.Construct();
+ if (ibase->first.IsVirtual() && address != NULL) {
+ Reflex::Object o(td, address);
size_t offset = ibase->first.Offset(o.Address());
- o.Destruct();
return offset;
} else
- return ibase->first.Offset(0);
+ return ibase->first.Offset(0);
}
}
@@ -256,12 +255,12 @@
return (int)td.HasBase(tb);
}
-size_t cppyy_base_offset(cppyy_typehandle_t dh, cppyy_typehandle_t bh) {
+size_t cppyy_base_offset(cppyy_typehandle_t dh, cppyy_typehandle_t bh, cppyy_object_t address) {
if (dh == bh)
return 0;
Reflex::Type td = type_from_handle(dh);
Reflex::Type tb = type_from_handle(bh);
- return (size_t)base_offset(td, tb);
+ return (size_t)base_offset(td, tb, (void*)address);
}
@@ -327,40 +326,33 @@
/* data member reflection information ------------------------------------- */
int cppyy_num_data_members(cppyy_typehandle_t handle) {
Reflex::Scope s = scope_from_handle(handle);
- return s.DataMemberSize(Reflex::INHERITEDMEMBERS_ALSO);
+ return s.DataMemberSize();
}
char* cppyy_data_member_name(cppyy_typehandle_t handle, int data_member_index) {
Reflex::Scope s = scope_from_handle(handle);
- Reflex::Member m = s.DataMemberAt(data_member_index, Reflex::INHERITEDMEMBERS_ALSO);
+ Reflex::Member m = s.DataMemberAt(data_member_index);
std::string name = m.Name();
return cppstring_to_cstring(name);
}
char* cppyy_data_member_type(cppyy_typehandle_t handle, int data_member_index) {
Reflex::Scope s = scope_from_handle(handle);
- Reflex::Member m = s.DataMemberAt(data_member_index, Reflex::INHERITEDMEMBERS_ALSO);
+ Reflex::Member m = s.DataMemberAt(data_member_index);
std::string name = m.TypeOf().Name(Reflex::FINAL|Reflex::SCOPED|Reflex::QUALIFIED);
return cppstring_to_cstring(name);
}
size_t cppyy_data_member_offset(cppyy_typehandle_t handle, int data_member_index) {
Reflex::Scope s = scope_from_handle(handle);
- Reflex::Member m = s.DataMemberAt(data_member_index, Reflex::INHERITEDMEMBERS_ALSO);
-
- if (s != m.DeclaringScope()) {
- // in case this data member is part of a base class, the offset is complicated
- // when dealing with virtual inheritance and needs to be calculated
- return base_offset(s, m.DeclaringType()) + m.Offset();
- }
-
+ Reflex::Member m = s.DataMemberAt(data_member_index);
return m.Offset();
}
int cppyy_is_staticdata(cppyy_typehandle_t handle, int data_member_index) {
Reflex::Scope s = scope_from_handle(handle);
- Reflex::Member m = s.DataMemberAt(data_member_index, Reflex::INHERITEDMEMBERS_ALSO);
+ Reflex::Member m = s.DataMemberAt(data_member_index);
return m.IsStatic();
}
diff --git a/pypy/module/cppyy/test/Makefile b/pypy/module/cppyy/test/Makefile
--- a/pypy/module/cppyy/test/Makefile
+++ b/pypy/module/cppyy/test/Makefile
@@ -1,4 +1,4 @@
-dicts = example01Dict.so datatypesDict.so advancedcppDict.so stltypesDict.so operatorsDict.so fragileDict.so
+dicts = example01Dict.so datatypesDict.so advancedcppDict.so stltypesDict.so operatorsDict.so fragileDict.so std_streamsDict.so
all : $(dicts)
ROOTSYS := ${ROOTSYS}
@@ -18,10 +18,10 @@
ifeq ($(shell $(genreflex) --help | grep -- --with-methptrgetter),)
genreflexflags=
- cppflags2=-O3
+ cppflags2=-O3 -fPIC
else
genreflexflags=--with-methptrgetter
- cppflags2=-Wno-pmf-conversions -O3
+ cppflags2=-Wno-pmf-conversions -O3 -fPIC
endif
%Dict.so: %_rflx.cpp %.cxx
@@ -44,6 +44,10 @@
$(genreflex) stltypes.h --selection=stltypes.xml
g++ -o $@ stltypes_rflx.cpp stltypes.cxx -shared -lReflex $(cppflags) $(cppflags2)
+std_streamsDict.so: std_streams.cxx std_streams.h std_streams.xml
+ $(genreflex) std_streams.h --selection=std_streams.xml
+ g++ -o $@ std_streams_rflx.cpp std_streams.cxx -shared -lReflex $(cppflags) $(cppflags2)
+
operatorsDict.so: operators.cxx operators.h operators.xml
$(genreflex) operators.h --selection=operators.xml
g++ -o $@ operators_rflx.cpp operators.cxx -shared -lReflex $(cppflags) $(cppflags2)
More information about the pypy-commit
mailing list