Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r62434:7cf1f9e13c4e
Date: 2013-03-18 18:41 -0700
http://bitbucket.org/pypy/pypy/changeset/7cf1f9e13c4e/
Log: bring std::map into CINT backend
diff --git a/pypy/module/cppyy/__init__.py b/pypy/module/cppyy/__init__.py
--- a/pypy/module/cppyy/__init__.py
+++ b/pypy/module/cppyy/__init__.py
@@ -10,6 +10,7 @@
'_resolve_name' : 'interp_cppyy.resolve_name',
'_scope_byname' : 'interp_cppyy.scope_byname',
'_template_byname' : 'interp_cppyy.template_byname',
+ '_std_string_name' : 'interp_cppyy.std_string_name',
'_set_class_generator' : 'interp_cppyy.set_class_generator',
'_register_class' : 'interp_cppyy.register_class',
'_is_static' : 'interp_cppyy.is_static',
diff --git a/pypy/module/cppyy/capi/__init__.py
b/pypy/module/cppyy/capi/__init__.py
--- a/pypy/module/cppyy/capi/__init__.py
+++ b/pypy/module/cppyy/capi/__init__.py
@@ -7,6 +7,7 @@
identify = backend.identify
pythonize = backend.pythonize
register_pythonizations = backend.register_pythonizations
+std_string_name = backend.std_string_name
ts_reflect = backend.ts_reflect
ts_call = backend.ts_call
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
@@ -10,7 +10,7 @@
from rpython.rlib import libffi, rdynload
-__all__ = ['identify', 'eci', 'c_load_dictionary']
+__all__ = ['identify', 'std_string_name', 'eci', 'c_load_dictionary']
pkgpath = py.path.local(__file__).dirpath().join(os.pardir)
srcpath = pkgpath.join("src")
@@ -37,6 +37,8 @@
ts_memory = False
ts_helper = False
+std_string_name = 'string'
+
# force loading in global mode of core libraries, rather than linking with
# them as PyPy uses various version of dlopen in various places; note that
# this isn't going to fly on Windows (note that locking them in objects and
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
@@ -3,7 +3,7 @@
from rpython.rlib import libffi
from rpython.translator.tool.cbuild import ExternalCompilationInfo
-__all__ = ['identify', 'eci', 'c_load_dictionary']
+__all__ = ['identify', 'std_string_name', 'eci', 'c_load_dictionary']
pkgpath = py.path.local(__file__).dirpath().join(os.pardir)
srcpath = pkgpath.join("src")
@@ -35,6 +35,8 @@
ts_memory = 'auto'
ts_helper = 'auto'
+std_string_name = 'std::basic_string<char>'
+
eci = ExternalCompilationInfo(
separate_module_files=[srcpath.join("reflexcwrapper.cxx")],
include_dirs=[incpath] + rootincpath,
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
@@ -82,6 +82,9 @@
return None
+def std_string_name(space):
+ return space.wrap(capi.std_string_name)
+
@unwrap_spec(w_callback=W_Root)
def set_class_generator(space, w_callback):
state = space.fromcache(State)
diff --git a/pypy/module/cppyy/pythonify.py b/pypy/module/cppyy/pythonify.py
--- a/pypy/module/cppyy/pythonify.py
+++ b/pypy/module/cppyy/pythonify.py
@@ -36,7 +36,7 @@
def _arg_to_str(self, arg):
if arg == str:
- arg = 'std::basic_string<char>'
+ arg = cppyy._std_string_name()
elif type(arg) != str:
arg = arg.__name__
return arg
@@ -336,8 +336,8 @@
else:
pyclass.__getitem__ = python_style_getitem
- # string comparisons (note: CINT backend requires the simple name 'string')
- if pyclass.__name__ == 'std::basic_string<char>' or pyclass.__name__ ==
'string':
+ # string comparisons
+ if pyclass.__name__ == cppyy._std_string_name():
def eq(self, other):
if type(other) == pyclass:
return self.c_str() == other.c_str()
@@ -347,7 +347,7 @@
pyclass.__str__ = pyclass.c_str
# std::pair unpacking through iteration
- if 'std::pair' in pyclass.__name__:
+ if 'std::pair' == pyclass.__name__[:9] or 'pair' == pyclass.__name__[:4]:
def getitem(self, idx):
if idx == 0: return self.first
if idx == 1: return self.second
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
@@ -310,6 +310,10 @@
if (!G__defined_templateclass((char*)template_name))
return (cppyy_type_t)NULL;
+ // #include for specific, pre-compiled STL classes
+ if (strcmp(template_name, "std::map") == 0)
+ gROOT->ProcessLine("#include <map>");
+
// the following yields a dummy TClassRef, but its name can be queried
ClassRefs_t::size_type sz = g_classrefs.size();
g_classref_indices[template_name] = sz;
diff --git a/pypy/module/cppyy/test/stltypes.h
b/pypy/module/cppyy/test/stltypes.h
--- a/pypy/module/cppyy/test/stltypes.h
+++ b/pypy/module/cppyy/test/stltypes.h
@@ -74,7 +74,9 @@
struct _CppyyMapInstances {
+#ifndef __CINT__
STLTYPE_INSTANTIATION2(map, int, int, 1);
+#endif
STLTYPE_INSTANTIATION2(map, std::string, int, 2);
STLTYPE_INSTANTIATION2(map, std::string, unsigned int, 3);
STLTYPE_INSTANTIATION2(map, std::string, unsigned long, 4);
diff --git a/pypy/module/cppyy/test/stltypes_LinkDef.h
b/pypy/module/cppyy/test/stltypes_LinkDef.h
--- a/pypy/module/cppyy/test/stltypes_LinkDef.h
+++ b/pypy/module/cppyy/test/stltypes_LinkDef.h
@@ -8,7 +8,18 @@
#pragma link C++ class std::vector<just_a_class>::iterator;
#pragma link C++ class std::vector<just_a_class>::const_iterator;
+#pragma link C++ class map<std::string, unsigned int>;
+#pragma link C++ class map<std::string, unsigned int>::iterator;
+#pragma link C++ class map<std::string, unsigned int>::const_iterator;
+#pragma link C++ class pair<std::string, unsigned int>;
+
+#pragma link C++ class map<std::string, unsigned long>;
+#pragma link C++ class map<std::string, unsigned long>::iterator;
+#pragma link C++ class map<std::string, unsigned long>::const_iterator;
+#pragma link C++ class pair<std::string, unsigned long>;
+
#pragma link C++ class just_a_class;
#pragma link C++ class stringy_class;
+#pragma link C++ class stl_like_class<int>;
#endif
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit