[pypy-commit] pypy cling-support: from Aditi: resolve std::string ctor overload with length

2016-08-15 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86207:eb960a97982c
Date: 2016-08-15 17:03 -0700
http://bitbucket.org/pypy/pypy/changeset/eb960a97982c/

Log:from Aditi: resolve std::string ctor overload with length

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
@@ -17,10 +17,11 @@
 pass
 
 # overload priorities: lower is preferred
-priority = { 'void*'  : 100,
- 'void**' : 100,
- 'float'  :  30,
- 'double' :  10, }
+priority = { 'void*' : 100,
+ 'void**': 100,
+ 'float' :  30,
+ 'double':  10,
+ 'const string&' :   1, } # solves a specific string ctor overload
 
 from rpython.rlib.listsort import make_timsort_class
 CPPMethodBaseTimSort = make_timsort_class()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: from Aditi (modified): allow passing of strings with \0 in them

2016-08-15 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86208:7f130da8dc67
Date: 2016-08-15 17:09 -0700
http://bitbucket.org/pypy/pypy/changeset/7f130da8dc67/

Log:from Aditi (modified): allow passing of strings with \0 in them

diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -158,11 +158,15 @@
 return _c_call_r(cppmethod, cppobject, nargs, args)
 _c_call_s = rffi.llexternal(
 "cppyy_call_s",
-[C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.CCHARP,
+[C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP, rffi.INTP], rffi.CCHARP,
 releasegil=ts_call,
 compilation_info=backend.eci)
 def c_call_s(space, cppmethod, cppobject, nargs, args):
-return _c_call_s(cppmethod, cppobject, nargs, args)
+length = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
+cstr = _c_call_s(cppmethod, cppobject, nargs, args, length)
+cstr_len = int(length[0])
+lltype.free(length, flavor='raw')
+return cstr, cstr_len
 
 _c_constructor = rffi.llexternal(
 "cppyy_constructor",
diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -146,7 +146,8 @@
 'call_d'   : ([c_method, c_object, c_int, c_voidp],   
c_double),
 
 'call_r'   : ([c_method, c_object, c_int, c_voidp],   c_voidp),
-'call_s'   : ([c_method, c_object, c_int, c_voidp],   
c_ccharp),
+# call_s actually takes an intp as last parameter, but this will do
+'call_s'   : ([c_method, c_object, c_int, c_voidp, c_voidp],   
 c_ccharp),
 
 'constructor'  : ([c_method, c_object, c_int, c_voidp],   
c_object),
 'call_o'   : ([c_method, c_object, c_int, c_voidp, c_type],
 c_object),
@@ -336,8 +337,12 @@
 args = [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs)]
 return _cdata_to_ptr(space, call_capi(space, 'call_r', args))
 def c_call_s(space, cppmethod, cppobject, nargs, cargs):
-args = [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs)]
-return call_capi(space, 'call_s', args)
+length = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
+args = [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs), _Args(vp=length)]
+cstr = call_capi(space, 'call_s', args)
+cstr_len = int(length[0])
+lltype.free(length, flavor='raw')
+return cstr, cstr_len
 
 def c_constructor(space, cppmethod, cppobject, nargs, cargs):
 args = [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs)]
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -195,8 +195,10 @@
 class StdStringExecutor(InstancePtrExecutor):
 
 def execute(self, space, cppmethod, cppthis, num_args, args):
-cstr_result = capi.c_call_s(space, cppmethod, cppthis, num_args, args)
-return space.wrap(capi.charp2str_free(space, cstr_result))
+cstr, cstr_len = capi.c_call_s(space, cppmethod, cppthis, num_args, 
args)
+string = rffi.charpsize2str(cstr, cstr_len)
+capi.c_free(rffi.cast(rffi.VOIDP, cstr))
+return space.wrap(string)
 
 def execute_libffi(self, space, cif_descr, funcaddr, buffer):
 from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
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
@@ -59,7 +59,7 @@
 RPY_EXTERN
 void*  cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs, 
void* args);
 RPY_EXTERN
-char*  cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, 
void* args);
+char*  cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, 
void* args, int* length);
 
 RPY_EXTERN
 cppyy_object_t cppyy_constructor(cppyy_method_t method, cppyy_type_t 
klass, int nargs, void* args);
diff --git a/pypy/module/cppyy/include/cpp_cppyy.h 
b/pypy/module/cppyy/include/cpp_cppyy.h
--- a/pypy/module/cppyy/include/cpp_cppyy.h
+++ b/pypy/module/cppyy/include/cpp_cppyy.h
@@ -62,7 +62,7 @@
Double_t CallD( TCppMethod_t method, TCppObject_t self, void* args );
LongDouble_t CallLD( TCppMethod_t method, TCppObject_t self, void* args );
void*CallR( TCppMethod_t method, TCppObject_t self, void* args );
-   Char_t*  CallS( TCppMethod_t method, TCppObject_t self, void* args );
+   Char_t*  CallS( TCppMethod_t method, TCppObject_t self, void* args, 
int* length );
TCppObject_t CallConstructor( TCppMethod_t method, TCppType_t type, void* 
args );
void CallDestructor( TCppType_t type, TCppObject_t self );
TCppObject_t CallO( TCppMethod_t method, TCppObject_t 

[pypy-commit] pypy cling-support: refactored changs from Aditi: all string tests now pass

2016-08-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86234:8d97e46d038c
Date: 2016-08-16 15:40 -0700
http://bitbucket.org/pypy/pypy/changeset/8d97e46d038c/

Log:refactored changs from Aditi: all string tests now pass

diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -158,14 +158,16 @@
 return _c_call_r(cppmethod, cppobject, nargs, args)
 _c_call_s = rffi.llexternal(
 "cppyy_call_s",
-[C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP, rffi.INTP], rffi.CCHARP,
+[C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP, rffi.SIZE_TP], rffi.CCHARP,
 releasegil=ts_call,
 compilation_info=backend.eci)
 def c_call_s(space, cppmethod, cppobject, nargs, args):
-length = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
-cstr = _c_call_s(cppmethod, cppobject, nargs, args, length)
-cstr_len = int(length[0])
-lltype.free(length, flavor='raw')
+length = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
+try:
+cstr = _c_call_s(cppmethod, cppobject, nargs, args, length)
+cstr_len = int(length[0])
+finally:
+lltype.free(length, flavor='raw')
 return cstr, cstr_len
 
 _c_constructor = rffi.llexternal(
@@ -548,11 +550,11 @@
 [rffi.CCHARP, rffi.SIZE_T], C_OBJECT,
 releasegil=ts_helper,
 compilation_info=backend.eci)
-def c_charp2stdstring(space, svalue, sz):
-charp = rffi.str2charp(svalue)
-result = _c_charp2stdstring(charp, sz)
-rffi.free_charp(charp)
-return result
+def c_charp2stdstring(space, pystr, sz):
+cstr = rffi.str2charp(pystr)
+cppstr = _c_charp2stdstring(cstr, sz)
+rffi.free_charp(cstr)
+return cppstr
 _c_stdstring2stdstring = rffi.llexternal(
 "cppyy_stdstring2stdstring",
 [C_OBJECT], C_OBJECT,
diff --git a/pypy/module/cppyy/capi/cling_capi.py 
b/pypy/module/cppyy/capi/cling_capi.py
--- a/pypy/module/cppyy/capi/cling_capi.py
+++ b/pypy/module/cppyy/capi/cling_capi.py
@@ -1,9 +1,13 @@
 import py, os
 
+from pypy.interpreter.gateway import interp2app, unwrap_spec
+
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.rtyper.lltypesystem import rffi
+from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib import libffi, rdynload
 
+from pypy.module.cppyy.capi.capi_types import C_OBJECT
+
 __all__ = ['identify', 'std_string_name', 'eci', 'c_load_dictionary']
 
 pkgpath = py.path.local(__file__).dirpath().join(os.pardir)
@@ -68,11 +72,42 @@
 pch = _c_load_dictionary(name)
 return pch
 
+_c_stdstring2charp = rffi.llexternal(
+"cppyy_stdstring2charp",
+[C_OBJECT, rffi.SIZE_TP], rffi.CCHARP,
+releasegil=ts_helper,
+compilation_info=eci)
+def c_stdstring2charp(space, cppstr):
+sz = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
+try:
+cstr = _c_stdstring2charp(cppstr, sz)
+cstr_len = int(sz[0])
+finally:
+lltype.free(sz, flavor='raw')
+return rffi.charpsize2str(cstr, cstr_len)
 
-# Cling-specific pythonizations
+# pythonizations
+def stdstring_c_str(space, w_self):
+"""Return a python string taking into account \0"""
+
+from pypy.module.cppyy import interp_cppyy
+cppstr = space.interp_w(interp_cppyy.W_CPPInstance, w_self, 
can_be_None=False)
+return space.wrap(c_stdstring2charp(space, cppstr._rawobject))
+
+# setup pythonizations for later use at run-time
+_pythonizations = {}
 def register_pythonizations(space):
 "NOT_RPYTHON"
-pass
+
+allfuncs = [
+
+### std::string
+stdstring_c_str,
+
+]
+
+for f in allfuncs:
+_pythonizations[f.__name__] = space.wrap(interp2app(f))
 
 def _method_alias(space, w_pycppclass, m1, m2):
 space.setattr(w_pycppclass, space.wrap(m1),
@@ -80,4 +115,6 @@
 
 def pythonize(space, name, w_pycppclass):
 if name == "string":
+space.setattr(w_pycppclass, space.wrap("c_str"), 
_pythonizations["stdstring_c_str"])
 _method_alias(space, w_pycppclass, "_cppyy_as_builtin", "c_str")
+_method_alias(space, w_pycppclass, "__str__",   "c_str")
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
@@ -59,7 +59,7 @@
 RPY_EXTERN
 void*  cppyy_call_r(cppyy_method_t method, cppyy_object_t self, int nargs, 
void* args);
 RPY_EXTERN
-char*  cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, 
void* args, int* length);
+char*  cppyy_call_s(cppyy_method_t method, cppyy_object_t self, int nargs, 
void* args, size_t* length);
 
 RPY_EXTERN
 cppyy_object_t cppyy_constructor(cppyy_method_t method, cppyy_type_t 
klass, int nargs, void* args);
@@ -179,6 +179,8 @@
 RPY_EXTERN
 cppyy_object_t cppyy_charp2stdstring(const char* str, size_t sz);
 RPY_EXTERN
+char* cppyy_stdstring2charp(cppyy_object_t ptr, size_t* lsz);
+

[pypy-commit] pypy cling-support: from Aditi: loadable_capi fixes

2016-08-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86235:373896495865
Date: 2016-08-16 15:56 -0700
http://bitbucket.org/pypy/pypy/changeset/373896495865/

Log:from Aditi: loadable_capi fixes

diff --git a/pypy/module/cppyy/capi/cling_capi.py 
b/pypy/module/cppyy/capi/cling_capi.py
--- a/pypy/module/cppyy/capi/cling_capi.py
+++ b/pypy/module/cppyy/capi/cling_capi.py
@@ -86,6 +86,7 @@
 lltype.free(sz, flavor='raw')
 return rffi.charpsize2str(cstr, cstr_len)
 
+# TODO: factor these out ...
 # pythonizations
 def stdstring_c_str(space, w_self):
 """Return a python string taking into account \0"""
diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -146,7 +146,7 @@
 'call_d'   : ([c_method, c_object, c_int, c_voidp],   
c_double),
 
 'call_r'   : ([c_method, c_object, c_int, c_voidp],   c_voidp),
-# call_s actually takes an intp as last parameter, but this will do
+# call_s actually takes an size_t* as last parameter, but this 
will do
 'call_s'   : ([c_method, c_object, c_int, c_voidp, c_voidp],   
 c_ccharp),
 
 'constructor'  : ([c_method, c_object, c_int, c_voidp],   
c_object),
@@ -337,8 +337,8 @@
 args = [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs)]
 return _cdata_to_ptr(space, call_capi(space, 'call_r', args))
 def c_call_s(space, cppmethod, cppobject, nargs, cargs):
-length = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
-args = [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs), _Args(vp=length)]
+length = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
+args = [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs), _Arg(vp=length)]
 cstr = call_capi(space, 'call_s', args)
 cstr_len = int(length[0])
 lltype.free(length, flavor='raw')
@@ -373,7 +373,7 @@
 return space.bool_w(call_capi(space, 'is_namespace', [_Arg(h=scope)]))
 def c_is_template(space, name):
 return space.bool_w(call_capi(space, 'is_template', [_Arg(s=name)]))
-def c_is_abstract(space, scope):
+def c_is_abstract(space, cpptype):
 return space.bool_w(call_capi(space, 'is_abstract', [_Arg(h=cpptype)]))
 def c_is_enum(space, name):
 return space.bool_w(call_capi(space, 'is_enum', [_Arg(s=name)]))
@@ -525,13 +525,53 @@
 def c_charp2stdstring(space, svalue, sz):
 return _cdata_to_cobject(
 space, call_capi(space, 'charp2stdstring', [_Arg(s=svalue), 
_Arg(l=sz)]))
+_c_stdstring2charp = rffi.llexternal(
+"cppyy_stdstring2charp",
+[C_OBJECT, rffi.SIZE_TP], rffi.CCHARP,
+releasegil=ts_helper,
+compilation_info=eci)
+def c_stdstring2charp(space, cppstr):
+sz = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
+try:
+cstr = call_capi(space, 'stdstring2charp', [_Arg(h=cppstr), 
_Arg(vp=sz)])
+cstr_len = int(sz[0])
+finally:
+lltype.free(sz, flavor='raw')
+return rffi.charpsize2str(cstr, cstr_len)
 def c_stdstring2stdstring(space, cppobject):
 return _cdata_to_cobject(space, call_capi(space, 'stdstring2stdstring', 
[_Arg(h=cppobject)]))
 
-# loadable-capi-specific pythonizations (none, as the capi isn't known until 
runtime)
+
+# TODO: factor these out ...
+# pythonizations
+def stdstring_c_str(space, w_self):
+"""Return a python string taking into account \0"""
+
+from pypy.module.cppyy import interp_cppyy
+cppstr = space.interp_w(interp_cppyy.W_CPPInstance, w_self, 
can_be_None=False)
+return space.wrap(c_stdstring2charp(space, cppstr._rawobject))
+
+# setup pythonizations for later use at run-time
+_pythonizations = {}
 def register_pythonizations(space):
 "NOT_RPYTHON"
-pass
+
+allfuncs = [
+
+### std::string
+stdstring_c_str,
+
+]
+
+for f in allfuncs:
+_pythonizations[f.__name__] = space.wrap(interp2app(f))
+
+def _method_alias(space, w_pycppclass, m1, m2):
+space.setattr(w_pycppclass, space.wrap(m1),
+  space.getattr(w_pycppclass, space.wrap(m2)))
 
 def pythonize(space, name, w_pycppclass):
-pass
+if name == "string":
+space.setattr(w_pycppclass, space.wrap("c_str"), 
_pythonizations["stdstring_c_str"])
+_method_alias(space, w_pycppclass, "_cppyy_as_builtin", "c_str")
+_method_alias(space, w_pycppclass, "__str__",   "c_str")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: cleanup

2016-08-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86236:4333bf213e97
Date: 2016-08-16 16:41 -0700
http://bitbucket.org/pypy/pypy/changeset/4333bf213e97/

Log:cleanup

diff --git a/pypy/module/cppyy/capi/cling_capi.py 
b/pypy/module/cppyy/capi/cling_capi.py
--- a/pypy/module/cppyy/capi/cling_capi.py
+++ b/pypy/module/cppyy/capi/cling_capi.py
@@ -1,6 +1,6 @@
 import py, os
 
-from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app
 
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.rtyper.lltypesystem import rffi, lltype
diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -3,6 +3,7 @@
 from rpython.rlib.rarithmetic import r_singlefloat
 from rpython.tool import leakfinder
 
+from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.error import oefmt
 
 from pypy.module._cffi_backend import ctypefunc, ctypeprim, cdataobj, misc
@@ -218,6 +219,8 @@
 'free' : ([c_voidp],  c_void),
 
 'charp2stdstring'  : ([c_ccharp, c_size_t],   
c_object),
+#stdstring2charp  actually takes an size_t* as last parameter, but 
this will do
+'stdstring2charp'  : ([c_ccharp, c_voidp],
c_ccharp),
 'stdstring2stdstring'  : ([c_object], 
c_object),
 }
 
@@ -525,11 +528,6 @@
 def c_charp2stdstring(space, svalue, sz):
 return _cdata_to_cobject(
 space, call_capi(space, 'charp2stdstring', [_Arg(s=svalue), 
_Arg(l=sz)]))
-_c_stdstring2charp = rffi.llexternal(
-"cppyy_stdstring2charp",
-[C_OBJECT, rffi.SIZE_TP], rffi.CCHARP,
-releasegil=ts_helper,
-compilation_info=eci)
 def c_stdstring2charp(space, cppstr):
 sz = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
 try:
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
@@ -179,7 +179,7 @@
 RPY_EXTERN
 cppyy_object_t cppyy_charp2stdstring(const char* str, size_t sz);
 RPY_EXTERN
-char* cppyy_stdstring2charp(cppyy_object_t ptr, size_t* lsz);
+const char* cppyy_stdstring2charp(cppyy_object_t ptr, size_t* lsz);
 RPY_EXTERN
 cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr);
 
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -1467,9 +1467,9 @@
 return (cppyy_object_t)new std::string(str, sz);
 }
 
-char* cppyy_stdstring2charp(cppyy_object_t ptr, size_t* lsz) {
+const char* cppyy_stdstring2charp(cppyy_object_t ptr, size_t* lsz) {
 *lsz = ((std::string*)ptr)->size();
-return (char*)((std::string*)ptr)->data();
+return ((std::string*)ptr)->data();
 }
 
 cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr){
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: raise same type exception if all overloads return that type; otherwise TypeError

2016-08-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86237:b71f0b85c644
Date: 2016-08-16 16:41 -0700
http://bitbucket.org/pypy/pypy/changeset/b71f0b85c644/

Log:raise same type exception if all overloads return that type;
otherwise TypeError

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
@@ -544,6 +544,8 @@
 errmsg = 'none of the %d overloaded methods succeeded. Full details:' 
% len(self.functions)
 if hasattr(self.space, "fake"): # FakeSpace fails errorstr (see 
below)
 raise OperationError(self.space.w_TypeError, 
self.space.wrap(errmsg))
+w_exc_type = None
+all_same_type = True
 for i in range(len(self.functions)):
 cppyyfunc = self.functions[i]
 try:
@@ -552,6 +554,10 @@
 # special case if there's just one function, to prevent 
clogging the error message
 if len(self.functions) == 1:
 raise
+if w_exc_type is None:
+w_exc_type = e.w_type
+elif all_same_type and not e.match(self.space, w_exc_type):
+all_same_type = False
 errmsg += '\n  '+cppyyfunc.signature()+' =>\n'
 errmsg += ''+e.errorstr(self.space)
 except Exception as e:
@@ -560,7 +566,10 @@
 errmsg += '\n  '+cppyyfunc.signature()+' =>\n'
 errmsg += 'Exception: '+str(e)
 
-raise OperationError(self.space.w_TypeError, self.space.wrap(errmsg))
+if all_same_type and w_exc_type is not None:
+raise OperationError(w_exc_type, self.space.wrap(errmsg))
+else:
+raise OperationError(self.space.w_TypeError, 
self.space.wrap(errmsg))
 
 def signature(self):
 sig = self.functions[0].signature()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: link examples with -lCore for the benefit of loadable_capi.py

2016-08-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86238:6c2423d9357d
Date: 2016-08-16 17:01 -0700
http://bitbucket.org/pypy/pypy/changeset/6c2423d9357d/

Log:link examples with -lCore for the benefit of loadable_capi.py

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
@@ -19,7 +19,7 @@
 cppflags=-pthread -std=c++11 -m64 -I./include -L./lib64 -L./lib
   else
 genreflex=$(ROOTSYS)/bin/genreflex
-cppflags=$(shell $(ROOTSYS)/bin/root-config --cflags) $(shell 
$(ROOTSYS)/bin/root-config --ldflags)
+cppflags=$(shell $(ROOTSYS)/bin/root-config --cflags) $(shell 
$(ROOTSYS)/bin/root-config --ldflags) -L$(shell $(ROOTSYS)/bin/root-config 
--libdir) -lCore
   endif
 endif
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: fix string handling for the loadable capi

2016-08-18 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86295:4831e0f5b4d5
Date: 2016-08-18 13:41 -0700
http://bitbucket.org/pypy/pypy/changeset/4831e0f5b4d5/

Log:fix string handling for the loadable capi

diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -354,7 +354,7 @@
 i += 1
 py_indices.append(index)
 index = indices[i]
-c_free(rffi.cast(rffi.VOIDP, indices))   # c_free defined below
+c_free(space, rffi.cast(rffi.VOIDP, indices))  # c_free defined below
 return py_indices
 
 _c_method_name = rffi.llexternal(
@@ -533,16 +533,18 @@
 compilation_info=backend.eci)
 def c_strtoull(space, svalue):
 return _c_strtoull(svalue)
-c_free = rffi.llexternal(
+_c_free = rffi.llexternal(
 "cppyy_free",
 [rffi.VOIDP], lltype.Void,
 releasegil=ts_memory,
 compilation_info=backend.eci)
+def c_free(space, voidp):
+return _c_free(voidp)
 
 def charp2str_free(space, charp):
 string = rffi.charp2str(charp)
 voidp = rffi.cast(rffi.VOIDP, charp)
-c_free(voidp)
+_c_free(voidp)
 return string
 
 _c_charp2stdstring = rffi.llexternal(
diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -220,7 +220,7 @@
 
 'charp2stdstring'  : ([c_ccharp, c_size_t],   
c_object),
 #stdstring2charp  actually takes an size_t* as last parameter, but 
this will do
-'stdstring2charp'  : ([c_ccharp, c_voidp],
c_ccharp),
+'stdstring2charp'  : ([c_object, c_voidp],
c_ccharp),
 'stdstring2stdstring'  : ([c_object], 
c_object),
 }
 
@@ -281,6 +281,10 @@
 ptr = w_cdata.unsafe_escaping_ptr()
 return rffi.cast(rffi.VOIDP, ptr)
 
+def _cdata_to_ccharp(space, w_cdata):
+ptr = _cdata_to_ptr(space, w_cdata)  # see above ... something better?
+return rffi.cast(rffi.CCHARP, ptr)
+
 def c_load_dictionary(name):
 return libffi.CDLL(name)
 
@@ -341,11 +345,14 @@
 return _cdata_to_ptr(space, call_capi(space, 'call_r', args))
 def c_call_s(space, cppmethod, cppobject, nargs, cargs):
 length = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
-args = [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs), _Arg(vp=length)]
-cstr = call_capi(space, 'call_s', args)
-cstr_len = int(length[0])
-lltype.free(length, flavor='raw')
-return cstr, cstr_len
+try:
+w_cstr = call_capi(space, 'call_s',
+[_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs),
+ _Arg(vp=rffi.cast(rffi.VOIDP, length))])
+cstr_len = int(length[0])
+finally:
+lltype.free(length, flavor='raw')
+return _cdata_to_ccharp(space, w_cstr), cstr_len
 
 def c_constructor(space, cppmethod, cppobject, nargs, cargs):
 args = [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs)]
@@ -527,15 +534,16 @@
 
 def c_charp2stdstring(space, svalue, sz):
 return _cdata_to_cobject(
-space, call_capi(space, 'charp2stdstring', [_Arg(s=svalue), 
_Arg(l=sz)]))
+space, call_capi(space, 'charp2stdstring', [_Arg(s=svalue), 
_Arg(h=sz)]))
 def c_stdstring2charp(space, cppstr):
 sz = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
 try:
-cstr = call_capi(space, 'stdstring2charp', [_Arg(h=cppstr), 
_Arg(vp=sz)])
+w_cstr = call_capi(space, 'stdstring2charp',
+[_Arg(h=cppstr), _Arg(vp=rffi.cast(rffi.VOIDP, sz))])
 cstr_len = int(sz[0])
 finally:
 lltype.free(sz, flavor='raw')
-return rffi.charpsize2str(cstr, cstr_len)
+return rffi.charpsize2str(_cdata_to_ccharp(space, w_cstr), cstr_len)
 def c_stdstring2stdstring(space, cppobject):
 return _cdata_to_cobject(space, call_capi(space, 'stdstring2stdstring', 
[_Arg(h=cppobject)]))
 
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -196,9 +196,9 @@
 
 def execute(self, space, cppmethod, cppthis, num_args, args):
 cstr, cstr_len = capi.c_call_s(space, cppmethod, cppthis, num_args, 
args)
-string = rffi.charpsize2str(cstr, cstr_len)
-capi.c_free(rffi.cast(rffi.VOIDP, cstr))
-return space.wrap(string)
+pystr = rffi.charpsize2str(cstr, cstr_len)
+capi.c_free(space, rffi.cast(rffi.VOIDP, cstr))
+return space.wrap(pystr)
 
 def execute_libffi(self, space, cif_descr, funcaddr, buffer):
 from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: change handling of std; fixes access to cout

2016-08-18 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86296:1eaa1b5ee34f
Date: 2016-08-18 14:17 -0700
http://bitbucket.org/pypy/pypy/changeset/1eaa1b5ee34f/

Log:change handling of std; fixes access to cout

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
@@ -440,7 +440,7 @@
 gbl = make_cppnamespace(None, "::", None, False)   # global C++ namespace
 gbl.__doc__ = "Global C++ namespace."
 
-# mostly for the benefit of the CINT backend, which treats std as special
+# pre-create std to allow direct importing
 gbl.std = make_cppnamespace(None, "std", None, False)
 
 # install a type for enums to refer to
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -70,9 +70,10 @@
   assert( g_classrefs.size() == GLOBAL_HANDLE );
   g_name2classrefidx[ "" ]  = GLOBAL_HANDLE;
   g_classrefs.push_back(TClassRef(""));
-  // ROOT ignores std/::std, so point them to the global namespace
-  g_name2classrefidx[ "std" ]   = GLOBAL_HANDLE;
-  g_name2classrefidx[ "::std" ] = GLOBAL_HANDLE;
+  // aliases for std (setup already in pythonify)
+  g_name2classrefidx[ "std" ]   = GLOBAL_HANDLE+1;
+  g_name2classrefidx[ "::std" ] = GLOBAL_HANDLE+1;
+  g_classrefs.push_back(TClassRef("std"));
   // add a dummy global to refer to as null at index 0
   g_globalvars.push_back( nullptr );
}
@@ -1012,8 +1013,10 @@
 
 Cppyy::TCppIndex_t Cppyy::GetDatamemberIndex( TCppScope_t scope, const 
std::string& name )
 {
+   std::cout << " ASKING FOR: " << name << " on scope: " << scope << std::endl;
if ( scope == GLOBAL_HANDLE ) {
   TGlobal* gb = (TGlobal*)gROOT->GetListOfGlobals( kTRUE )->FindObject( 
name.c_str() );
+  std::cout << " FOUND (G): "<< gb << " " << 
(TGlobal*)gROOT->GetListOfGlobals( kTRUE )->FindObject("std::cout") << 
std::endl;
   if ( gb && gb->GetAddress() && gb->GetAddress() != (void*)-1 ) {
  g_globalvars.push_back( gb );
  return g_globalvars.size() - 1;
@@ -1025,6 +1028,7 @@
  TDataMember* dm =
 (TDataMember*)cr->GetListOfDataMembers()->FindObject( name.c_str() 
);
  // TODO: turning this into an index is silly ...
+ std::cout << " FOUND (D): "<< dm << std::endl;
  if ( dm ) return (TCppIndex_t)cr->GetListOfDataMembers()->IndexOf( dm 
);
   }
}
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
@@ -62,14 +62,12 @@
 
 endif
 
-ifeq ($(CLING),)
 ifeq ($(DUMMY),)
 # TODO: methptrgetter causes these tests to crash, so don't use it for now
 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 -std=c++14 
$(cppflags) $(cppflags2)
 endif
-endif
 
 .PHONY: clean
 clean:
diff --git a/pypy/module/cppyy/test/std_streams.xml 
b/pypy/module/cppyy/test/std_streams.xml
--- a/pypy/module/cppyy/test/std_streams.xml
+++ b/pypy/module/cppyy/test/std_streams.xml
@@ -1,9 +1,12 @@
 
 
+  
+
   
   
   
 
+  
   
 
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: translater fixes

2016-08-18 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86301:e2e2d5f25c36
Date: 2016-08-18 15:59 -0700
http://bitbucket.org/pypy/pypy/changeset/e2e2d5f25c36/

Log:translater fixes

diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -1,4 +1,5 @@
 from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rlib.rarithmetic import intmask
 from rpython.rlib import jit
 
 import cling_capi as backend
@@ -165,7 +166,7 @@
 length = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
 try:
 cstr = _c_call_s(cppmethod, cppobject, nargs, args, length)
-cstr_len = int(length[0])
+cstr_len = intmask(length[0])
 finally:
 lltype.free(length, flavor='raw')
 return cstr, cstr_len
diff --git a/pypy/module/cppyy/capi/cling_capi.py 
b/pypy/module/cppyy/capi/cling_capi.py
--- a/pypy/module/cppyy/capi/cling_capi.py
+++ b/pypy/module/cppyy/capi/cling_capi.py
@@ -4,6 +4,7 @@
 
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rlib.rarithmetic import intmask
 from rpython.rlib import libffi, rdynload
 
 from pypy.module.cppyy.capi.capi_types import C_OBJECT
@@ -81,7 +82,7 @@
 sz = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
 try:
 cstr = _c_stdstring2charp(cppstr, sz)
-cstr_len = int(sz[0])
+cstr_len = intmask(sz[0])
 finally:
 lltype.free(sz, flavor='raw')
 return rffi.charpsize2str(cstr, cstr_len)
diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -1,4 +1,5 @@
 from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rlib.rarithmetic import intmask
 from rpython.rlib import jit, jit_libffi, libffi, rdynload, objectmodel
 from rpython.rlib.rarithmetic import r_singlefloat
 from rpython.tool import leakfinder
@@ -349,7 +350,7 @@
 w_cstr = call_capi(space, 'call_s',
 [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs),
  _Arg(vp=rffi.cast(rffi.VOIDP, length))])
-cstr_len = int(length[0])
+cstr_len = intmask(length[0])
 finally:
 lltype.free(length, flavor='raw')
 return _cdata_to_ccharp(space, w_cstr), cstr_len
@@ -540,7 +541,7 @@
 try:
 w_cstr = call_capi(space, 'stdstring2charp',
 [_Arg(h=cppstr), _Arg(vp=rffi.cast(rffi.VOIDP, sz))])
-cstr_len = int(sz[0])
+cstr_len = intmask(sz[0])
 finally:
 lltype.free(sz, flavor='raw')
 return rffi.charpsize2str(_cdata_to_ccharp(space, w_cstr), cstr_len)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: remove spurious printout

2016-08-18 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86300:4ea4f34d66b9
Date: 2016-08-18 14:52 -0700
http://bitbucket.org/pypy/pypy/changeset/4ea4f34d66b9/

Log:remove spurious printout

diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -1013,10 +1013,8 @@
 
 Cppyy::TCppIndex_t Cppyy::GetDatamemberIndex( TCppScope_t scope, const 
std::string& name )
 {
-   std::cout << " ASKING FOR: " << name << " on scope: " << scope << std::endl;
if ( scope == GLOBAL_HANDLE ) {
   TGlobal* gb = (TGlobal*)gROOT->GetListOfGlobals( kTRUE )->FindObject( 
name.c_str() );
-  std::cout << " FOUND (G): "<< gb << " " << 
(TGlobal*)gROOT->GetListOfGlobals( kTRUE )->FindObject("std::cout") << 
std::endl;
   if ( gb && gb->GetAddress() && gb->GetAddress() != (void*)-1 ) {
  g_globalvars.push_back( gb );
  return g_globalvars.size() - 1;
@@ -1028,7 +1026,6 @@
  TDataMember* dm =
 (TDataMember*)cr->GetListOfDataMembers()->FindObject( name.c_str() 
);
  // TODO: turning this into an index is silly ...
- std::cout << " FOUND (D): "<< dm << std::endl;
  if ( dm ) return (TCppIndex_t)cr->GetListOfDataMembers()->IndexOf( dm 
);
   }
}
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: annotation fix

2016-08-19 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86325:67349a4ab510
Date: 2016-08-18 16:41 -0700
http://bitbucket.org/pypy/pypy/changeset/67349a4ab510/

Log:annotation fix

diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -534,8 +534,8 @@
 return pystr
 
 def c_charp2stdstring(space, svalue, sz):
-return _cdata_to_cobject(
-space, call_capi(space, 'charp2stdstring', [_Arg(s=svalue), 
_Arg(h=sz)]))
+return _cdata_to_cobject(space, call_capi(space, 'charp2stdstring',
+[_Arg(s=svalue), _Arg(h=rffi.cast(rffi.ULONG, sz))]))
 def c_stdstring2charp(space, cppstr):
 sz = lltype.malloc(rffi.SIZE_TP.TO, 1, flavor='raw')
 try:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: force deserialization of global functions

2016-08-19 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86324:741cd54aa263
Date: 2016-08-18 16:40 -0700
http://bitbucket.org/pypy/pypy/changeset/741cd54aa263/

Log:force deserialization of global functions

diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -716,8 +716,13 @@
 {
std::vector< TCppMethod_t > methods;
if ( scope == GLOBAL_HANDLE ) {
+  // TODO: figure out a way of being conservative with reloading
   TCollection* funcs = gROOT->GetListOfGlobalFunctions( kTRUE );
 
+  // tickle deserialization
+  if ( !funcs->FindObject( name.c_str() ) )
+ return methods;
+
   TIter ifunc(funcs);
   TFunction* func = 0;
   while ( (func = (TFunction*)ifunc.Next()) ) {
@@ -1327,6 +1332,11 @@
 }
 } else if (scope == (cppyy_scope_t)GLOBAL_HANDLE) {
 TCollection* funcs = gROOT->GetListOfGlobalFunctions(kTRUE);
+
+// tickle deserialization
+if (!funcs->FindObject(name))
+return (cppyy_index_t*)nullptr;
+
 TFunction* func = 0;
 TIter ifunc(funcs);
 while ((func = (TFunction*)ifunc.Next())) {
@@ -1336,7 +1346,7 @@
 }
 
 if (result.empty())
-return (cppyy_index_t*)0;
+return (cppyy_index_t*)nullptr;
 
 cppyy_index_t* llresult = 
(cppyy_index_t*)malloc(sizeof(cppyy_index_t)*(result.size()+1));
 for (int i = 0; i < (int)result.size(); ++i) llresult[i] = result[i];
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: checkpoint: first stab at resurrecting the fast path with better cffi integration

2016-08-20 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86366:1ff61f3c0347
Date: 2016-08-20 19:16 -0700
http://bitbucket.org/pypy/pypy/changeset/1ff61f3c0347/

Log:checkpoint: first stab at resurrecting the fast path with better
cffi integration

diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -7,8 +7,7 @@
 #import cint_capi as backend
 
 from pypy.module.cppyy.capi.capi_types import C_SCOPE, C_TYPE, C_OBJECT,\
-   C_METHOD, C_INDEX, C_INDEX_ARRAY, WLAVC_INDEX,\
-   C_METHPTRGETTER, C_METHPTRGETTER_PTR
+   C_METHOD, C_INDEX, C_INDEX_ARRAY, WLAVC_INDEX, C_FUNC_PTR
 
 identify  = backend.identify
 pythonize = backend.pythonize
@@ -186,15 +185,15 @@
 def c_call_o(space, method, cppobj, nargs, args, cppclass):
 return _c_call_o(method, cppobj, nargs, args, cppclass.handle)
 
-_c_get_methptr_getter = rffi.llexternal(
-"cppyy_get_methptr_getter",
-[C_SCOPE, C_INDEX], C_METHPTRGETTER_PTR,
+_c_get_function_address = rffi.llexternal(
+"cppyy_get_function_address",
+[C_SCOPE, C_INDEX], C_FUNC_PTR,
 releasegil=ts_reflect,
 compilation_info=backend.eci,
 elidable_function=True,
 random_effects_on_gcobjs=False)
-def c_get_methptr_getter(space, cppscope, index):
-return _c_get_methptr_getter(cppscope.handle, index)
+def c_get_function_address(space, cppscope, index):
+return _c_get_function_address(cppscope.handle, index)
 
 # handling of function argument buffer ---
 _c_allocate_function_args = rffi.llexternal(
diff --git a/pypy/module/cppyy/capi/capi_types.py 
b/pypy/module/cppyy/capi/capi_types.py
--- a/pypy/module/cppyy/capi/capi_types.py
+++ b/pypy/module/cppyy/capi/capi_types.py
@@ -18,5 +18,4 @@
 C_INDEX_ARRAY = rffi.LONGP
 WLAVC_INDEX = rffi.LONG
 
-C_METHPTRGETTER = lltype.FuncType([C_OBJECT], rffi.VOIDP)
-C_METHPTRGETTER_PTR = lltype.Ptr(C_METHPTRGETTER)
+C_FUNC_PTR = rffi.VOIDP
diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -10,7 +10,7 @@
 from pypy.module._cffi_backend import ctypefunc, ctypeprim, cdataobj, misc
 
 from pypy.module.cppyy.capi.capi_types import C_SCOPE, C_TYPE, C_OBJECT,\
-   C_METHOD, C_INDEX, C_INDEX_ARRAY, WLAVC_INDEX, C_METHPTRGETTER_PTR
+   C_METHOD, C_INDEX, C_INDEX_ARRAY, WLAVC_INDEX, C_FUNC_PTR
 
 
 reflection_library = 'libcppyy_backend.so'
@@ -154,7 +154,7 @@
 'constructor'  : ([c_method, c_object, c_int, c_voidp],   
c_object),
 'call_o'   : ([c_method, c_object, c_int, c_voidp, c_type],
 c_object),
 
-'get_methptr_getter'   : ([c_scope, c_index], 
c_voidp), # TODO: verify
+'get_function_address' : ([c_scope, c_index], 
c_voidp), # TODO: verify
 
 # handling of function argument buffer
 'allocate_function_args'   : ([c_int],c_voidp),
@@ -362,10 +362,10 @@
 args = [_Arg(h=cppmethod), _Arg(h=cppobject), _Arg(l=nargs), 
_Arg(vp=cargs), _Arg(h=cppclass.handle)]
 return _cdata_to_cobject(space, call_capi(space, 'call_o', args))
 
-def c_get_methptr_getter(space, cppscope, index):
+def c_get_function_address(space, cppscope, index):
 args = [_Arg(h=cppscope.handle), _Arg(l=index)]
-return rffi.cast(C_METHPTRGETTER_PTR,
-_cdata_to_ptr(space, call_capi(space, 'get_methptr_getter', args)))
+return rffi.cast(C_FUNC_PTR,
+_cdata_to_ptr(space, call_capi(space, 'get_function_address', args)))
 
 # handling of function argument buffer ---
 def c_allocate_function_args(space, size):
diff --git a/pypy/module/cppyy/ffitypes.py b/pypy/module/cppyy/ffitypes.py
--- a/pypy/module/cppyy/ffitypes.py
+++ b/pypy/module/cppyy/ffitypes.py
@@ -81,6 +81,7 @@
 libffitype  = jit_libffi.types.sint
 c_type  = rffi.INT
 c_ptrtype   = rffi.INTP
+ctype_name  = 'int'
 
 def _unwrap_object(self, space, w_obj):
 return rffi.cast(self.c_type, space.c_int_w(w_obj))
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
@@ -12,8 +12,8 @@
 typedef cppyy_scope_t cppyy_type_t;
 typedef unsigned long cppyy_object_t;
 typedef unsigned long cppyy_method_t;
-typedef long cppyy_index_t;
-typedef void* (*cppyy_methptrgetter_t)(cppyy_object_t);
+typedef long  cppyy_index_t;
+typedef void* cppyy_funcaddr_t;
 
 /* name to opaque C++ scope representation 
 */
 RPY_EXTERN
@@ -67,7 +67,7 @@
 cppyy_object_t cppyy_call_o(cppyy_method_t method, cppyy_object_t self, 
int nargs, void* args, cppyy_type_t result_type);
 
 RPY_EXTERN
-cppyy_methptrgetter_t 

[pypy-commit] pypy cling-support: capitulate on __dir__ for now

2016-08-20 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86367:b0a2d7ad8562
Date: 2016-08-20 22:30 -0700
http://bitbucket.org/pypy/pypy/changeset/b0a2d7ad8562/

Log:capitulate on __dir__ for now

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
@@ -832,13 +832,7 @@
 return datamember
 
 def _find_datamembers(self):
-num_datamembers = capi.c_num_datamembers(self.space, self)
-for i in range(num_datamembers):
-if not capi.c_is_publicdata(self.space, self, i):
-continue
-datamember_name = capi.c_datamember_name(self.space, self, i)
-if not datamember_name in self.datamembers:
-self._make_datamember(datamember_name, i)
+pass   # force lazy lookups in namespaces
 
 def find_overload(self, meth_name):
 indices = capi.c_method_indices_from_name(self.space, self, meth_name)
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -132,7 +132,19 @@
 Cppyy::TCppIndex_t Cppyy::GetNumScopes( TCppScope_t scope )
 {
TClassRef& cr = type_from_handle( scope );
-   if ( cr.GetClass() ) return 0;   // not supported if not at global scope
+   if ( cr.GetClass() ) {
+   // this is expensive, but this function is only ever called for __dir__
+   // TODO: rewrite __dir__ on the C++ side for a single loop
+   std::string s = GetFinalName( scope ); s += "::";
+   gClassTable->Init(); 
+   const int N = gClassTable->Classes();
+   int total = 0;
+   for ( int i = 0; i < N; ++i ) {
+   if ( strncmp( gClassTable->Next(), s.c_str(), s.size() ) == 0 )
+  total += 1;
+   }
+   return total;
+   }
assert( scope == (TCppScope_t)GLOBAL_HANDLE );
return gClassTable->Classes();
 }
@@ -141,7 +153,22 @@
 {
 // Retrieve the scope name of the scope indexed with iscope in parent.
TClassRef& cr = type_from_handle( parent );
-   if ( cr.GetClass() ) return 0;   // not supported if not at global scope
+   if ( cr.GetClass() ) {
+   // this is expensive (quadratic in number of classes), but only ever called 
for __dir__
+   // TODO: rewrite __dir__ on the C++ side for a single loop
+   std::string s = GetFinalName( parent ); s += "::";
+   gClassTable->Init();
+   const int N = gClassTable->Classes();
+   int match = 0;
+   for ( int i = 0; i < N; ++i ) {
+   char* cname = gClassTable->Next();
+   if ( strncmp( cname, s.c_str(), s.size() ) == 0 && match++ == 
iscope ) {
+  std::string ret( cname+ s.size() );
+  return ret.substr(0, ret.find( "::" ) ); // TODO: may mean 
duplicates
+   }
+   }
+   // should never get here ... fall through will fail on assert below
+   }
assert( parent == (TCppScope_t)GLOBAL_HANDLE );
std::string name = gClassTable->At( iscope );
if ( name.find("::") == std::string::npos )
diff --git a/pypy/module/cppyy/test/test_fragile.py 
b/pypy/module/cppyy/test/test_fragile.py
--- a/pypy/module/cppyy/test/test_fragile.py
+++ b/pypy/module/cppyy/test/test_fragile.py
@@ -228,8 +228,10 @@
 
 assert 'nested1' in members  # namespace
 
-assert 'fglobal' in members  # function
-assert 'gI'in members# variable
+# TODO: think this through ... probably want this, but interferes with
+# the (new) policy of lazy lookups
+#assert 'fglobal' in members  # function
+#assert 'gI'in members# variable
 
 def test12_imports(self):
 """Test ability to import from namespace (or fail with ImportError)"""
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: complete fast path

2016-08-22 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86435:0b1eabb9b806
Date: 2016-08-22 21:46 -0700
http://bitbucket.org/pypy/pypy/changeset/0b1eabb9b806/

Log:complete fast path

diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -8,6 +8,8 @@
 from pypy.interpreter.error import oefmt
 
 from pypy.module._cffi_backend import ctypefunc, ctypeprim, cdataobj, misc
+from pypy.module._cffi_backend import newtype
+from pypy.module.cppyy import ffitypes
 
 from pypy.module.cppyy.capi.capi_types import C_SCOPE, C_TYPE, C_OBJECT,\
C_METHOD, C_INDEX, C_INDEX_ARRAY, WLAVC_INDEX, C_FUNC_PTR
@@ -90,35 +92,35 @@
 self.library = None
 self.capi_calls = {}
 
-import pypy.module._cffi_backend.newtype as nt
+nt = newtype # module from _cffi_backend
+state = space.fromcache(ffitypes.State)   # factored out common types
 
 # TODO: the following need to match up with the globally defined C_XYZ 
low-level
 # types (see capi/__init__.py), but by using strings here, that isn't 
guaranteed
-c_opaque_ptr = nt.new_primitive_type(space, 'unsigned long')
+c_opaque_ptr = state.c_ulong
  
 c_scope  = c_opaque_ptr
 c_type   = c_scope
 c_object = c_opaque_ptr
 c_method = c_opaque_ptr
-c_index  = nt.new_primitive_type(space, 'long')
+c_index  = state.c_long
+c_index_array = state.c_voidp
 
-c_void   = nt.new_void_type(space)
-c_char   = nt.new_primitive_type(space, 'char')
-c_uchar  = nt.new_primitive_type(space, 'unsigned char')
-c_short  = nt.new_primitive_type(space, 'short')
-c_int= nt.new_primitive_type(space, 'int')
-c_long   = nt.new_primitive_type(space, 'long')
-c_llong  = nt.new_primitive_type(space, 'long long')
-c_ullong = nt.new_primitive_type(space, 'unsigned long long')
-c_float  = nt.new_primitive_type(space, 'float')
-c_double = nt.new_primitive_type(space, 'double')
+c_void   = state.c_void
+c_char   = state.c_char
+c_uchar  = state.c_uchar
+c_short  = state.c_short
+c_int= state.c_int
+c_long   = state.c_long
+c_llong  = state.c_llong
+c_ullong = state.c_ullong
+c_float  = state.c_float
+c_double = state.c_double
 
-c_ccharp = nt.new_pointer_type(space, c_char)
-c_index_array = nt.new_pointer_type(space, c_void)
+c_ccharp = state.c_ccharp
+c_voidp  = state.c_voidp
 
-c_voidp  = nt.new_pointer_type(space, c_void)
 c_size_t = nt.new_primitive_type(space, 'size_t')
-
 c_ptrdiff_t = nt.new_primitive_type(space, 'ptrdiff_t')
 
 self.capi_call_ifaces = {
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
@@ -4,7 +4,7 @@
 
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib.rarithmetic import r_singlefloat
-from rpython.rlib import jit_libffi, rfloat
+from rpython.rlib import rfloat
 
 from pypy.module._rawffi.interp_rawffi import letter2tp
 from pypy.module._rawffi.array import W_Array, W_ArrayInstance
@@ -81,11 +81,11 @@
 
 
 class TypeConverter(object):
-_immutable_fields_ = ['libffitype', 'uses_local', 'name']
+_immutable_fields_ = ['cffi_name', 'uses_local', 'name']
 
-libffitype = lltype.nullptr(jit_libffi.FFI_TYPE_P.TO)
+cffi_name  = None
 uses_local = False
-name = ""
+name   = ""
 
 def __init__(self, space, extra):
 pass
@@ -103,6 +103,10 @@
 raise oefmt(space.w_TypeError,
 "no converter available for '%s'", self.name)
 
+def cffi_type(self, space):
+from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
+raise FastCallNotPossible
+
 def convert_argument(self, space, w_obj, address, call_local):
 self._is_abstract(space)
 
@@ -143,9 +147,7 @@
 
 class ArrayTypeConverterMixin(object):
 _mixin_ = True
-_immutable_fields_ = ['libffitype', 'size']
-
-libffitype = jit_libffi.types.pointer
+_immutable_fields_ = ['size']
 
 def __init__(self, space, array_size):
 if array_size <= 0:
@@ -153,6 +155,10 @@
 else:
 self.size = array_size
 
+def cffi_type(self, space):
+state = space.fromcache(ffitypes.State)
+return state.c_voidp
+
 def from_memory(self, space, w_obj, w_pycppclass, offset):
 # read access, so no copy needed
 address_value = self._get_raw_address(space, w_obj, offset)
@@ -172,13 +178,15 @@
 
 class PtrTypeConverterMixin(object):
 _mixin_ = True
-_immutable_fields_ = ['libffitype', 'size']
-
-libffitype = jit_libffi.types.pointer
+_immutable_fields_ = ['size']
 
 def __ini

[pypy-commit] pypy cling-support: add offset elision for simple hierarchies

2016-08-22 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r86436:07248074d30c
Date: 2016-08-22 22:00 -0700
http://bitbucket.org/pypy/pypy/changeset/07248074d30c/

Log:add offset elision for simple hierarchies

diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -627,10 +627,28 @@
return cr->GetName();
 }
 
-Bool_t Cppyy::HasComplexHierarchy( TCppType_t /* handle */ )
+Bool_t Cppyy::HasComplexHierarchy( TCppType_t klass )
 {
-// Always TRUE for now (pre-empts certain optimizations).
-  return kTRUE;
+   int is_complex = 1;
+   size_t nbases = 0;
+
+   TClassRef& cr = type_from_handle( klass );
+   if ( cr.GetClass() && cr->GetListOfBases() != 0 )
+  nbases = GetNumBases( klass );
+
+   if (1 < nbases)
+  is_complex = 1;
+   else if (nbases == 0)
+  is_complex = 0;
+   else { // one base class only
+  TBaseClass* base = (TBaseClass*)cr->GetListOfBases()->At( 0 );
+  if ( base->Property() & kIsVirtualBase )
+ is_complex = 1;   // TODO: verify; can be complex, need not be.
+  else
+ is_complex = HasComplexHierarchy( GetScope( base->GetName() ) );
+   }
+
+   return is_complex;
 }
 
 Cppyy::TCppIndex_t Cppyy::GetNumBases( TCppType_t klass )
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: optimization as used in the paper

2016-09-13 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r87095:ff0990bd1f29
Date: 2016-09-13 11:09 -0700
http://bitbucket.org/pypy/pypy/changeset/ff0990bd1f29/

Log:optimization as used in the paper

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
@@ -9,8 +9,8 @@
 # the selection of the desired backend (default is Reflex).
 
 # choose C-API access method:
-#from pypy.module.cppyy.capi.loadable_capi import *
-from pypy.module.cppyy.capi.builtin_capi import *
+from pypy.module.cppyy.capi.loadable_capi import *
+#from pypy.module.cppyy.capi.builtin_capi import *
 
 from pypy.module.cppyy.capi.capi_types import C_OBJECT,\
 C_NULL_TYPE, C_NULL_OBJECT
diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -190,7 +190,6 @@
 [C_SCOPE, C_INDEX], C_FUNC_PTR,
 releasegil=ts_reflect,
 compilation_info=backend.eci,
-elidable_function=True,
 random_effects_on_gcobjs=False)
 def c_get_function_address(space, cppscope, index):
 return _c_get_function_address(cppscope.handle, index)
@@ -215,8 +214,8 @@
 [], rffi.SIZE_T,
 releasegil=ts_memory,
 compilation_info=backend.eci,
-elidable_function=True,
 random_effects_on_gcobjs=False)
+@jit.elidable
 def c_function_arg_sizeof(space):
 return _c_function_arg_sizeof()
 _c_function_arg_typeoffset = rffi.llexternal(
@@ -224,8 +223,8 @@
 [], rffi.SIZE_T,
 releasegil=ts_memory,
 compilation_info=backend.eci,
-elidable_function=True,
 random_effects_on_gcobjs=False)
+@jit.elidable
 def c_function_arg_typeoffset(space):
 return _c_function_arg_typeoffset()
 
@@ -300,9 +299,8 @@
 [C_TYPE, C_TYPE], rffi.INT,
 releasegil=ts_reflect,
 compilation_info=backend.eci,
-elidable_function=True,
 random_effects_on_gcobjs=False)
-@jit.elidable_promote('2')
+@jit.elidable
 def c_is_subtype(space, derived, base):
 if derived == base:
 return 1
@@ -313,9 +311,8 @@
 [C_TYPE, C_TYPE, C_OBJECT, rffi.INT], rffi.SIZE_T,
 releasegil=ts_reflect,
 compilation_info=backend.eci,
-elidable_function=True,
 random_effects_on_gcobjs=False)
-@jit.elidable_promote('1,2,4')
+@jit.elidable
 def c_base_offset(space, derived, base, address, direction):
 if derived == base:
 return 0
@@ -564,3 +561,26 @@
 compilation_info=backend.eci)
 def c_stdstring2stdstring(space, cppobject):
 return _c_stdstring2stdstring(cppobject)
+
+_c_stdvector_valuetype = rffi.llexternal(
+"cppyy_stdvector_valuetype",
+[rffi.CCHARP], rffi.CCHARP,
+releasegil=ts_helper,
+compilation_info=backend.eci)
+def c_stdvector_valuetype(space, pystr):
+cstr = rffi.str2charp(pystr)
+result = _c_stdvector_valuetype(cstr)
+rffi.free_charp(cstr)
+if result:
+return charp2str_free(space, result)
+return ""
+_c_stdvector_valuesize = rffi.llexternal(
+"cppyy_stdvector_valuesize",
+[rffi.CCHARP], rffi.SIZE_T,
+releasegil=ts_helper,
+compilation_info=backend.eci)
+def c_stdvector_valuesize(space, pystr):
+cstr = rffi.str2charp(pystr)
+result = _c_stdvector_valuesize(cstr)
+rffi.free_charp(cstr)
+return result
diff --git a/pypy/module/cppyy/capi/cling_capi.py 
b/pypy/module/cppyy/capi/cling_capi.py
--- a/pypy/module/cppyy/capi/cling_capi.py
+++ b/pypy/module/cppyy/capi/cling_capi.py
@@ -1,12 +1,16 @@
 import py, os
 
+from pypy.objspace.std.iterobject import W_AbstractSeqIterObject
+
+from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import interp2app
 
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib.rarithmetic import intmask
-from rpython.rlib import libffi, rdynload
+from rpython.rlib import jit, libffi, rdynload
 
+from pypy.module._rawffi.array import W_ArrayInstance
 from pypy.module.cppyy.capi.capi_types import C_OBJECT
 
 __all__ = ['identify', 'std_string_name', 'eci', 'c_load_dictionary']
@@ -89,6 +93,9 @@
 
 # TODO: factor these out ...
 # pythonizations
+
+#
+# std::string behavior
 def stdstring_c_str(space, w_self):
 """Return a python string taking into account \0"""
 
@@ -96,6 +103,60 @@
 cppstr = space.interp_w(interp_cppyy.W_CPPInstance, w_self, 
can_be_None=False)
 return space.wrap(c_stdstring2charp(space, cppstr._rawobject))
 
+#
+# std::vector behavior
+class W_STLVectorIter(W_AbstractSeqIterObject):
+_immutable_fields_ = ['overload', 'len']#'data', 'converter', 'len', 
'stride', 'vector']
+
+def __init__(self, space, w_vector):
+W_AbstractSeqIterObject.__init__(self, w_vector)
+# TODO: this should live in rpythonize.py or something so that the
+# imports can move to the top w/o getting circles
+from

[pypy-commit] pypy cling-support: more detailed benchmarks, used for paper

2016-09-13 Thread wlav
 cpython_bench1 = PureBench1()
+elif not 'cppyy' in sys.builtin_module_names:
+# runs ROOT/cppyy.py
+cpython_bench1 = CPythonBench1()
+try:
+print run_bench(cpython_bench1)
 sys.exit(0)
-
-# special case for PyROOT (run under python, not pypy-c)
-if '--pyroot' in sys.argv:
-pyroot_bench1 = PyROOTBench1()
-print run_bench(pyroot_bench1)
-sys.exit(0)
+except NameError:
+pass
 
 # get C++ reference point
 if not os.path.exists("bench1.exe") or\
 os.stat("bench1.exe").st_mtime < os.stat("bench1.cxx").st_mtime:
 print "rebuilding bench1.exe ... "
-os.system( "g++ -O2 bench1.cxx example01.cxx -o bench1.exe" )
+# the following is debatable, as pypy-c uses direct function
+# pointers, whereas that is only true for virtual functions in
+# the case of C++ (by default, anyway, it need not)
+# yes, shared library use is what's going on ...
+#os.system( "g++ -O2 bench1.cxx example01.cxx -o bench1.exe" )
+os.system( "g++ -O2 bench1.cxx -L. -lexample01Dict -o bench1.exe" )
 stat, cppref = commands.getstatusoutput("./bench1.exe")
 t_cppref = float(cppref)
 
-# created object
+# create object
 benches = [
 CppyyInterpBench1(), CppyyInterpBench2(), CppyyInterpBench3(),
 CppyyPythonBench1(), CppyyPythonBench2(), CppyyPythonBench3() ]
@@ -167,7 +210,35 @@
 # test runs ...
 for bench in benches:
 print_bench(bench.title, run_bench(bench))
-stat, t_cintex = commands.getstatusoutput("python bench1.py --pycintex")
-    print_bench("pycintex", float(t_cintex))
-#stat, t_pyroot = commands.getstatusoutput("python bench1.py --pyroot")
-#print_bench("pyroot  ", float(t_pyroot))
+
+stat, t_cpython1 = 
commands.getstatusoutput("/home/wlav/aditi/pypy/bin/v5/pypy-c bench1.py - 
-pure")
+if stat:
+print 'CPython pure bench1 failed:'
+os.write(sys.stdout.fileno(), t_cpython1)
+print
+exit(stat)
+print_bench("pypy-c pure ", float(t_cpython1))
+
+stat, t_cpython1 = commands.getstatusoutput("python bench1.py - -pure")
+if stat:
+print 'CPython pure bench1 failed:'
+os.write(sys.stdout.fileno(), t_cpython1)
+print
+exit(stat)
+print_bench("CPython pure", float(t_cpython1))
+
+stat, t_cpython1 = commands.getstatusoutput("python bench1.py - -b")
+if stat:
+print 'CPython bench1 failed:'
+os.write(sys.stdout.fileno(), t_cpython1)
+print
+exit(stat)
+print_bench("CPython ", float(t_cpython1))
+
+#stat, t_cpython1 = commands.getstatusoutput("python bench1.py - -swig")
+#if stat:
+#print 'SWIG bench1 failed:'
+#os.write(sys.stdout.fileno(), t_cpython1)
+#print
+#exit(stat)
+#print_bench("SWIG", float(t_cpython1))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reflex-support: updates for handling of null-ptrs and enums

2014-07-16 Thread wlav
Author: Wim Lavrijsen 
Branch: reflex-support
Changeset: r72457:6fd647e28232
Date: 2014-07-16 12:16 -0700
http://bitbucket.org/pypy/pypy/changeset/6fd647e28232/

Log:updates for handling of null-ptrs and enums

diff --git a/pypy/module/cppyy/test/test_datatypes.py 
b/pypy/module/cppyy/test/test_datatypes.py
--- a/pypy/module/cppyy/test/test_datatypes.py
+++ b/pypy/module/cppyy/test/test_datatypes.py
@@ -391,6 +391,15 @@
 CppyyTestData.s_ldouble  =  math.pi
 assert c.s_ldouble  ==  math.pi
 
+# enum types
+assert raises(AttributeError, getattr, CppyyTestData, 'kBanana')
+if self.capi_identity == 'Cling':# detailed enum support only in 
Cling
+   assert raises(TypeError,  setattr, CppyyTestData, 'kLots',   42)
+c.s_enum = CppyyTestData.kLots
+assert CppyyTestData.s_enum == CppyyTestData.kLots
+CppyyTestData.s_enum = CppyyTestData.kNothing
+assert c.s_enum == CppyyTestData.kNothing
+
 c.__destruct__()
 
 def test07_range_access(self):
@@ -772,8 +781,13 @@
 def address_equality_test(a, b):
 assert cppyy.addressof(a) == cppyy.addressof(b)
 b2 = cppyy.bind_object(a, CppyyTestData)
+b.m_int = 888
+assert b.m_int == 888
+assert b == b2 and b.m_int == b2.m_int
 assert b is b2# memory regulator recycles
 b3 = cppyy.bind_object(cppyy.addressof(a), CppyyTestData)
+assert b3.m_int == 888
+assert b == b3 and b.m_int == b3.m_int
 assert b is b3# likewise
 
 address_equality_test(c.m_voidp, c2)
diff --git a/pypy/module/cppyy/test/test_fragile.py 
b/pypy/module/cppyy/test/test_fragile.py
--- a/pypy/module/cppyy/test/test_fragile.py
+++ b/pypy/module/cppyy/test/test_fragile.py
@@ -70,7 +70,7 @@
 assert fragile.D().check() == ord('D')
 
 d = fragile.D()
-raises(TypeError, d.overload, None)
+raises(TypeError, d.overload, 1.)
 raises(TypeError, d.overload, None, None, None)
 
 d.overload('a')
@@ -88,8 +88,10 @@
 assert fragile.E().check() == ord('E')
 
 e = fragile.E()
-raises(TypeError, e.overload, None)
-raises(TypeError, getattr, e, 'm_pp_no_such')
+# TODO: figure out the desired behavior here; right now, an opaque
+# pointer is returned to allow passing back to C++ code
+#raises(TypeError, e.overload, None)
+#raises(TypeError, getattr, e, 'm_pp_no_such')
 
 def test05_wrong_arg_addressof(self):
 """Test addressof() error reporting"""
@@ -184,17 +186,17 @@
 assert "TypeError: wrong number of arguments" in str(e)
 
 try:
-d.overload(None)  # raises TypeError
+d.overload(1.)# raises TypeError
 assert 0
 except TypeError, e:
 assert "fragile::D::overload()" in str(e)
 assert "TypeError: wrong number of arguments" in str(e)
 assert "fragile::D::overload(fragile::no_such_class*)" in str(e)
-assert "TypeError: no converter available for 
'fragile::no_such_class*'" in str(e)
+  # assert "TypeError: no converter available for 
'fragile::no_such_class*'" in str(e)
 assert "fragile::D::overload(char, int)" in str(e)
-assert "TypeError: expected string, got NoneType object" in str(e)
+assert "TypeError: expected string, got float object" in str(e)
 assert "fragile::D::overload(int, fragile::no_such_class*)" in 
str(e)
-assert "TypeError: expected integer, got NoneType object" in str(e)
+assert "TypeError: expected integer, got float object" in str(e)
 
 j = fragile.J()
 assert fragile.J.method1.__doc__ == j.method1.__doc__
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reflex-support: cling fixes

2014-07-16 Thread wlav
Author: Wim Lavrijsen 
Branch: reflex-support
Changeset: r72456:0de503991f11
Date: 2014-07-16 12:16 -0700
http://bitbucket.org/pypy/pypy/changeset/0de503991f11/

Log:cling fixes

diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -3,6 +3,7 @@
 
 import reflex_capi as backend
 #import cint_capi as backend
+#import cling_capi as backend
 
 from pypy.module.cppyy.capi.capi_types import C_SCOPE, C_TYPE, C_OBJECT,\
C_METHOD, C_INDEX, C_INDEX_ARRAY, WLAVC_INDEX,\
diff --git a/pypy/module/cppyy/capi/cling_capi.py 
b/pypy/module/cppyy/capi/cling_capi.py
--- a/pypy/module/cppyy/capi/cling_capi.py
+++ b/pypy/module/cppyy/capi/cling_capi.py
@@ -14,12 +14,13 @@
 (config_stat, incdir) = commands.getstatusoutput("root-config --incdir")
 
 if os.environ.get("ROOTSYS"):
-if config_stat != 0: # presumably Reflex-only
-rootincpath = [os.path.join(os.environ["ROOTSYS"], 
"interpreter/cling/include"),
-   os.path.join(os.environ["ROOTSYS"], 
"interpreter/llvm/inst/include")]
+rootincpath = [os.path.join(os.environ["ROOTSYS"], 
"interpreter/cling/include"),
+   os.path.join(os.environ["ROOTSYS"], 
"interpreter/llvm/inst/include")]
+if config_stat != 0:
+rootincpath.append(os.path.join(os.environ["ROOTSYS"], "include"))
 rootlibpath = [os.path.join(os.environ["ROOTSYS"], "lib64"), 
os.path.join(os.environ["ROOTSYS"], "lib")]
 else:
-rootincpath = [incdir]
+rootincpath.append(incdir)
 rootlibpath = commands.getoutput("root-config --libdir").split()
 else:
 if config_stat == 0:
@@ -45,7 +46,7 @@
 includes=["clingcwrapper.h"],
 library_dirs=rootlibpath,
 libraries=["Cling"],
-compile_extra=["-fno-strict-aliasing"],
+compile_extra=["-fno-strict-aliasing", "-std=c++11"],
 use_cpp_linker=True,
 )
 
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -21,7 +21,7 @@
 #include "cling/Interpreter/DynamicLibraryManager.h"
 #include "cling/Interpreter/Interpreter.h"
 #include "cling/Interpreter/LookupHelper.h"
-#include "cling/Interpreter/StoredValueRef.h"
+#include "cling/Interpreter/Value.h"
 #include "cling/MetaProcessor/MetaProcessor.h"
 
 #include "llvm/ADT/SmallVector.h"
@@ -157,7 +157,8 @@
 cppyy_scope_t cppyy_get_scope(const char* scope_name) {
 const cling::LookupHelper& lh = gCppyy_Cling->getLookupHelper();
 const Type* type = 0;
-const Decl* decl = lh.findScope(scope_name, &type, /* intantiateTemplate= 
*/ true);
+const Decl* decl = lh.findScope(scope_name,
+cling::LookupHelper::NoDiagnostics, &type, /* intantiateTemplate= */ 
true);
 if (!decl) {
 //std::string buf = TClassEdit::InsertStd(name);
 //decl = lh.findScope(buf, &type, /* intantiateTemplate= */ true);
@@ -190,8 +191,8 @@
 
 // TODO: expect the below to live in libCling.so
 static CPPYY_Cling_Wrapper_t make_wrapper(const FunctionDecl* fdecl);
-static void exec_with_valref_return(void* address, cling::StoredValueRef* ret, 
const FunctionDecl*);
-static long long sv_to_long_long(const cling::StoredValueRef& svref);
+static void exec_with_valref_return(void* address, cling::Value*, const 
FunctionDecl*);
+static long long sv_to_long_long(const cling::Value& val);
 // -- TODO: expect the above to live in libCling.so
 
 
@@ -200,7 +201,7 @@
 if (s_wrappers.find(method) == s_wrappers.end()) {
 make_wrapper((FunctionDecl*)method);
 }
-cling::StoredValueRef ret;
+cling::Value ret;
 //std::vector arguments = build_args(nargs, args);
 //CPPYY_Cling_Wrapper_t cb = (CPPYY_Cling_Wrapper_t)method;
 exec_with_valref_return((void*)self, &ret, (FunctionDecl*)method);
@@ -362,7 +363,7 @@
 // R__LOCKGUARD2(gInterpreterMutex);
 std::cout << " NOW LOADING: " << lib_name << std::endl;
 
-cling::StoredValueRef call_res;
+cling::Value call_res;
 cling::Interpreter::CompilationResult comp_res = 
cling::Interpreter::kSuccess;
 std::ostringstream line;
 line << "#include \"" << lib_name << ".h\"";
@@ -377,8 +378,8 @@
 // UpdateListOfLoadedSharedLibraries();
 // }
 switch (res) {
-case cling::DynamicLibraryManager::kLoadLibSuccess: return (void*)1;
-case cling::DynamicLibraryManager::kLoadLibExists:  return (void*)2;
+case cling::DynamicLibraryManager::kLoadLibSuccess:   return (void*)1;
+case cling::DynamicLibraryManager::kLoadLibAlreadyLoaded: return (void*)2;
 default: break;
 };
 return (void*)1;
@@ -389,68 +390,130 @@
 
 // TODO: expect the below to live in libCling.so
 
-template 
-T sv_to_long_long_u_or_not(const cling::StoredValueRef& svref) {
-const cling::Value& valref = svref.get();
-QualType QT = valref.getC

[pypy-commit] pypy default: update doc to refer to new reflex-2014-10-20.tar.bz2

2014-10-20 Thread wlav
Author: Wim Lavrijsen 
Branch: 
Changeset: r74021:0ee314061d53
Date: 2014-10-20 11:21 -0700
http://bitbucket.org/pypy/pypy/changeset/0ee314061d53/

Log:update doc to refer to new reflex-2014-10-20.tar.bz2

diff --git a/pypy/doc/cppyy.rst b/pypy/doc/cppyy.rst
--- a/pypy/doc/cppyy.rst
+++ b/pypy/doc/cppyy.rst
@@ -83,7 +83,7 @@
 the selection of scientific software) will also work for a build with the
 builtin backend.
 
-.. _`download`: http://cern.ch/wlav/reflex-2013-08-14.tar.bz2
+.. _`download`: http://cern.ch/wlav/reflex-2014-10-20.tar.bz2
 .. _`ROOT`: http://root.cern.ch/
 
 Besides Reflex, you probably need a version of `gccxml`_ installed, which is
@@ -98,8 +98,8 @@
 
 To install the standalone version of Reflex, after download::
 
-$ tar jxf reflex-2013-08-14.tar.bz2
-$ cd reflex-2013-08-14
+$ tar jxf reflex-2014-10-20.tar.bz2
+$ cd reflex-2014-10-20
 $ ./build/autogen
 $ ./configure 
 $ make && make install
@@ -804,7 +804,7 @@
 also means that you can't actually find out whether it is in use, other than
 by running a micro-benchmark or a JIT test).
 
-.. _`provided`: http://cern.ch/wlav/reflex-2013-04-23.tar.bz2
+.. _`provided`: http://cern.ch/wlav/reflex-2014-10-20.tar.bz2
 .. _`genreflex-methptrgetter.patch`: 
https://bitbucket.org/pypy/pypy/src/default/pypy/module/cppyy/genreflex-methptrgetter.patch
 
 CPython
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: start of exchanging reflex by cling

2016-06-27 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85417:ff08d43af948
Date: 2016-06-07 11:14 -0700
http://bitbucket.org/pypy/pypy/changeset/ff08d43af948/

Log:start of exchanging reflex by cling

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: From Aditi: first stab at new Cling backend, based off the C++ Cppyy.cxx

2016-06-27 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85418:1e669815cd70
Date: 2016-06-27 13:59 -0700
http://bitbucket.org/pypy/pypy/changeset/1e669815cd70/

Log:From Aditi: first stab at new Cling backend, based off the C++
Cppyy.cxx

diff too long, truncating to 2000 out of 3541 lines

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -77,3 +77,5 @@
 ^.hypothesis/
 ^release/
 ^rpython/_cache$
+
+pypy/module/cppyy/.+/*\.pcm
diff --git a/pypy/module/cppyy/bench/Makefile b/pypy/module/cppyy/bench/Makefile
--- a/pypy/module/cppyy/bench/Makefile
+++ b/pypy/module/cppyy/bench/Makefile
@@ -26,4 +26,4 @@
 
 bench02Dict_reflex.so: bench02.h bench02.cxx bench02.xml
$(genreflex) bench02.h $(genreflexflags) --selection=bench02.xml 
-I$(ROOTSYS)/include
-   g++ -o $@ bench02.cxx bench02_rflx.cpp -I$(ROOTSYS)/include -shared 
-lReflex -lHistPainter `root-config --libs` $(cppflags) $(cppflags2)
+   g++ -o $@ bench02.cxx bench02_rflx.cpp -I$(ROOTSYS)/include -shared 
-std=c++14 -lHistPainter `root-config --libs` $(cppflags) $(cppflags2)
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
@@ -9,8 +9,8 @@
 # the selection of the desired backend (default is Reflex).
 
 # choose C-API access method:
-from pypy.module.cppyy.capi.loadable_capi import *
-#from pypy.module.cppyy.capi.builtin_capi import *
+#from pypy.module.cppyy.capi.loadable_capi import *
+from pypy.module.cppyy.capi.builtin_capi import *
 
 from pypy.module.cppyy.capi.capi_types import C_OBJECT,\
 C_NULL_TYPE, C_NULL_OBJECT
diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -1,7 +1,8 @@
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib import jit
 
-import reflex_capi as backend
+import cling_capi as backend
+#import reflex_capi as backend
 #import cint_capi as backend
 
 from pypy.module.cppyy.capi.capi_types import C_SCOPE, C_TYPE, C_OBJECT,\
diff --git a/pypy/module/cppyy/capi/cling_capi.py 
b/pypy/module/cppyy/capi/cling_capi.py
--- a/pypy/module/cppyy/capi/cling_capi.py
+++ b/pypy/module/cppyy/capi/cling_capi.py
@@ -16,7 +16,8 @@
 if os.environ.get("ROOTSYS"):
 if config_stat != 0: # presumably Reflex-only
 rootincpath = [os.path.join(os.environ["ROOTSYS"], 
"interpreter/cling/include"),
-   os.path.join(os.environ["ROOTSYS"], 
"interpreter/llvm/inst/include")]
+   os.path.join(os.environ["ROOTSYS"], 
"interpreter/llvm/inst/include"),
+   os.path.join(os.environ["ROOTSYS"], "include"),]
 rootlibpath = [os.path.join(os.environ["ROOTSYS"], "lib64"), 
os.path.join(os.environ["ROOTSYS"], "lib")]
 else:
 rootincpath = [incdir]
@@ -39,13 +40,21 @@
 
 std_string_name = 'std::basic_string'
 
+# force loading (and exposure) of libCore symbols
+with rffi.scoped_str2charp('libCore.so') as ll_libname:
+_coredll = rdynload.dlopen(ll_libname, rdynload.RTLD_GLOBAL | 
rdynload.RTLD_NOW)
+
+# require local translator path to pickup common defs
+from rpython.translator import cdir
+translator_c_dir = py.path.local(cdir)
+
 eci = ExternalCompilationInfo(
 separate_module_files=[srcpath.join("clingcwrapper.cxx")],
-include_dirs=[incpath] + rootincpath,
+include_dirs=[incpath, translator_c_dir] + rootincpath,
 includes=["clingcwrapper.h"],
 library_dirs=rootlibpath,
 libraries=["Cling"],
-compile_extra=["-fno-strict-aliasing"],
+compile_extra=["-fno-strict-aliasing", "-std=c++14"],
 use_cpp_linker=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
@@ -735,7 +735,7 @@
 
 type_info = (
 (rffi.LONG,   ("long", "long int")),
-(rffi.LONGLONG,   ("long long", "long long int")),
+(rffi.LONGLONG,   ("long long", "long long int", "Long64_t")),
 )
 
 for c_type, names in type_info:
@@ -743,6 +743,7 @@
 _immutable_ = True
 def __init__(self, space, default):
 self.default = rffi.cast(self.c_type, capi.c_strtoll(space, 
default))
+
 class ConstRefConverter(ConstRefNumericTypeConverterMixin, 
BasicConverter):
 _immutable_ = True
 libffitype = jit_libffi.types.pointer
@@ -761,7 +762,7 @@
 (rffi.USHORT, ("unsigned short", "unsigned short int")),
 (rffi.UINT,   ("unsigned", "unsigned int")),
 (rffi.ULONG,  ("unsigned long", "unsigned long int")),
-(rffi.ULONGLONG,  ("unsigned long long", "unsigned long long int")),
+(rffi.ULONGLONG,  ("unsigned long long", "unsigned long long int", 
"ULong64_t")),
 )
 
 for c_type, names in type_info:
diff --git a/pypy/mo

[pypy-commit] pypy cling-support: spell out all classes as [A-Z] pattern appears not to be working anymore

2016-06-30 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85476:7fcccdb6a0b1
Date: 2016-06-30 15:52 -0700
http://bitbucket.org/pypy/pypy/changeset/7fcccdb6a0b1/

Log:spell out all classes as [A-Z] pattern appears not to be working
anymore

diff --git a/pypy/module/cppyy/test/fragile.xml 
b/pypy/module/cppyy/test/fragile.xml
--- a/pypy/module/cppyy/test/fragile.xml
+++ b/pypy/module/cppyy/test/fragile.xml
@@ -5,7 +5,22 @@
   
   
 
-  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
   
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: from Aditi: test_cppyy.py now succeeds

2016-06-30 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85477:107dd38e12c9
Date: 2016-06-30 15:52 -0700
http://bitbucket.org/pypy/pypy/changeset/107dd38e12c9/

Log:from Aditi: test_cppyy.py now succeeds

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
@@ -255,6 +255,8 @@
 def convert_argument(self, space, w_obj, address, call_local):
 x = rffi.cast(self.c_ptrtype, address)
 x[0] = self._unwrap_object(space, w_obj)
+ba = rffi.cast(rffi.CCHARP, address)
+ba[capi.c_function_arg_typeoffset(space)] = self.typecode
 
 class FloatTypeConverterMixin(NumericTypeConverterMixin):
 _mixin_ = True
@@ -337,7 +339,7 @@
 _immutable_fields_ = ['libffitype', 'typecode']
 
 libffitype = jit_libffi.types.pointer
-typecode = 'F'
+typecode = 'f'
 
 def convert_argument_libffi(self, space, w_obj, address, call_local):
 from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
@@ -356,7 +358,7 @@
 _immutable_fields_ = ['libffitype', 'typecode']
 
 libffitype = jit_libffi.types.pointer
-typecode = 'D'
+typecode = 'd'
 
 
 class CStringConverter(TypeConverter):
@@ -713,17 +715,18 @@
 "NOT_RPYTHON"
 # signed types (use strtoll in setting of default in __init__)
 type_info = (
-(rffi.SHORT,  ("short", "short int")),
-(rffi.INT,("int",)),
+(rffi.SHORT,  ("short", "short int"),  'h'),
+(rffi.INT,("int",),'i'),
 )
 
 # constref converters exist only b/c the stubs take constref by value, 
whereas
 # libffi takes them by pointer (hence it needs the fast-path in testing); 
note
 # that this is list is not complete, as some classes are specialized
 
-for c_type, names in type_info:
+for c_type, names, c_tc in type_info:
 class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, 
TypeConverter):
 _immutable_ = True
+typecode = c_tc
 def __init__(self, space, default):
 self.default = rffi.cast(self.c_type, capi.c_strtoll(space, 
default))
 class ConstRefConverter(ConstRefNumericTypeConverterMixin, 
BasicConverter):
@@ -734,40 +737,35 @@
 _converters["const "+name+"&"] = ConstRefConverter
 
 type_info = (
-(rffi.LONG,   ("long", "long int")),
-(rffi.LONGLONG,   ("long long", "long long int", "Long64_t")),
+(rffi.LONG,   ("long", "long int"),'l'),
+(rffi.LONGLONG,   ("long long", "long long int", "Long64_t"),  'k'),
 )
 
-for c_type, names in type_info:
+for c_type, names, c_tc in type_info:
 class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, 
TypeConverter):
 _immutable_ = True
+typecode = c_tc
 def __init__(self, space, default):
 self.default = rffi.cast(self.c_type, capi.c_strtoll(space, 
default))
-
 class ConstRefConverter(ConstRefNumericTypeConverterMixin, 
BasicConverter):
 _immutable_ = True
 libffitype = jit_libffi.types.pointer
-typecode = 'r'
-def convert_argument(self, space, w_obj, address, call_local):
-x = rffi.cast(self.c_ptrtype, address)
-x[0] = self._unwrap_object(space, w_obj)
-ba = rffi.cast(rffi.CCHARP, address)
-ba[capi.c_function_arg_typeoffset(space)] = self.typecode
 for name in names:
 _converters[name] = BasicConverter
 _converters["const "+name+"&"] = ConstRefConverter
 
 # unsigned integer types (use strtoull in setting of default in __init__)
 type_info = (
-(rffi.USHORT, ("unsigned short", "unsigned short int")),
-(rffi.UINT,   ("unsigned", "unsigned int")),
-(rffi.ULONG,  ("unsigned long", "unsigned long int")),
-(rffi.ULONGLONG,  ("unsigned long long", "unsigned long long int", 
"ULong64_t")),
+(rffi.USHORT, ("unsigned short", "unsigned short int"),
'H'),
+(rffi.UINT,   ("unsigned", "unsigned int"),
'I'),
+(rffi.ULONG,  ("unsigned long", "unsigned long int"),  
'L'),
+(rffi.ULONGLONG,  ("unsigned long long", "unsigned long long int", 
"ULong64_t"),   'K'),
 )
 
-for c_type, names in type_info:
+for c_type, names, c_tc in type_info:
 class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, 
TypeConverter):
 _immutable_ = True
+typecode = c_tc
 def __init__(self, space, default):
 self.default = rffi.cast(self.c_type, capi.c_strtoull(space, 
default))
 class ConstRefConverter(ConstRefNumericTypeConverterMixin, 
BasicConverter):

[pypy-commit] pypy cling-support: from Aditi: more typecode fixes

2016-07-06 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85592:bbbf4b479fc5
Date: 2016-07-06 12:53 -0700
http://bitbucket.org/pypy/pypy/changeset/bbbf4b479fc5/

Log:from Aditi: more typecode fixes

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
@@ -284,6 +284,8 @@
 def convert_argument(self, space, w_obj, address, call_local):
 x = rffi.cast(rffi.LONGP, address)
 x[0] = self._unwrap_object(space, w_obj)
+ba = rffi.cast(rffi.CCHARP, address)
+ba[capi.c_function_arg_typeoffset(space)] = 'b'
 
 def convert_argument_libffi(self, space, w_obj, address, call_local):
 x = rffi.cast(rffi.LONGP, address)
@@ -307,6 +309,8 @@
 def convert_argument(self, space, w_obj, address, call_local):
 x = rffi.cast(rffi.CCHARP, address)
 x[0] = self._unwrap_object(space, w_obj)
+ba = rffi.cast(rffi.CCHARP, address)
+ba[capi.c_function_arg_typeoffset(space)] = 'b'
 
 def convert_argument_libffi(self, space, w_obj, address, call_local):
 x = rffi.cast(self.c_ptrtype, address)
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -368,7 +368,7 @@
   case 'K':  /* unsigned long long */
  vargs[i] = (void*)&args[i].fValue.fULongLong;
  break;
-  case 'f':  /* double */
+  case 'f':  /* float */
  vargs[i] = (void*)&args[i].fValue.fFloat;
  break;
   case 'd':  /* double */
diff --git a/pypy/module/cppyy/test/test_datatypes.py 
b/pypy/module/cppyy/test/test_datatypes.py
--- a/pypy/module/cppyy/test/test_datatypes.py
+++ b/pypy/module/cppyy/test/test_datatypes.py
@@ -124,8 +124,7 @@
 assert isinstance(c, cppyy_test_data)
 
 # boolean types through functions
-c.set_bool(True);
-assert c.get_bool() == True
+c.set_bool(True);  assert c.get_bool() == True
 c.set_bool(0); assert c.get_bool() == False
 
 # boolean types through data members
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: from Aditi: implementation of lazy lookup of global/namespaced methods

2016-07-11 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85660:c3d56777b481
Date: 2016-07-11 11:05 -0700
http://bitbucket.org/pypy/pypy/changeset/c3d56777b481/

Log:from Aditi: implementation of lazy lookup of global/namespaced
methods

diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -1240,9 +1240,39 @@
 }
 
 cppyy_index_t* cppyy_method_indices_from_name(cppyy_scope_t scope, const char* 
name){
-//NEED TO DO:
-return (cppyy_index_t*)0;
-//return (cppyy_index_t*)Cppyy::GetMethodsFromName(scope, name);
+std::vector result;
+TClassRef& cr = type_from_handle(scope);
+if (cr.GetClass()) {
+gInterpreter->UpdateListOfMethods(cr.GetClass());
+int imeth = 0;
+TFunction* func;
+TIter next(cr->GetListOfMethods());
+while ((func = (TFunction*)next())) {
+if (strcmp(name, func->GetName()) == 0) {
+if (func->Property() & 
Cppyy::IsPublicMethod((cppyy_method_t)func))
+result.push_back((cppyy_index_t)imeth);
+}
+++imeth;
+}
+} else if (scope == (cppyy_scope_t)GLOBAL_HANDLE) {
+TCollection* funcs = gROOT->GetListOfGlobalFunctions(kTRUE);
+TFunction* func = 0;
+TIter ifunc(funcs);
+while ((func = (TFunction*)ifunc.Next())) {
+if (strcmp(name, func->GetName()) == 0) {
+g_globalfuncs.push_back(*func);
+result.push_back((cppyy_index_t)func);
+}
+}
+}
+
+if (result.empty())
+return (cppyy_index_t*)0;
+
+cppyy_index_t* llresult = 
(cppyy_index_t*)malloc(sizeof(cppyy_index_t)*(result.size()+1));
+for (int i = 0; i < (int)result.size(); ++i) llresult[i] = result[i];
+llresult[result.size()] = -1;
+return llresult;
 }
 
 char* cppyy_method_name(cppyy_scope_t scope, cppyy_index_t idx) {
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: from Aditi (edited): initial enum support

2016-07-11 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85665:66ca03bf6d3c
Date: 2016-07-11 15:52 -0700
http://bitbucket.org/pypy/pypy/changeset/66ca03bf6d3c/

Log:from Aditi (edited): initial enum support

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
@@ -719,8 +719,8 @@
 "NOT_RPYTHON"
 # signed types (use strtoll in setting of default in __init__)
 type_info = (
-(rffi.SHORT,  ("short", "short int"),  'h'),
-(rffi.INT,("int",),'i'),
+(rffi.SHORT,  ("short", "short int"),  'h'),
+(rffi.INT,("int", "internal_enum_type_t"), 'i'),
 )
 
 # constref converters exist only b/c the stubs take constref by value, 
whereas
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -314,7 +314,7 @@
 (bool,capi.c_call_b,   ("bool",)),
 (rffi.CHAR,   capi.c_call_c,   ("char", "unsigned char")),
 (rffi.SHORT,  capi.c_call_h,   ("short", "short int", "unsigned 
short", "unsigned short int")),
-(rffi.INT,capi.c_call_i,   ("int",)),
+(rffi.INT,capi.c_call_i,   ("int", "internal_enum_type_t")),
 (rffi.UINT,   capi.c_call_l,   ("unsigned", "unsigned int")),
 (rffi.LONG,   capi.c_call_l,   ("long", "long int")),
 (rffi.ULONG,  capi.c_call_l,   ("unsigned long", "unsigned long 
int")),
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
@@ -446,7 +446,7 @@
 # install a type for enums to refer to
 # TODO: this is correct for C++98, not for C++11 and in general there will
 # be the same issue for all typedef'd builtin types
-setattr(gbl, 'unsigned int', int)
+setattr(gbl, 'internal_enum_type_t', int)
 
 # install nullptr as a unique reference
 setattr(gbl, 'nullptr', cppyy._get_nullptr())
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -558,6 +558,7 @@
 }
 
 Bool_t Cppyy::IsEnum( const std::string& type_name ) {
+   if ( type_name.empty() ) return kFALSE;
return gInterpreter->ClassInfo_IsEnum( type_name.c_str() );
 }
 
@@ -1068,7 +1069,10 @@
 }
 
 char* cppyy_resolve_name(const char* cppitem_name) {
-return cppstring_to_cstring(Cppyy::ResolveName(cppitem_name));
+std::string str = cppstring_to_cstring(Cppyy::ResolveName(cppitem_name));
+if (Cppyy::IsEnum(str))
+return cppstring_to_cstring("internal_enum_type_t");
+return cppstring_to_cstring(str);
 }
 
 cppyy_scope_t cppyy_get_scope(const char* scope_name) {
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: assertEqual -> assert

2016-07-12 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85667:8ab8c51edb73
Date: 2016-07-12 09:52 -0700
http://bitbucket.org/pypy/pypy/changeset/8ab8c51edb73/

Log:assertEqual -> assert

diff --git a/pypy/module/cppyy/test/test_stltypes.py 
b/pypy/module/cppyy/test/test_stltypes.py
--- a/pypy/module/cppyy/test/test_stltypes.py
+++ b/pypy/module/cppyy/test/test_stltypes.py
@@ -266,7 +266,7 @@
 stringy_class = cppyy.gbl.stringy_class
 
 t0 = "aap\0noot"
-self.assertEqual(t0, "aap\0noot")
+assert t0 == "aap\0noot"
 
 c, s = stringy_class(""), std.string(t0, len(t0))
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: from Aditi: proper type codes for instances converters

2016-07-12 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85668:979fabdcc11a
Date: 2016-07-12 09:52 -0700
http://bitbucket.org/pypy/pypy/changeset/979fabdcc11a/

Log:from Aditi: proper type codes for instances converters

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
@@ -455,9 +455,10 @@
 uses_local = True
 
 class InstanceRefConverter(TypeConverter):
-_immutable_fields_ = ['libffitype', 'cppclass']
+_immutable_fields_ = ['libffitype', 'typecode', 'cppclass']
 
 libffitype  = jit_libffi.types.pointer
+typecode= 'V'
 
 def __init__(self, space, cppclass):
 from pypy.module.cppyy.interp_cppyy import W_CPPClass
@@ -480,7 +481,7 @@
 x[0] = rffi.cast(rffi.VOIDP, self._unwrap_object(space, w_obj))
 address = rffi.cast(capi.C_OBJECT, address)
 ba = rffi.cast(rffi.CCHARP, address)
-ba[capi.c_function_arg_typeoffset(space)] = 'o'
+ba[capi.c_function_arg_typeoffset(space)] = self.typecode
 
 def convert_argument_libffi(self, space, w_obj, address, call_local):
 x = rffi.cast(rffi.VOIDPP, address)
@@ -502,6 +503,7 @@
 
 
 class InstancePtrConverter(InstanceRefConverter):
+typecode= 'o'
 
 def _unwrap_object(self, space, w_obj):
 try:
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -377,6 +377,7 @@
   case 'D':  /* long double */
  vargs[i] = (void*)&args[i].fValue.fLongDouble;
  break;
+  case 'a':
   case 'o':
   case 'p':  /* void* */
  vargs[i] = (void*)&args[i].fValue.fVoidp;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: fix handling of abstract classes

2016-07-12 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85669:cfe5c3380cce
Date: 2016-07-12 10:55 -0700
http://bitbucket.org/pypy/pypy/changeset/cfe5c3380cce/

Log:fix handling of abstract classes

diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -238,6 +238,13 @@
 compilation_info=backend.eci)
 def c_is_namespace(space, scope):
 return _c_is_namespace(scope)
+_c_is_abstract = rffi.llexternal(
+"cppyy_is_abstract",
+[C_SCOPE], rffi.INT,
+releasegil=ts_reflect,
+compilation_info=backend.eci)
+def c_is_abstract(space, cpptype):
+return _c_is_abstract(cpptype)
 _c_is_enum = rffi.llexternal(
 "cppyy_is_enum",
 [rffi.CCHARP], rffi.INT,
diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -162,6 +162,7 @@
 
 # scope reflection information
 'is_namespace' : ([c_scope],  c_int),
+'is_abstract'  : ([c_type],   c_int),
 'is_enum'  : ([c_ccharp], c_int),
 
 # type/class reflection information
@@ -367,6 +368,8 @@
 # scope reflection information ---
 def c_is_namespace(space, scope):
 return space.bool_w(call_capi(space, 'is_namespace', [_Arg(h=scope)]))
+def c_is_abstract(space, scope):
+return space.bool_w(call_capi(space, 'is_abstract', [_Arg(h=cpptype)]))
 def c_is_enum(space, name):
 return space.bool_w(call_capi(space, 'is_enum', [_Arg(s=name)]))
 
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
@@ -85,6 +85,8 @@
 RPY_EXTERN
 int cppyy_is_namespace(cppyy_scope_t scope);
 RPY_EXTERN
+int cppyy_is_abstract(cppyy_type_t type);
+RPY_EXTERN
 int cppyy_is_enum(const char* type_name);
 
 /* class reflection information 
--- */
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
@@ -1078,16 +1078,13 @@
 return None
 
 def instance__init__(self, args_w):
-try:
-constructor_overload = 
self.cppclass.get_overload(self.cppclass.name)
-constructor_overload.call(self, args_w)
-except OperationError as e:
-if not e.match(self.space, self.space.w_AttributeError):
-raise
+if capi.c_is_abstract(self.space, self.cppclass.handle):
 raise oefmt(self.space.w_TypeError,
 "cannot instantiate abstract class '%s'",
 self.cppclass.name)
-
+constructor_overload = self.cppclass.get_overload(self.cppclass.name)
+constructor_overload.call(self, args_w)
+ 
 def instance__eq__(self, w_other):
 # special case: if other is None, compare pointer-style
 if self.space.is_w(w_other, self.space.w_None):
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -567,16 +567,18 @@
 // class reflection information --
 std::string Cppyy::GetFinalName( TCppType_t klass )
 {
-   if ( klass == GLOBAL_HANDLE )// due to CLING WORKAROUND in 
InitConverters_
+   if ( klass == GLOBAL_HANDLE )
   return "";
-   // TODO: either this or GetScopedFinalName is wrong
TClassRef& cr = type_from_handle( klass );
-   return cr->GetName();
+   std::string clName = cr->GetName();
+   std::string::size_type pos = clName.substr( 0, clName.find( '<' ) ).rfind( 
"::" );
+   if ( pos != std::string::npos )
+  return clName.substr( pos + 2, std::string::npos );
+   return clName;
 }
 
 std::string Cppyy::GetScopedFinalName( TCppType_t klass )
 {
-   // TODO: either this or GetFinalName is wrong
TClassRef& cr = type_from_handle( klass );
return cr->GetName();
 }
@@ -1198,6 +1200,10 @@
 return (int)Cppyy::IsNamespace(scope);
 }
 
+int cppyy_is_abstract(cppyy_type_t type){
+return (int)Cppyy::IsAbstract(type);
+}
+
 int cppyy_is_enum(const char* type_name){
 return (int)Cppyy::IsEnum(type_name);
 }
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: pass length when converting char* to std::string

2016-07-12 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85670:76d09d04588d
Date: 2016-07-12 11:15 -0700
http://bitbucket.org/pypy/pypy/changeset/76d09d04588d/

Log:pass length when converting char* to std::string

diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -541,12 +541,12 @@
 
 _c_charp2stdstring = rffi.llexternal(
 "cppyy_charp2stdstring",
-[rffi.CCHARP], C_OBJECT,
+[rffi.CCHARP, rffi.SIZE_T], C_OBJECT,
 releasegil=ts_helper,
 compilation_info=backend.eci)
-def c_charp2stdstring(space, svalue):
+def c_charp2stdstring(space, svalue, sz):
 charp = rffi.str2charp(svalue)
-result = _c_charp2stdstring(charp)
+result = _c_charp2stdstring(charp, sz)
 rffi.free_charp(charp)
 return result
 _c_stdstring2stdstring = rffi.llexternal(
diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -216,7 +216,7 @@
 'strtoull' : ([c_ccharp], 
c_ullong),
 'free' : ([c_voidp],  c_void),
 
-'charp2stdstring'  : ([c_ccharp], 
c_object),
+'charp2stdstring'  : ([c_ccharp, c_size_t],   
c_object),
 'stdstring2stdstring'  : ([c_object], 
c_object),
 }
 
@@ -517,8 +517,9 @@
 c_free(space, rffi.cast(rffi.VOIDP, charp))
 return pystr
 
-def c_charp2stdstring(space, svalue):
-return _cdata_to_cobject(space, call_capi(space, 'charp2stdstring', 
[_Arg(s=svalue)]))
+def c_charp2stdstring(space, svalue, sz):
+return _cdata_to_cobject(
+space, call_capi(space, 'charp2stdstring', [_Arg(s=svalue), 
_Arg(l=sz)]))
 def c_stdstring2stdstring(space, cppobject):
 return _cdata_to_cobject(space, call_capi(space, 'stdstring2stdstring', 
[_Arg(h=cppobject)]))
 
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
@@ -563,7 +563,7 @@
 arg = InstanceConverter._unwrap_object(self, space, w_obj)
 return capi.c_stdstring2stdstring(space, arg)
 else:
-return capi.c_charp2stdstring(space, space.str_w(w_obj))
+return capi.c_charp2stdstring(space, space.str_w(w_obj), 
space.len_w(w_obj))
 
 def to_memory(self, space, w_obj, w_value, offset):
 try:
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
@@ -177,7 +177,7 @@
 void cppyy_free(void* ptr);
 
 RPY_EXTERN
-cppyy_object_t cppyy_charp2stdstring(const char* str);
+cppyy_object_t cppyy_charp2stdstring(const char* str, size_t sz);
 RPY_EXTERN
 cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr);
 
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -1405,8 +1405,8 @@
 free(ptr);
 }
 
-cppyy_object_t cppyy_charp2stdstring(const char* str){
-return (cppyy_object_t)new std::string(str);
+cppyy_object_t cppyy_charp2stdstring(const char* str, size_t sz){
+return (cppyy_object_t)new std::string(str, sz);
 }
 
 cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr){
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: simpler template handling

2016-07-12 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85671:7e5b01d3cab2
Date: 2016-07-12 11:40 -0700
http://bitbucket.org/pypy/pypy/changeset/7e5b01d3cab2/

Log:simpler template handling

diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -53,13 +53,6 @@
 compilation_info=backend.eci)
 def c_get_scope_opaque(space, name):
 return _c_get_scope_opaque(name)
-_c_get_template = rffi.llexternal(
-"cppyy_get_template",
-[rffi.CCHARP], C_TYPE,
-releasegil=ts_reflect,
-compilation_info=backend.eci)
-def c_get_template(space, name):
-return _c_get_template(name)
 _c_actual_class = rffi.llexternal(
 "cppyy_actual_class",
 [C_TYPE, C_OBJECT], C_TYPE,
@@ -238,6 +231,13 @@
 compilation_info=backend.eci)
 def c_is_namespace(space, scope):
 return _c_is_namespace(scope)
+_c_is_template = rffi.llexternal(
+"cppyy_is_template",
+[rffi.CCHARP], rffi.INT,
+releasegil=ts_reflect,
+compilation_info=backend.eci)
+def c_is_template(space, name):
+return _c_is_template(name)
 _c_is_abstract = rffi.llexternal(
 "cppyy_is_abstract",
 [C_SCOPE], rffi.INT,
diff --git a/pypy/module/cppyy/capi/loadable_capi.py 
b/pypy/module/cppyy/capi/loadable_capi.py
--- a/pypy/module/cppyy/capi/loadable_capi.py
+++ b/pypy/module/cppyy/capi/loadable_capi.py
@@ -126,7 +126,6 @@
 
 'resolve_name' : ([c_ccharp], 
c_ccharp),
 'get_scope': ([c_ccharp], c_scope),
-'get_template' : ([c_ccharp], c_type),
 'actual_class' : ([c_type, c_object], c_type),
 
 # memory management
@@ -162,6 +161,7 @@
 
 # scope reflection information
 'is_namespace' : ([c_scope],  c_int),
+'is_template'  : ([c_ccharp], c_int),
 'is_abstract'  : ([c_type],   c_int),
 'is_enum'  : ([c_ccharp], c_int),
 
@@ -291,8 +291,6 @@
 return charp2str_free(space, call_capi(space, 'resolve_name', 
[_Arg(s=name)]))
 def c_get_scope_opaque(space, name):
 return rffi.cast(C_SCOPE, space.uint_w(call_capi(space, 'get_scope', 
[_Arg(s=name)])))
-def c_get_template(space, name):
-return rffi.cast(C_TYPE, space.uint_w(call_capi(space, 'get_template', 
[_Arg(s=name)])))
 def c_actual_class(space, cppclass, cppobj):
 args = [_Arg(h=cppclass.handle), _Arg(h=cppobj)]
 return rffi.cast(C_TYPE, space.uint_w(call_capi(space, 'actual_class', 
args)))
@@ -368,6 +366,8 @@
 # scope reflection information ---
 def c_is_namespace(space, scope):
 return space.bool_w(call_capi(space, 'is_namespace', [_Arg(h=scope)]))
+def c_is_template(space, name):
+return space.bool_w(call_capi(space, 'is_template', [_Arg(s=name)]))
 def c_is_abstract(space, scope):
 return space.bool_w(call_capi(space, 'is_abstract', [_Arg(h=cpptype)]))
 def c_is_enum(space, name):
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
@@ -26,8 +26,6 @@
 RPY_EXTERN
 cppyy_scope_t cppyy_get_scope(const char* scope_name);
 RPY_EXTERN
-cppyy_type_t cppyy_get_template(const char* template_name);
-RPY_EXTERN
 cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t obj);
 
 /* memory management 
-- */
@@ -85,6 +83,8 @@
 RPY_EXTERN
 int cppyy_is_namespace(cppyy_scope_t scope);
 RPY_EXTERN
+int cppyy_is_template(const char* template_name);
+RPY_EXTERN
 int cppyy_is_abstract(cppyy_type_t type);
 RPY_EXTERN
 int cppyy_is_enum(const char* type_name);
diff --git a/pypy/module/cppyy/include/cpp_cppyy.h 
b/pypy/module/cppyy/include/cpp_cppyy.h
--- a/pypy/module/cppyy/include/cpp_cppyy.h
+++ b/pypy/module/cppyy/include/cpp_cppyy.h
@@ -6,21 +6,21 @@
 #include 
 #include 
 
-//ROOT types
-   typedef long   Long_t;
-   typedef unsigned long ULong_t;
-   typedef long long   Long64_t;
-   typedef unsigned long long ULong64_t;
-   typedef float   Float_t;
-   typedef double  Double_t;
-   typedef long double LongDouble_t;
-   typedef boolBool_t;
-   typedef charChar_t;
-   typedef unsigned char UChar_t;
-   typedef short   Short_t;
-   typedef unsigned short UShort_t;
-   typedef intInt_t;
-   typedef unsigned int UInt_t;
+// ROOT types
+typedef longLong_t;
+typedef unsigned longULong_t;
+typedef long longLong64_t;
+typedef unsigned long long   ULong64_t;
+typedef floatFloat_t;
+typedef double   Double_t;
+typede

[pypy-commit] pypy cling-support: fix configuration and reduce (direct) dependency on cpyext tests

2016-07-13 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85678:2e0d2cee85c8
Date: 2016-07-13 09:45 -0700
http://bitbucket.org/pypy/pypy/changeset/2e0d2cee85c8/

Log:fix configuration and reduce (direct) dependency on cpyext tests

diff --git a/pypy/module/cppyy/test/crossing.xml 
b/pypy/module/cppyy/test/crossing.xml
--- a/pypy/module/cppyy/test/crossing.xml
+++ b/pypy/module/cppyy/test/crossing.xml
@@ -1,7 +1,6 @@
 
 
   
-
-  
+  
 
 
diff --git a/pypy/module/cppyy/test/test_crossing.py 
b/pypy/module/cppyy/test/test_crossing.py
--- a/pypy/module/cppyy/test/test_crossing.py
+++ b/pypy/module/cppyy/test/test_crossing.py
@@ -9,8 +9,6 @@
 from pypy.module.cpyext import api
 from pypy.module.cpyext.state import State
 
-from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
-
 
 currpath = py.path.local(__file__).dirpath()
 test_dct = str(currpath.join("crossingDict.so"))
@@ -24,7 +22,7 @@
 
 # from pypy/module/cpyext/test/test_cpyext.py; modified to accept more external
 # symbols and called directly instead of import_module
-def compile_extension_module(space, modname, symbols, **kwds):
+def compile_extension_module(space, modname, **kwds):
 """
 Build an extension module and return the filename of the resulting native
 code file.
@@ -38,19 +36,23 @@
 state = space.fromcache(State)
 api_library = state.api_lib
 if sys.platform == 'win32':
-kwds["libraries"] = [api_library]
+kwds["libraries"] = []#[api_library]
 # '%s' undefined; assuming extern returning int
 kwds["compile_extra"] = ["/we4013"]
+# prevent linking with PythonXX.lib
+w_maj, w_min = space.fixedview(space.sys.get('version_info'), 5)[:2]
+kwds["link_extra"] = ["/NODEFAULTLIB:Python%d%d.lib" %
+  (space.int_w(w_maj), space.int_w(w_min))]
 elif sys.platform == 'darwin':
 kwds["link_files"] = [str(api_library + '.dylib')]
 else:
 kwds["link_files"] = [str(api_library + '.so')]
 if sys.platform.startswith('linux'):
-kwds["compile_extra"]=["-Werror=implicit-function-declaration"]
+kwds["compile_extra"]=["-Werror", "-g", "-O0"]
+kwds["link_extra"]=["-g"]
 
 modname = modname.split('.')[-1]
 eci = ExternalCompilationInfo(
-#export_symbols=['init%s' % (modname,)]+symbols,
 include_dirs=api.include_dirs,
 **kwds
 )
@@ -65,28 +67,30 @@
 soname.rename(pydname)
 return str(pydname)
 
-class AppTestCrossing(AppTestCpythonExtensionBase):
-spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools', 'cpyext'])
+class AppTestCrossing:
+spaceconfig = dict(usemodules=['cppyy', '_rawffi', 'itertools'])
 
 def setup_class(cls):
-AppTestCpythonExtensionBase.setup_class.im_func(cls)
 # cppyy specific additions (note that test_dct is loaded late
 # to allow the generated extension module be loaded first)
 cls.w_test_dct= cls.space.wrap(test_dct)
 cls.w_pre_imports = cls.space.appexec([], """():
-import cppyy, cpyext, ctypes""")# prevents leak-checking 
complaints on ctypes
+import ctypes, cppyy""")# prevents leak-checking complaints on 
ctypes' statics
 
 def setup_method(self, func):
-AppTestCpythonExtensionBase.setup_method.im_func(self, func)
-
 @unwrap_spec(name=str, init=str, body=str)
-def create_cdll(space, name, init, body, w_symbols):
+def create_cdll(space, name, init, body):
 # the following is loosely from test_cpyext.py import_module; it
 # is copied here to be able to tweak the call to
 # compile_extension_module and to get a different return result
 # than in that function
 code = """
 #include 
+/* fix for cpython 2.7 Python.h if running tests with -A
+   since pypy compiles with -fvisibility-hidden */
+#undef PyMODINIT_FUNC
+#define PyMODINIT_FUNC RPY_EXPORTED void
+
 %(body)s
 
 PyMODINIT_FUNC
@@ -95,8 +99,7 @@
 }
 """ % dict(name=name, init=init, body=body)
 kwds = dict(separate_module_sources=[code])
-symbols = [space.str_w(w_item) for w_item in 
space.fixedview(w_symbols)]
-mod = compile_extension_module(space, name, symbols, **kwds)
+mod = compile_extension_module(space, name, **kwds)
 
 # explicitly load the module as a CDLL rather than as a module
 from pypy.module.imp.importing import get_so_extension
@@ -106,17 +109,6 @@
 
 self.w_create_cdll = self.space.wrap(interp2app(create_cdll))
 
-def test00_base_class(self):
-"""Test from cpyext; only here to see whether the imported class 
works"""
-
-import sys
-init = """
-if (Py_IsInitialized())
-Py_InitModule("foo", NULL);
-"""

[pypy-commit] pypy cling-support: drop the use of g_globalfuncs vars as it is no longer needed for life-time management

2016-07-14 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85703:d24dadc47ff8
Date: 2016-07-14 11:09 -0700
http://bitbucket.org/pypy/pypy/changeset/d24dadc47ff8/

Log:drop the use of g_globalfuncs vars as it is no longer needed for
life-time management

diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -48,9 +48,6 @@
 typedef std::map< Cppyy::TCppMethod_t, CallFunc_t* > Method2CallFunc_t;
 static Method2CallFunc_t g_method2callfunc;
 
-typedef std::vector< TFunction > GlobalFuncs_t;
-static GlobalFuncs_t g_globalfuncs;
-
 typedef std::vector< TGlobal* > GlobalVars_t;
 static GlobalVars_t g_globalvars;
 
@@ -699,24 +696,19 @@
 {
TClassRef& cr = type_from_handle (scope);
if (cr.GetClass())
-return (TCppIndex_t)imeth;
-assert(handle == (TCppType_t)GLOBAL_HANDLE);
-return (TCppIndex_t)&g_globalfuncs[imeth];
+  return (TCppIndex_t)imeth;
+   assert(handle == (TCppType_t)GLOBAL_HANDLE);
+   return imeth;
 }
 
 std::vector< Cppyy::TCppMethod_t > Cppyy::GetMethodsFromName(
   TCppScope_t scope, const std::string& name )
 {
-// TODO: this method assumes that the call for this name is made only
-// once, and thus there is no need to store the results of the search
-// in g_globalfuncs ... probably true, but needs verification
std::vector< TCppMethod_t > methods;
if ( scope == GLOBAL_HANDLE ) {
   TCollection* funcs = gROOT->GetListOfGlobalFunctions( kTRUE );
-  g_globalfuncs.reserve(funcs->GetSize());
 
   TIter ifunc(funcs);
-
   TFunction* func = 0;
   while ( (func = (TFunction*)ifunc.Next()) ) {
   // cover not only direct matches, but also template matches
@@ -822,18 +814,20 @@
 {
TClassRef& cr = type_from_handle( scope );
TFunction* f = type_get_method( scope, imeth );
-   std::ostringstream sig;
-   if ( cr.GetClass() && cr->GetClassInfo() )
-  sig << f->GetReturnTypeName() << " ";
-   sig << cr.GetClassName() << "::" << f->GetName() << "(";
-   int nArgs = f->GetNargs();
-   for ( int iarg = 0; iarg < nArgs; ++iarg ) {
-  sig << ((TMethodArg*)f->GetListOfMethodArgs()->At( iarg 
))->GetFullTypeName();
-  if (iarg != nArgs-1)
- sig << ", ";
+   if ( cr.GetClass() && cr->GetClassInfo() ) {
+  std::ostringstream sig;
+  sig << f->GetReturnTypeName() << " "
+  << cr.GetClassName() << "::" << f->GetName() << "(";
+  int nArgs = f->GetNargs();
+  for ( int iarg = 0; iarg < nArgs; ++iarg ) {
+ sig << ((TMethodArg*)f->GetListOfMethodArgs()->At( iarg 
))->GetFullTypeName();
+ if (iarg != nArgs-1)
+sig << ", ";
+  }
+  sig << ")" << std::ends;
+  return cppstring_to_cstring(sig.str());
}
-   sig << ")" << std::ends;
-   return cppstring_to_cstring(sig.str());
+   return "";
 }
 
 Bool_t Cppyy::IsConstMethod( TCppMethod_t method )
@@ -1246,23 +1240,23 @@
 }
 
 int cppyy_is_subtype(cppyy_type_t derived, cppyy_type_t base){
-return (int)Cppyy::IsSubtype( derived, base );
+return (int)Cppyy::IsSubtype(derived, base);
 }
 
 
 /* calculate offsets between declared and actual type, up-cast: direction > 0; 
down-cast: direction < 0 */
 ptrdiff_t cppyy_base_offset(cppyy_type_t derived, cppyy_type_t base, 
cppyy_object_t address, int direction) {
-return (ptrdiff_t)Cppyy::GetBaseOffset(derived, base, (void*)address, 
direction,   0);
+return (ptrdiff_t)Cppyy::GetBaseOffset(derived, base, (void*)address, 
direction, 0);
 }
 
 
 /* method/function reflection information - */
 int cppyy_num_methods(cppyy_scope_t scope) {
-return (int)Cppyy::GetNumMethods (scope);
+return (int)Cppyy::GetNumMethods(scope);
 }
 
 cppyy_index_t cppyy_method_index_at(cppyy_scope_t scope, int imeth) {
-return cppyy_index_t(Cppyy::GetMethodIndexAt (scope, imeth));
+return cppyy_index_t(Cppyy::GetMethodIndexAt(scope, imeth));
 }
 
 cppyy_index_t* cppyy_method_indices_from_name(cppyy_scope_t scope, const char* 
name){
@@ -1275,7 +1269,7 @@
 TIter next(cr->GetListOfMethods());
 while ((func = (TFunction*)next())) {
 if (strcmp(name, func->GetName()) == 0) {
-if (func->Property() & 
Cppyy::IsPublicMethod((cppyy_method_t)func))
+if (Cppyy::IsPublicMethod((cppyy_method_t)func))
 result.push_back((cppyy_index_t)imeth);
 }
 ++imeth;
@@ -1285,10 +1279,8 @@
 TFunction* func = 0;
 TIter ifunc(funcs);
 while ((func = (TFunction*)ifunc.Next())) {
-if (strcmp(name, func->GetName()) == 0) {
-g_globalfuncs.push_back(*func);
+if (strcmp(name, func->GetName()) == 0)
 result.push_back((cppyy_index_t)func);
-}
 }
 }
 
___
pypy-commit mailing list
pypy-comm

[pypy-commit] pypy cling-support: from Aditi: add signature strings

2016-07-14 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85702:60f4ffb2e3b4
Date: 2016-07-14 09:44 -0700
http://bitbucket.org/pypy/pypy/changeset/60f4ffb2e3b4/

Log:from Aditi: add signature strings

diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -818,9 +818,22 @@
return "";
 }
 
-std::string Cppyy::GetMethodSignature( TCppScope_t /* scope */, TCppIndex_t /* 
imeth */ )
+std::string Cppyy::GetMethodSignature( TCppScope_t scope, TCppIndex_t imeth )
 {
-   return "";
+   TClassRef& cr = type_from_handle( scope );
+   TFunction* f = type_get_method( scope, imeth );
+   std::ostringstream sig;
+   if ( cr.GetClass() && cr->GetClassInfo() )
+  sig << f->GetReturnTypeName() << " ";
+   sig << cr.GetClassName() << "::" << f->GetName() << "(";
+   int nArgs = f->GetNargs();
+   for ( int iarg = 0; iarg < nArgs; ++iarg ) {
+  sig << ((TMethodArg*)f->GetListOfMethodArgs()->At( iarg 
))->GetFullTypeName();
+  if (iarg != nArgs-1)
+ sig << ", ";
+   }
+   sig << ")" << std::ends;
+   return cppstring_to_cstring(sig.str());
 }
 
 Bool_t Cppyy::IsConstMethod( TCppMethod_t method )
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: from Aditi: proper message on failure to load dictionary file

2016-07-14 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85701:6d4c1909c9ad
Date: 2016-07-14 09:30 -0700
http://bitbucket.org/pypy/pypy/changeset/6d4c1909c9ad/

Log:from Aditi: proper message on failure to load dictionary file

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
@@ -32,6 +32,9 @@
 def load_dictionary(space, name):
 try:
 cdll = capi.c_load_dictionary(name)
+if not cdll:
+   raise OperationError(space.w_RuntimeError, space.wrap(str("could 
not load dictionary " + name)))
+
 except rdynload.DLOpenError as e:
 raise OperationError(space.w_RuntimeError, space.wrap(str(e.msg)))
 return W_CPPLibrary(space, cdll)
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -20,6 +20,7 @@
 #include "TMethod.h"
 #include "TMethodArg.h"
 #include "TROOT.h"
+#include "TSystem.h"
 
 // Standard
 #include 
@@ -165,9 +166,10 @@
if ( icr != g_name2classrefidx.end() )
   return (TCppType_t)icr->second;
 
-   // use TClass directly, to enable auto-loading
+// use TClass directly, to enable auto-loading; class may be stubbed (eg. for
+// function returns) leading to a non-null TClass that is otherwise invalid
TClassRef cr( TClass::GetClass( scope_name.c_str(), kTRUE, kTRUE ) );
-   if ( !cr.GetClass() )
+   if ( !cr.GetClass() || !cr->Property() )
   return (TCppScope_t)NULL;
 
// no check for ClassInfo as forward declared classes are okay (fragile)
@@ -1390,7 +1392,8 @@
 /* misc helpers --- */
 RPY_EXTERN
 void* cppyy_load_dictionary(const char* lib_name) {
-return (void*)(gInterpreter->Load(lib_name) == 0);
+int result = gSystem->Load(lib_name);
+return (void*)(result == 0 /* success */ || result == 1 /* already loaded 
*/);
 }
 
 long long cppyy_strtoll(const char* str) {
diff --git a/pypy/module/cppyy/test/test_cppyy.py 
b/pypy/module/cppyy/test/test_cppyy.py
--- a/pypy/module/cppyy/test/test_cppyy.py
+++ b/pypy/module/cppyy/test/test_cppyy.py
@@ -4,7 +4,7 @@
 
 
 currpath = py.path.local(__file__).dirpath()
-test_dct = str(currpath.join("example01_rflx_rdict.pcm"))#example01Dict.so"))
+test_dct = str(currpath.join("example01Dict.so"))
 
 def setup_module(mod):
 if sys.platform == 'win32':
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: clean up some warnings about duplicates

2016-07-14 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85716:e6e59e1bc7fa
Date: 2016-07-14 15:09 -0700
http://bitbucket.org/pypy/pypy/changeset/e6e59e1bc7fa/

Log:clean up some warnings about duplicates

diff --git a/pypy/module/cppyy/test/stltypes.xml 
b/pypy/module/cppyy/test/stltypes.xml
--- a/pypy/module/cppyy/test/stltypes.xml
+++ b/pypy/module/cppyy/test/stltypes.xml
@@ -12,11 +12,11 @@
-->
 
   
-  
+  
   
 
-  
+  
 
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: implement lookup of global operators

2016-07-14 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85717:14334ff3d976
Date: 2016-07-14 15:20 -0700
http://bitbucket.org/pypy/pypy/changeset/14334ff3d976/

Log:implement lookup of global operators

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
@@ -1095,9 +1095,10 @@
 try:
 # TODO: expecting w_other to be an W_CPPInstance is too limiting
 other = self.space.interp_w(W_CPPInstance, w_other, 
can_be_None=False)
-for name in ["", "__gnu_cxx"]:
+for name in ["", "__gnu_cxx", "__1"]:
 nss = scope_byname(self.space, name)
-meth_idx = capi.c_get_global_operator(self.space, nss, 
self.cppclass, other.cppclass, "==")
+meth_idx = capi.c_get_global_operator(
+self.space, nss, self.cppclass, other.cppclass, 
"operator==")
 if meth_idx != -1:
 f = nss._make_cppfunction("operator==", meth_idx)
 ol = W_CPPOverload(self.space, nss, [f])
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -112,10 +112,10 @@
 }
 
 static inline
-char* cppstring_to_cstring(const std::string& name) {
-char* name_char = (char*)malloc(name.size() + 1);
-strcpy(name_char, name.c_str());
-return name_char;
+char* cppstring_to_cstring( const std::string& name ) {
+   char* name_char = (char*)malloc(name.size() + 1 );
+   strcpy( name_char, name.c_str() );
+   return name_char;
 }
 
 
@@ -863,9 +863,23 @@
 }
 
 Cppyy::TCppIndex_t Cppyy::GetGlobalOperator(
-  TCppScope_t /* scope */, TCppType_t /* lc */, TCppType_t /* rc */, const 
std::string& /* op */ )
+  TCppScope_t scope, TCppType_t lc, TCppType_t rc, const std::string& 
opname )
 {
-   return (TCppIndex_t)0;
+// Find a global operator function with a matching signature
+   std::string proto = GetScopedFinalName(lc) + ", " + GetScopedFinalName(rc);
+   if ( scope == (cppyy_scope_t)GLOBAL_HANDLE ) {
+  TFunction* func = gROOT->GetGlobalFunctionWithPrototype( opname.c_str(), 
proto.c_str() );
+  if (func) return (TCppIndex_t)func;
+   } else {
+  TClassRef& cr = type_from_handle( scope );
+  if ( cr.GetClass() ) {
+ TFunction* func = cr->GetMethodWithPrototype( opname.c_str(), 
proto.c_str() );
+ if ( func ) return (TCppIndex_t)cr->GetListOfMethods()->IndexOf( func 
);
+  }
+   }
+
+// failure ...
+   return (TCppIndex_t)-1;
 }
 
 // method properties -
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: rudimentary support for templated functions

2016-07-18 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85764:f5aadcd69784
Date: 2016-07-18 15:48 -0700
http://bitbucket.org/pypy/pypy/changeset/f5aadcd69784/

Log:rudimentary support for templated functions

diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -24,6 +24,7 @@
 
 // Standard
 #include 
+#include  // for std::count
 #include 
 #include 
 #include 
@@ -743,8 +744,8 @@
 {
if ( method ) {
   std::string name = ((TFunction*)method)->GetName();
-  //if ( IsMethodTemplate( method ) )
-  //   return name.substr( 0, name.find('<') );
+  if ( IsMethodTemplate( method ) )
+ return name.substr( 0, name.find('<') );
   return name;
}
return "";
@@ -844,6 +845,8 @@
 {
if ( method ) {
   TFunction* f = (TFunction*)method;
+  if ( f->ExtraProperty() & kIsConstructor )
+ return kFALSE;
   std::string name = f->GetName();
   return (name[name.size()-1] == '>') && (name.find('<') != 
std::string::npos);
}
@@ -851,15 +854,29 @@
 }
 
 Cppyy::TCppIndex_t Cppyy::GetMethodNumTemplateArgs(
-  TCppScope_t /* scope */, TCppIndex_t /* imeth */ )
+  TCppScope_t scope, TCppIndex_t imeth )
 {
-   return (TCppIndex_t)0;
+// this is dumb, but the fact that Cling can instantiate template
+// methods on-the-fly means that there is some vast reworking TODO
+// in interp_cppyy.py, so this is just to make the original tests
+// pass that worked in the Reflex era ...
+   const std::string name = GetMethodName(GetMethod(scope, imeth));
+   return (TCppIndex_t)(std::count( name.begin(), name.end(), ',' ) + 1);
 }
 
 std::string Cppyy::GetMethodTemplateArgName(
-  TCppScope_t /* scope */, TCppIndex_t /* imeth */, TCppIndex_t /* iarg */ 
)
+  TCppScope_t scope, TCppIndex_t imeth, TCppIndex_t /* iarg */ )
 {
-   return "";
+// TODO: like above, given Cling's instantiation capability, this
+// is just dumb ...
+   TClassRef& cr = type_from_handle( scope );
+   TFunction* f = type_get_method( scope, imeth );
+   std::string name = f->GetName();
+   std::string::size_type pos = name.find( '<' );
+// TODO: left as-is, this should loop over arguments, but what is here
+// suffices to pass the Reflex-based tests (need more tests :) )
+   return cppstring_to_cstring(
+  ResolveName( name.substr(pos+1, name.size()-pos-2) ) );
 }
 
 Cppyy::TCppIndex_t Cppyy::GetGlobalOperator(
@@ -1273,7 +1290,17 @@
 return cppyy_index_t(Cppyy::GetMethodIndexAt(scope, imeth));
 }
 
-cppyy_index_t* cppyy_method_indices_from_name(cppyy_scope_t scope, const char* 
name){
+static inline bool match_name(const std::string& tname, const std::string 
fname) {
+// either match exactly, or match the name as template
+   if (fname.rfind(tname, 0) == 0) {
+  if ( (tname.size() == fname.size()) ||
+   (tname.size() < fname.size() && fname[tname.size()] == '<') )
+ return true;
+   }
+   return false;
+}
+
+cppyy_index_t* cppyy_method_indices_from_name(cppyy_scope_t scope, const char* 
name) {
 std::vector result;
 TClassRef& cr = type_from_handle(scope);
 if (cr.GetClass()) {
@@ -1282,7 +1309,7 @@
 TFunction* func;
 TIter next(cr->GetListOfMethods());
 while ((func = (TFunction*)next())) {
-if (strcmp(name, func->GetName()) == 0) {
+if (match_name(name, func->GetName())) {
 if (Cppyy::IsPublicMethod((cppyy_method_t)func))
 result.push_back((cppyy_index_t)imeth);
 }
@@ -1293,7 +1320,7 @@
 TFunction* func = 0;
 TIter ifunc(funcs);
 while ((func = (TFunction*)ifunc.Next())) {
-if (strcmp(name, func->GetName()) == 0)
+if (match_name(name, func->GetName()))
 result.push_back((cppyy_index_t)func);
 }
 }
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: translator fixes

2016-07-21 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85800:580f6e7ccf32
Date: 2016-07-21 20:51 -0700
http://bitbucket.org/pypy/pypy/changeset/580f6e7ccf32/

Log:translator fixes

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
@@ -744,7 +744,7 @@
 
 type_info = (
 (rffi.LONG,   ("long", "long int"),'l'),
-(rffi.LONGLONG,   ("long long", "long long int", "Long64_t"),  'k'),
+(rffi.LONGLONG,   ("long long", "long long int", "Long64_t"),  'q'),
 )
 
 for c_type, names, c_tc in type_info:
@@ -765,7 +765,7 @@
 (rffi.USHORT, ("unsigned short", "unsigned short int"),
'H'),
 (rffi.UINT,   ("unsigned", "unsigned int"),
'I'),
 (rffi.ULONG,  ("unsigned long", "unsigned long int"),  
'L'),
-(rffi.ULONGLONG,  ("unsigned long long", "unsigned long long int", 
"ULong64_t"),   'K'),
+(rffi.ULONGLONG,  ("unsigned long long", "unsigned long long int", 
"ULong64_t"),   'Q'),
 )
 
 for c_type, names, c_tc in type_info:
@@ -787,17 +787,18 @@
 def _build_array_converters():
 "NOT_RPYTHON"
 array_info = (
-('b', rffi.sizeof(rffi.UCHAR),  ("bool",)),# is debatable, but 
works ...
-('h', rffi.sizeof(rffi.SHORT),  ("short int", "short")),
-('H', rffi.sizeof(rffi.USHORT), ("unsigned short int", "unsigned 
short")),
-('i', rffi.sizeof(rffi.INT),("int",)),
-('I', rffi.sizeof(rffi.UINT),   ("unsigned int", "unsigned")),
-('l', rffi.sizeof(rffi.LONG),   ("long int", "long")),
-('L', rffi.sizeof(rffi.ULONG),  ("unsigned long int", "unsigned 
long")),
-('k', rffi.sizeof(rffi.LONGLONG),("long long", "long long int", 
"Long64_t")),
-('K', rffi.sizeof(rffi.ULONGLONG),("unsigned long long", "unsigned 
long long int", "ULong64_t")),
-('f', rffi.sizeof(rffi.FLOAT),  ("float",)),
-('d', rffi.sizeof(rffi.DOUBLE), ("double",)),
+('b', rffi.sizeof(rffi.UCHAR),  ("bool",)),# is debatable, but 
works ...
+('h', rffi.sizeof(rffi.SHORT),  ("short int", "short")),
+('H', rffi.sizeof(rffi.USHORT), ("unsigned short int", "unsigned 
short")),
+('i', rffi.sizeof(rffi.INT),("int",)),
+('I', rffi.sizeof(rffi.UINT),   ("unsigned int", "unsigned")),
+('l', rffi.sizeof(rffi.LONG),   ("long int", "long")),
+('L', rffi.sizeof(rffi.ULONG),  ("unsigned long int", "unsigned 
long")),
+('q', rffi.sizeof(rffi.LONGLONG),   ("long long", "long long int", 
"Long64_t")),
+('Q', rffi.sizeof(rffi.ULONGLONG),  ("unsigned long long", "unsigned 
long long int", "ULong64_t")),
+('f', rffi.sizeof(rffi.FLOAT),  ("float",)),
+('d', rffi.sizeof(rffi.DOUBLE), ("double",)),
+('g', rffi.sizeof(rffi.LONGDOUBLE), ("long double",)),
 )
 
 for tcode, tsize, names in array_info:
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -362,10 +362,10 @@
   case 'L':  /* unsigned long */
  vargs[i] = (void*)&args[i].fValue.fULong;
  break;
-  case 'k':  /* long long */
+  case 'q':  /* long long */
  vargs[i] = (void*)&args[i].fValue.fLongLong;
  break;
-  case 'K':  /* unsigned long long */
+  case 'Q':  /* unsigned long long */
  vargs[i] = (void*)&args[i].fValue.fULongLong;
  break;
   case 'f':  /* float */
@@ -374,7 +374,7 @@
   case 'd':  /* double */
  vargs[i] = (void*)&args[i].fValue.fDouble;
  break;
-  case 'D':  /* long double */
+  case 'g':  /* long double */
  vargs[i] = (void*)&args[i].fValue.fLongDouble;
  break;
   case 'a':
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: enable rootcling building, removing rootcint

2016-07-21 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85798:4b61ab0825f2
Date: 2016-07-19 11:28 -0700
http://bitbucket.org/pypy/pypy/changeset/4b61ab0825f2/

Log:enable rootcling building, removing rootcint

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
@@ -16,14 +16,10 @@
 else
   ifeq ($(ROOTSYS),)
 genreflex=genreflex
-cppflags=-I$(ROOTSYS)/include -L$(ROOTSYS)/lib64 -L$(ROOTSYS)/lib
+cppflags=-pthread -std=c++11 -m64 -I./include -L./lib64 -L./lib
   else
 genreflex=$(ROOTSYS)/bin/genreflex
-ifeq ($(wildcard $(ROOTSYS)/include),)   # standard locations used?
-  cppflags=-I$(shell root-config --incdir) -L$(shell root-config --libdir)
-else
-  cppflags=-I$(ROOTSYS)/include -L$(ROOTSYS)/lib64 -L$(ROOTSYS)/lib
-endif
+cppflags=$(shell $(ROOTSYS)/bin/root-config --cflags) $(shell 
$(ROOTSYS)/bin/root-config --ldflags)
   endif
 endif
 
@@ -34,7 +30,7 @@
 
 ifeq ($(DUMMY),t)
   cppflags2=-O3 -fPIC -rdynamic
-else ifeq ($(CINT),t)
+else ifeq ($(CLING),t)
   cppflags2=-O3 -fPIC -rdynamic
 else
   ifeq ($(shell $(genreflex) --help | grep -- --with-methptrgetter),)
@@ -46,13 +42,12 @@
   endif
 endif
 
-ifeq ($(CINT),t)
-%Dict.so: %_cint.cxx %.cxx
-   g++ -o $@ $^ -shared $(cppflags) $(cppflags2)
-   rlibmap -f -o $*Dict.rootmap -l $@ -c $*_LinkDef.h
+ifeq ($(CLING),t)
+%Dict.so: %.h %.cxx %_cling.cxx
+   g++ -o $@ $*.cxx $*_cling.cxx -shared $(cppflags) $(cppflags2)
 
-%_cint.cxx: %.h %_LinkDef.h
-   rootcint -f $@ -c $*.h $*_LinkDef.h
+%_cling.cxx: %.h %_LinkDef.h
+   rootcling -f $@ -rml $*Dict.so -rmf $*Dict.rootmap -c $*.h $*_LinkDef.h
 
 else ifeq ($(DUMMY),t)
 %Dict.so: %.cxx
@@ -67,7 +62,7 @@
 
 endif
 
-ifeq ($(CINT),)
+ifeq ($(CLING),)
 ifeq ($(DUMMY),)
 # TODO: methptrgetter causes these tests to crash, so don't use it for now
 std_streamsDict.so: std_streams.cxx std_streams.h std_streams.xml
@@ -78,4 +73,4 @@
 
 .PHONY: clean
 clean:
-   -rm -f $(dicts) $(subst .so,.rootmap,$(dicts)) $(subst 
Dict.so,_rflx_rdict.pcm,$(dicts)) $(wildcard *_cint.h)
+   -rm -f $(dicts) $(subst .so,.rootmap,$(dicts)) $(subst 
Dict.so,_rflx_rdict.pcm,$(dicts)) $(subst Dict.so,_rflx.cpp,$(dicts)) $(subst 
Dict.so,_cling.h,$(dicts)) $(subst Dict.so,_cling.cxx,$(dicts)) $(subst 
Dict.so,_cling_rdict.pcm,$(dicts)) $(wildcard *.pyc)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: fix the mechanics of test_zjit; TODO: the test actually succeeds

2016-07-21 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85799:f30be95c828b
Date: 2016-07-19 11:50 -0700
http://bitbucket.org/pypy/pypy/changeset/f30be95c828b/

Log:fix the mechanics of test_zjit; TODO: the test actually succeeds
even with cppyy_get_methptr_getter returning 0, so the test isn't
testing the number of layers correctly anymore (probably due to
improvements elsewhere in the 'slow path'?)

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
@@ -36,7 +36,11 @@
raise OperationError(space.w_RuntimeError, space.wrap(str("could 
not load dictionary " + name)))
 
 except rdynload.DLOpenError as e:
-raise OperationError(space.w_RuntimeError, space.wrap(str(e.msg)))
+if hasattr(space, "fake"):  # FakeSpace fails e.msg (?!)
+errmsg = "failed to load cdll"
+else:
+errmsg = e.msg
+raise OperationError(space.w_RuntimeError, space.wrap(str(errmsg)))
 return W_CPPLibrary(space, cdll)
 
 class State(object):
@@ -1037,7 +1041,8 @@
 self._opt_register_finalizer()
 
 def _opt_register_finalizer(self):
-if self.python_owns and not self.finalizer_registered:
+if self.python_owns and not self.finalizer_registered \
+   and not hasattr(self.space, "fake"):
 self.register_finalizer(self.space)
 self.finalizer_registered = True
 
diff --git a/pypy/module/cppyy/test/test_zjit.py 
b/pypy/module/cppyy/test/test_zjit.py
--- a/pypy/module/cppyy/test/test_zjit.py
+++ b/pypy/module/cppyy/test/test_zjit.py
@@ -71,7 +71,7 @@
 class FakeException(FakeType):
 def __init__(self, name):
 FakeType.__init__(self, name)
-self.message = name
+self.msg = name
 
 class FakeUserDelAction(object):
 def __init__(self, space):
@@ -210,6 +210,7 @@
 f()
 space = FakeSpace()
 result = self.meta_interp(f, [], listops=True, backendopt=True, 
listcomp=True)
+# TODO: this currently succeeds even as there is no fast path 
implemented?!
 self.check_jitcell_token_count(1)
 
 def test01_simple(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: remove more warnings

2016-07-21 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85797:92acdaca78a7
Date: 2016-07-19 10:27 -0700
http://bitbucket.org/pypy/pypy/changeset/92acdaca78a7/

Log:remove more warnings

diff --git a/pypy/module/cppyy/test/overloads.xml 
b/pypy/module/cppyy/test/overloads.xml
--- a/pypy/module/cppyy/test/overloads.xml
+++ b/pypy/module/cppyy/test/overloads.xml
@@ -4,8 +4,11 @@
 
   
 
-  
-  
+  
+  
+
+  
+  
 
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cling-support: take care of special case global pointers

2016-07-28 Thread wlav
Author: Wim Lavrijsen 
Branch: cling-support
Changeset: r85897:3a3e429e58c8
Date: 2016-07-28 11:37 -0700
http://bitbucket.org/pypy/pypy/changeset/3a3e429e58c8/

Log:take care of special case global pointers

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
@@ -517,8 +517,7 @@
 def from_memory(self, space, w_obj, w_pycppclass, offset):
 address = rffi.cast(capi.C_OBJECT, self._get_raw_address(space, w_obj, 
offset))
 from pypy.module.cppyy import interp_cppyy
-return interp_cppyy.wrap_cppobject(space, address, self.cppclass,
-   do_cast=False, is_ref=True)
+return interp_cppyy.wrap_cppobject(space, address, self.cppclass, 
do_cast=False)
 
 def to_memory(self, space, w_obj, w_value, offset):
 address = rffi.cast(rffi.VOIDPP, self._get_raw_address(space, w_obj, 
offset))
@@ -549,6 +548,11 @@
 r = rffi.cast(rffi.VOIDPP, call_local)
 w_obj._rawobject = rffi.cast(capi.C_OBJECT, r[0])
 
+def from_memory(self, space, w_obj, w_pycppclass, offset):
+address = rffi.cast(capi.C_OBJECT, self._get_raw_address(space, w_obj, 
offset))
+from pypy.module.cppyy import interp_cppyy
+return interp_cppyy.wrap_cppobject(space, address, self.cppclass,
+   do_cast=False, is_ref=True)
 
 class StdStringConverter(InstanceConverter):
 
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx 
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -956,6 +956,7 @@
   TGlobal* gbl = g_globalvars[ idata ];
   std::string fullType = gbl->GetFullTypeName();
   if ( fullType[fullType.size()-1] == '*' && \
+   !dynamic_cast(gbl) && \
fullType.find( "char", 0, 4 ) == std::string::npos )
  fullType.append( "*" );
   else if ( (int)gbl->GetArrayDim() > 1 )
diff --git a/pypy/module/cppyy/test/advancedcpp.cxx 
b/pypy/module/cppyy/test/advancedcpp.cxx
--- a/pypy/module/cppyy/test/advancedcpp.cxx
+++ b/pypy/module/cppyy/test/advancedcpp.cxx
@@ -73,7 +73,8 @@
 // a couple of globals for access testing
 double my_global_double = 12.;
 double my_global_array[500];
-
+static double sd = 1234.;
+double* my_global_ptr = &sd;
 
 // for life-line and identity testing
 int some_class_with_data::some_data::s_num_data = 0;
diff --git a/pypy/module/cppyy/test/advancedcpp.h 
b/pypy/module/cppyy/test/advancedcpp.h
--- a/pypy/module/cppyy/test/advancedcpp.h
+++ b/pypy/module/cppyy/test/advancedcpp.h
@@ -276,7 +276,7 @@
 //===
 extern double my_global_double;// a couple of globals for access testing
 extern double my_global_array[500];
-
+extern double* my_global_ptr;
 
 //===
 class some_class_with_data {   // for life-line and identity testing
diff --git a/pypy/module/cppyy/test/advancedcpp.xml 
b/pypy/module/cppyy/test/advancedcpp.xml
--- a/pypy/module/cppyy/test/advancedcpp.xml
+++ b/pypy/module/cppyy/test/advancedcpp.xml
@@ -34,9 +34,12 @@
   
 
   
-  
-  
+  
+  
 
+  
+  
+  
 
   
   
diff --git a/pypy/module/cppyy/test/test_advancedcpp.py 
b/pypy/module/cppyy/test/test_advancedcpp.py
--- a/pypy/module/cppyy/test/test_advancedcpp.py
+++ b/pypy/module/cppyy/test/test_advancedcpp.py
@@ -669,3 +669,14 @@
 
 assert cppyy.gbl.overload_one_way().gime() == 1
 assert cppyy.gbl.overload_the_other_way().gime() == "aap"
+
+def test22_access_to_global_variables(self):
+"""Access global_variables_and_pointers"""
+
+import cppyy
+
+assert cppyy.gbl.my_global_double == 12.
+assert len(cppyy.gbl.my_global_array) == 500
+# TODO: currently fails b/c double** not understood as &double*
+#assert cppyy.gbl.my_global_ptr[0] == 1234.
+
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reflex-support: close reflex-support

2015-07-20 Thread wlav
Author: Wim Lavrijsen 
Branch: reflex-support
Changeset: r78620:a5036b5b1dd8
Date: 2015-07-20 12:10 -0700
http://bitbucket.org/pypy/pypy/changeset/a5036b5b1dd8/

Log:close reflex-support

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reflex-support: update bound classes for added tests

2015-07-20 Thread wlav
Author: Wim Lavrijsen 
Branch: reflex-support
Changeset: r78619:d3bef9990ae7
Date: 2014-07-16 13:00 -0700
http://bitbucket.org/pypy/pypy/changeset/d3bef9990ae7/

Log:update bound classes for added tests

diff --git a/pypy/module/cppyy/test/example01_LinkDef.h 
b/pypy/module/cppyy/test/example01_LinkDef.h
--- a/pypy/module/cppyy/test/example01_LinkDef.h
+++ b/pypy/module/cppyy/test/example01_LinkDef.h
@@ -7,6 +7,9 @@
 #pragma link C++ class example01;
 #pragma link C++ typedef example01_t;
 #pragma link C++ class example01a;
+#pragma link C++ class example01b;
+#pragma link C++ class example01c;
+#pragma link C++ class example01d;
 #pragma link C++ class payload;
 #pragma link C++ class ArgPasser;
 #pragma link C++ class z_;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reflex-support: merge default into branch and fix error message for dlopen

2015-07-20 Thread wlav
Author: Wim Lavrijsen 
Branch: reflex-support
Changeset: r78618:ef58dc5560e2
Date: 2014-07-16 12:42 -0700
http://bitbucket.org/pypy/pypy/changeset/ef58dc5560e2/

Log:merge default into branch and fix error message for dlopen

diff too long, truncating to 2000 out of 40954 lines

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -6,3 +6,11 @@
 9b623bc48b5950cf07184462a0e48f2c4df0d720 pypy-2.1-beta1-arm
 9b623bc48b5950cf07184462a0e48f2c4df0d720 pypy-2.1-beta1-arm
 ab0dd631c22015ed88e583d9fdd4c43eebf0be21 pypy-2.1-beta1-arm
+20e51c4389ed4469b66bb9d6289ce0ecfc82c4b9 release-2.3.0
+20e51c4389ed4469b66bb9d6289ce0ecfc82c4b9 release-2.3.0
+ release-2.3.0
+394146e9bb673514c61f0150ab2013ccf78e8de7 release-2.3
+32f35069a16d819b58c1b6efb17c44e3e53397b2 release-2.2=3.1
+32f35069a16d819b58c1b6efb17c44e3e53397b2 release-2.3.1
+32f35069a16d819b58c1b6efb17c44e3e53397b2 release-2.2=3.1
+ release-2.2=3.1
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -44,31 +44,33 @@
 Alex Gaynor
 Michael Hudson
 David Schneider
+Matti Picus
+Brian Kearns
+Philip Jenvey
 Holger Krekel
 Christian Tismer
 Hakan Ardo
 Benjamin Peterson
-Matti Picus
-Philip Jenvey
+Manuel Jacob
 Anders Chrigstrom
-Brian Kearns
 Eric van Riet Paap
+Wim Lavrijsen
+Ronan Lamy
 Richard Emslie
 Alexander Schremmer
-Wim Lavrijsen
 Dan Villiom Podlaski Christiansen
-Manuel Jacob
 Lukas Diekmann
 Sven Hager
 Anders Lehmann
 Aurelien Campeas
 Niklaus Haldimann
-Ronan Lamy
 Camillo Bruni
 Laura Creighton
 Toon Verwaest
+Remi Meier
 Leonardo Santagada
 Seo Sanghyeon
+Romain Guillebert
 Justin Peel
 Ronny Pfannschmidt
 David Edelsohn
@@ -80,52 +82,62 @@
 Daniel Roberts
 Niko Matsakis
 Adrien Di Mascio
+Alexander Hesse
 Ludovic Aubry
-Alexander Hesse
 Jacob Hallen
-Romain Guillebert
 Jason Creighton
 Alex Martelli
 Michal Bendowski
 Jan de Mooij
+stian
 Michael Foord
 Stephan Diehl
 Stefan Schwarzer
 Valentino Volonghi
 Tomek Meka
 Patrick Maupin
-stian
 Bob Ippolito
 Bruno Gola
 Jean-Paul Calderone
 Timo Paulssen
+Squeaky
 Alexandre Fayolle
 Simon Burton
 Marius Gedminas
 John Witulski
+Konstantin Lopuhin
 Greg Price
 Dario Bertini
 Mark Pearse
 Simon Cross
-Konstantin Lopuhin
 Andreas Stührk
 Jean-Philippe St. Pierre
 Guido van Rossum
 Pavel Vinogradov
+Paweł Piotr Przeradowski
 Paul deGrandis
 Ilya Osadchiy
+Tobias Oberstein
 Adrian Kuhn
 Boris Feigin
+Stefano Rivera
 tav
+Taavi Burns
 Georg Brandl
 Bert Freudenberg
 Stian Andreassen
-Stefano Rivera
+Laurence Tratt
 Wanja Saatkamp
+Ivan Sichmann Freitas
 Gerald Klix
 Mike Blume
-Taavi Burns
 Oscar Nierstrasz
+Stefan H. Muller
+Jeremy Thurgood
+Gregor Wegberg
+Rami Chowdhury
+Tobias Pape
+Edd Barrett
 David Malcolm
 Eugene Oden
 Henry Mason
@@ -135,18 +147,16 @@
 Dusty Phillips
 Lukas Renggli
 Guenter Jantzen
-Tobias Oberstein
-Remi Meier
 Ned Batchelder
 Amit Regmi
 Ben Young
 Nicolas Chauvat
 Andrew Durdin
+Andrew Chambers
 Michael Schneider
 Nicholas Riley
 Jason Chu
 Igor Trindade Oliveira
-Jeremy Thurgood
 Rocco Moretti
 Gintautas Miliauskas
 Michael Twomey
@@ -159,18 +169,19 @@
 Karl Bartel
 Brian Dorsey
 Victor Stinner
+Andrews Medina
 Stuart Williams
 Jasper Schulz
+Christian Hudon
 Toby Watson
 Antoine Pitrou
 Aaron Iles
 Michael Cheng
 Justas Sadzevicius
+Mikael Schönenberg
 Gasper Zejn
 Neil Shepperd
-Mikael Schönenberg
 Elmo Mäntynen
-Tobias Pape
 Jonathan David Riehl
 Stanislaw Halik
 Anders Qvist
@@ -182,19 +193,18 @@
 Alexander Sedov
 Corbin Simpson
 Christopher Pope
-Laurence Tratt
-Guillebert Romain
+wenzhuman
 Christian Tismer 
+Marc Abramowitz
 Dan Stromberg
 Stefano Parmesan
-Christian Hudon
 Alexis Daboville
 Jens-Uwe Mager
 Carl Meyer
 Karl Ramm
 Pieter Zieschang
 Gabriel
-Paweł Piotr Przeradowski
+Lukas Vacek
 Andrew Dalke
 Sylvain Thenault
 Nathan Taylor
@@ -203,8 +213,11 @@
 Alejandro J. Cura
 Jacob Oscarson
 Travis Francis Athougies
+Ryan Gonzalez
 Kristjan Valur Jonsson
+Sebastian Pawluś
 Neil Blakey-Milner
+anatoly techtonik
 Lutz Paelike
 Lucio Torre
 Lars Wassermann
@@ -218,13 +231,14 @@
 Martin Blais
 Lene Wagner
 Tomo Cocoa
-Andrews Medina
 roberto@goyle
+Yury V. Zaytsev
+Anna Katrina Dominguez
 William Leslie
 Bobby Impollonia
 t...@eis

[pypy-commit] pypy reflex-support: coding convention fix

2013-12-18 Thread wlav
Author: Wim Lavrijsen 
Branch: reflex-support
Changeset: r68471:a53125f2cdc0
Date: 2013-10-17 12:28 -0700
http://bitbucket.org/pypy/pypy/changeset/a53125f2cdc0/

Log:coding convention fix

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
@@ -89,11 +89,11 @@
 cppyy_index_t cppyy_get_global_operator(
 cppyy_scope_t scope, cppyy_scope_t lc, cppyy_scope_t rc, const char* 
op);
 
-/* method properties - 
 */
+/* method properties 
-- */
 int cppyy_is_constructor(cppyy_type_t type, cppyy_index_t idx);
 int cppyy_is_staticmethod(cppyy_type_t type, cppyy_index_t idx);
 
-/* data member reflection information  
 */
+/* data member reflection information 
- */
 int cppyy_num_datamembers(cppyy_scope_t scope);
 char* cppyy_datamember_name(cppyy_scope_t scope, int datamember_index);
 char* cppyy_datamember_type(cppyy_scope_t scope, int datamember_index);
@@ -101,7 +101,7 @@
 
 int cppyy_datamember_index(cppyy_scope_t scope, const char* name);
 
-/* data member properties  
 */
+/* data member properties 
- */
 int cppyy_is_publicdata(cppyy_type_t type, int datamember_index);
 int cppyy_is_staticdata(cppyy_type_t type, int datamember_index);
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reflex-support: revert back to default choice of capi

2013-12-18 Thread wlav
Author: Wim Lavrijsen 
Branch: reflex-support
Changeset: r68474:2a1f5512b630
Date: 2013-12-18 14:18 -0800
http://bitbucket.org/pypy/pypy/changeset/2a1f5512b630/

Log:revert back to default choice of capi

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
@@ -9,8 +9,8 @@
 # the selection of the desired backend (default is Reflex).
 
 # choose C-API access method:
-#from pypy.module.cppyy.capi.loadable_capi import *
-from pypy.module.cppyy.capi.builtin_capi import *
+from pypy.module.cppyy.capi.loadable_capi import *
+#from pypy.module.cppyy.capi.builtin_capi import *
 
 from pypy.module.cppyy.capi.capi_types import C_OBJECT,\
 C_NULL_TYPE, C_NULL_OBJECT
diff --git a/pypy/module/cppyy/capi/builtin_capi.py 
b/pypy/module/cppyy/capi/builtin_capi.py
--- a/pypy/module/cppyy/capi/builtin_capi.py
+++ b/pypy/module/cppyy/capi/builtin_capi.py
@@ -1,8 +1,8 @@
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib import jit
 
-#import reflex_capi as backend
-import cint_capi as backend
+import reflex_capi as backend
+#import cint_capi as backend
 
 from pypy.module.cppyy.capi.capi_types import C_SCOPE, C_TYPE, C_OBJECT,\
C_METHOD, C_INDEX, C_INDEX_ARRAY, WLAVC_INDEX,\
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reflex-support: fix callback declaration

2013-12-18 Thread wlav
Author: Wim Lavrijsen 
Branch: reflex-support
Changeset: r68473:0744e9384dae
Date: 2013-12-18 14:07 -0800
http://bitbucket.org/pypy/pypy/changeset/0744e9384dae/

Log:fix callback declaration

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
@@ -8,6 +8,7 @@
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib import libffi, rdynload
+from rpython.tool.udir import udir
 
 from pypy.module.cppyy.capi.capi_types import C_OBJECT
 
@@ -22,13 +23,13 @@
 import commands
 (stat, incdir) = commands.getstatusoutput("root-config --incdir")
 if stat != 0:
-rootincpath = [os.path.join(os.environ["ROOTSYS"], "include")]
+rootincpath = [os.path.join(os.environ["ROOTSYS"], "include"), 
py.path.local(udir)]
 rootlibpath = [os.path.join(os.environ["ROOTSYS"], "lib64"), 
os.path.join(os.environ["ROOTSYS"], "lib")]
 else:
-rootincpath = [incdir]
+rootincpath = [incdir, py.path.local(udir)]
 rootlibpath = commands.getoutput("root-config --libdir").split()
 else:
-rootincpath = []
+rootincpath = [py.path.local(udir)]
 rootlibpath = []
 
 def identify():
@@ -422,7 +423,7 @@
 from pypy.module.cpyext.api import cpython_api, CANNOT_FAIL
 
 @cpython_api([rffi.VOIDP], lltype.Void, error=CANNOT_FAIL)
-def cppyy_recursive_remove(space, cppobject):
+def _Py_cppyy_recursive_remove(space, cppobject):
 from pypy.module.cppyy.interp_cppyy import memory_regulator
 from pypy.module.cppyy.capi import C_OBJECT, C_NULL_OBJECT
 
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
@@ -37,6 +37,9 @@
 #include 
 #include 
 
+// for recursive_remove callback
+#include "pypy_macros.h"
+
 
 /* ROOT/CINT internals --- */
 extern long G__store_struct_offset;
@@ -61,12 +64,12 @@
 };
 
 // memory regulation (cppyy_recursive_remove is generated as a cpyext capi 
call)
-extern "C" void cppyy_recursive_remove(void*);
+extern "C" void _Py_cppyy_recursive_remove(void*);
 
 class Cppyy_MemoryRegulator : public TObject {
 public:
 virtual void RecursiveRemove(TObject* object) {
-cppyy_recursive_remove((void*)object);
+_Py_cppyy_recursive_remove((void*)object);
 }
 };
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reflex-support: support access to void* data members and add cppyy.gbl.nullptr (and associated tests)

2014-01-22 Thread wlav
Author: Wim Lavrijsen 
Branch: reflex-support
Changeset: r68861:1edf9b7c3bdb
Date: 2014-01-22 18:39 -0800
http://bitbucket.org/pypy/pypy/changeset/1edf9b7c3bdb/

Log:support access to void* data members and add cppyy.gbl.nullptr (and
associated tests)

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
@@ -15,6 +15,7 @@
 '_set_function_generator': 'interp_cppyy.set_function_generator',
 '_register_class': 'interp_cppyy.register_class',
 '_is_static' : 'interp_cppyy.is_static',
+'_get_nullptr'   : 'interp_cppyy.get_nullptr',
 'CPPInstance': 'interp_cppyy.W_CPPInstance',
 'addressof'  : 'interp_cppyy.addressof',
 'bind_object': 'interp_cppyy.bind_object',
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
@@ -7,7 +7,7 @@
 from rpython.rlib import jit_libffi, rfloat
 
 from pypy.module._rawffi.interp_rawffi import unpack_simple_shape
-from pypy.module._rawffi.array import W_Array
+from pypy.module._rawffi.array import W_Array, W_ArrayInstance
 
 from pypy.module.cppyy import helper, capi, ffitypes
 
@@ -48,20 +48,33 @@
 return capi.C_NULL_OBJECT
 
 def is_nullpointer_specialcase(space, w_obj):
-# special case: allow integer 0 as (void*)0
+# 0, None, and nullptr may serve as "NULL", check for any of them
+
+# integer 0
 try:
 return space.int_w(w_obj) == 0
 except Exception:
 pass
-# special case: allow None as (void*)0
-return space.is_true(space.is_(w_obj, space.w_None))
+# None or nullptr
+from pypy.module.cppyy import interp_cppyy
+return space.is_true(space.is_(w_obj, space.w_None)) or \
+space.is_true(space.is_(w_obj, interp_cppyy.get_nullptr(space)))
 
 def get_rawbuffer(space, w_obj):
+# raw buffer
 try:
 buf = space.buffer_w(w_obj)
 return rffi.cast(rffi.VOIDP, buf.get_raw_address())
 except Exception:
 pass
+# array type
+try:
+arr = space.interp_w(W_ArrayInstance, w_obj, can_be_None=True)
+if arr:
+return rffi.cast(rffi.VOIDP, space.uint_w(arr.getbuffer(space)))
+except Exception:
+pass
+# pre-defined NULL
 if is_nullpointer_specialcase(space, w_obj):
 return rffi.cast(rffi.VOIDP, 0)
 raise TypeError("not an addressable buffer")
@@ -140,8 +153,6 @@
 self.size = array_size
 
 def from_memory(self, space, w_obj, w_pycppclass, offset):
-if hasattr(space, "fake"):
-raise NotImplementedError
 # read access, so no copy needed
 address_value = self._get_raw_address(space, w_obj, offset)
 address = rffi.cast(rffi.ULONG, address_value)
@@ -390,6 +401,24 @@
 x = rffi.cast(rffi.VOIDPP, address)
 x[0] = self._unwrap_object(space, w_obj)
 
+def from_memory(self, space, w_obj, w_pycppclass, offset):
+# returned as a long value for the address (INTPTR_T is not proper
+# per se, but rffi does not come with a PTRDIFF_T)
+address = self._get_raw_address(space, w_obj, offset)
+ptrval = rffi.cast(rffi.ULONG, rffi.cast(rffi.VOIDPP, address)[0])
+if ptrval == 0:
+from pypy.module.cppyy import interp_cppyy
+return interp_cppyy.get_nullptr(space)
+arr = space.interp_w(W_Array, unpack_simple_shape(space, 
space.wrap('P')))
+return arr.fromaddress(space, ptrval, sys.maxint)
+
+def to_memory(self, space, w_obj, w_value, offset):
+address = rffi.cast(rffi.VOIDPP, self._get_raw_address(space, w_obj, 
offset))
+if is_nullpointer_specialcase(space, w_value):
+address[0] = rffi.cast(rffi.VOIDP, 0)
+else:
+address[0] = rffi.cast(rffi.VOIDP, self._unwrap_object(space, 
w_value))
+
 class VoidPtrPtrConverter(TypeConverter):
 _immutable_fields_ = ['uses_local']
 
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -53,17 +53,12 @@
 if hasattr(space, "fake"):
 raise NotImplementedError
 lresult = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
-address = rffi.cast(rffi.ULONG, lresult)
+ptrval = rffi.cast(rffi.ULONG, lresult)
 arr = space.interp_w(W_Array, unpack_simple_shape(space, 
space.wrap(self.typecode)))
-if address == 0:
-# TODO: fix this hack; fromaddress() will allocate memory if 
address
-# is null and there seems to be no way around it (ll_buffer can not
-# be touched directly)
-nullarr = arr.fromaddress(space, address, 0)
-assert isinstance(nullarr, W_ArrayInstance)
-nullarr.free(space)

[pypy-commit] pypy reflex-support: allow bind_object() to cast

2014-01-22 Thread wlav
Author: Wim Lavrijsen 
Branch: reflex-support
Changeset: r68862:8e2e375941a4
Date: 2014-01-22 19:11 -0800
http://bitbucket.org/pypy/pypy/changeset/8e2e375941a4/

Log:allow bind_object() to cast

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
@@ -1217,8 +1217,8 @@
 address = _addressof(space, w_obj)
 return space.wrap(address)
 
-@unwrap_spec(owns=bool)
-def bind_object(space, w_obj, w_pycppclass, owns=False):
+@unwrap_spec(owns=bool, cast=bool)
+def bind_object(space, w_obj, w_pycppclass, owns=False, cast=False):
 """Takes an address and a bound C++ class proxy, returns a bound 
instance."""
 try:
 # attempt address from array or C++ instance
@@ -1233,4 +1233,4 @@
 raise OperationError(space.w_TypeError,
 space.wrap("no such class: %s" % space.str_w(w_pycppclass)))
 cppclass = space.interp_w(W_CPPClass, w_cppclass, can_be_None=False)
-return wrap_cppobject(space, rawobject, cppclass, do_cast=False, 
python_owns=owns)
+return wrap_cppobject(space, rawobject, cppclass, do_cast=cast, 
python_owns=owns)
diff --git a/pypy/module/cppyy/test/advancedcpp.h 
b/pypy/module/cppyy/test/advancedcpp.h
--- a/pypy/module/cppyy/test/advancedcpp.h
+++ b/pypy/module/cppyy/test/advancedcpp.h
@@ -35,6 +35,8 @@
 virtual base_class* cycle(base_class* b) { return b; }
 virtual base_class* clone() { return new base_class; }
 
+virtual void* mask(void* p) { return p; }
+
 public:
 int m_b;
 double m_db;
diff --git a/pypy/module/cppyy/test/test_advancedcpp.py 
b/pypy/module/cppyy/test/test_advancedcpp.py
--- a/pypy/module/cppyy/test/test_advancedcpp.py
+++ b/pypy/module/cppyy/test/test_advancedcpp.py
@@ -517,6 +517,20 @@
 assert isinstance(b.clone(), base_class)  # TODO: clone() leaks
 assert isinstance(d.clone(), derived_class)   # TODO: clone() leaks
 
+# special case when round-tripping through a void* ptr
+voidp = b.mask(d)
+assert not isinstance(voidp, base_class)
+assert not isinstance(voidp, derived_class)
+
+d1 = cppyy.bind_object(voidp, base_class, cast=True)
+assert isinstance(d1, derived_class)
+assert d1 is d
+
+b1 = cppyy.bind_object(voidp, base_class)
+assert isinstance(b1, base_class)
+assert cppyy.addressof(b1) == cppyy.addressof(d)
+assert not (b1 is d)
+
 def test13_actual_type_virtual_multi(self):
 """Test auto-downcast in adverse inheritance situation"""
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: naming consistency w/ CPython/cppyy

2018-04-20 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94400:0df7710aad8b
Date: 2017-10-30 13:14 -0700
http://bitbucket.org/pypy/pypy/changeset/0df7710aad8b/

Log:naming consistency w/ CPython/cppyy

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
@@ -13,7 +13,7 @@
 '_set_function_generator': 'interp_cppyy.set_function_generator',
 '_register_class': 'interp_cppyy.register_class',
 '_get_nullptr'   : 'interp_cppyy.get_nullptr',
-'CPPClassBase'   : 'interp_cppyy.W_CPPClass',
+'CPPInstanceBase': 'interp_cppyy.W_CPPInstance',
 'addressof'  : 'interp_cppyy.addressof',
 '_bind_object'   : 'interp_cppyy._bind_object',
 'bind_object': 'interp_cppyy.bind_object',
diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -607,7 +607,7 @@
 """Return a python string taking into account \0"""
 
 from pypy.module._cppyy import interp_cppyy
-cppstr = space.interp_w(interp_cppyy.W_CPPClass, w_self, can_be_None=False)
+cppstr = space.interp_w(interp_cppyy.W_CPPInstance, w_self, 
can_be_None=False)
 return space.newtext(c_stdstring2charp(space, cppstr._rawobject))
 
 # setup pythonizations for later use at run-time
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
@@ -22,8 +22,8 @@
 
 
 def get_rawobject(space, w_obj, can_be_None=True):
-from pypy.module._cppyy.interp_cppyy import W_CPPClass
-cppinstance = space.interp_w(W_CPPClass, w_obj, can_be_None=can_be_None)
+from pypy.module._cppyy.interp_cppyy import W_CPPInstance
+cppinstance = space.interp_w(W_CPPInstance, w_obj, can_be_None=can_be_None)
 if cppinstance:
 rawobject = cppinstance.get_rawobject()
 assert lltype.typeOf(rawobject) == capi.C_OBJECT
@@ -31,15 +31,15 @@
 return capi.C_NULL_OBJECT
 
 def set_rawobject(space, w_obj, address):
-from pypy.module._cppyy.interp_cppyy import W_CPPClass
-cppinstance = space.interp_w(W_CPPClass, w_obj, can_be_None=True)
+from pypy.module._cppyy.interp_cppyy import W_CPPInstance
+cppinstance = space.interp_w(W_CPPInstance, w_obj, can_be_None=True)
 if cppinstance:
 assert lltype.typeOf(cppinstance._rawobject) == capi.C_OBJECT
 cppinstance._rawobject = rffi.cast(capi.C_OBJECT, address)
 
 def get_rawobject_nonnull(space, w_obj):
-from pypy.module._cppyy.interp_cppyy import W_CPPClass
-cppinstance = space.interp_w(W_CPPClass, w_obj, can_be_None=True)
+from pypy.module._cppyy.interp_cppyy import W_CPPInstance
+cppinstance = space.interp_w(W_CPPInstance, w_obj, can_be_None=True)
 if cppinstance:
 cppinstance._nullcheck()
 rawobject = cppinstance.get_rawobject()
@@ -502,8 +502,8 @@
 self.clsdecl = clsdecl
 
 def _unwrap_object(self, space, w_obj):
-from pypy.module._cppyy.interp_cppyy import W_CPPClass
-if isinstance(w_obj, W_CPPClass):
+from pypy.module._cppyy.interp_cppyy import W_CPPInstance
+if isinstance(w_obj, W_CPPInstance):
 from pypy.module._cppyy.interp_cppyy import 
INSTANCE_FLAGS_IS_R_VALUE
 if w_obj.flags & INSTANCE_FLAGS_IS_R_VALUE:
 # reject moves as all are explicit
@@ -534,8 +534,8 @@
 class InstanceMoveConverter(InstanceRefConverter):
 def _unwrap_object(self, space, w_obj):
 # moving is same as by-ref, but have to check that move is allowed
-from pypy.module._cppyy.interp_cppyy import W_CPPClass, 
INSTANCE_FLAGS_IS_R_VALUE
-if isinstance(w_obj, W_CPPClass):
+from pypy.module._cppyy.interp_cppyy import W_CPPInstance, 
INSTANCE_FLAGS_IS_R_VALUE
+if isinstance(w_obj, W_CPPInstance):
 if w_obj.flags & INSTANCE_FLAGS_IS_R_VALUE:
 w_obj.flags &= ~INSTANCE_FLAGS_IS_R_VALUE
 return InstanceRefConverter._unwrap_object(self, space, w_obj)
@@ -598,8 +598,8 @@
 raise FastCallNotPossible
 
 def finalize_call(self, space, w_obj, call_local):
-from pypy.module._cppyy.interp_cppyy import W_CPPClass
-assert isinstance(w_obj, W_CPPClass)
+from pypy.module._cppyy.interp_cppyy import W_CPPInstance
+assert isinstance(w_obj, W_CPPInstance)
 r = rffi.cast(rffi.VOIDPP, call_local)
 w_obj._rawobject = rffi.cast(capi.C_OBJECT, r[0])
 
@@ -617,8 +617,8 @@
 InstanceConverter.__init__(self, space, cppclass)
 
 def _unwrap_object(self, space, w_obj):
-from pypy.module._cppyy.interp_cppyy import W_CPPClass
-if isinstance(w_obj, W_CPPClass):
+from pypy.module._cppyy.interp_cppyy impo

[pypy-commit] pypy cppyy-packaging: merge default into branch

2018-04-20 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94402:b74ad9bd1274
Date: 2018-01-26 14:27 -0800
http://bitbucket.org/pypy/pypy/changeset/b74ad9bd1274/

Log:merge default into branch

diff too long, truncating to 2000 out of 93932 lines

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -44,3 +44,10 @@
 d72f9800a42b46a8056951b1da2426d2c2d8d502 release-pypy3.5-v5.9.0
 03d614975835870da65ff0481e1edad68ebbcb8d release-pypy2.7-v5.9.0
 84a2f3e6a7f88f2fe698e473998755b3bd1a12e2 release-pypy2.7-v5.9.0
+0e7ea4fe15e82d5124e805e2e4a37cae1a402d4b release-pypy2.7-v5.10.0
+a91df6163fb76df245091f741dbf6a23ddc72374 release-pypy3.5-v5.10.0
+a91df6163fb76df245091f741dbf6a23ddc72374 release-pypy3.5-v5.10.0
+ release-pypy3.5-v5.10.0
+ release-pypy3.5-v5.10.0
+09f9160b643e3f02ccb8c843b2fbb4e5cbf54082 release-pypy3.5-v5.10.0
+3f6eaa010fce78cc7973bdc1dfdb95970f08fed2 release-pypy3.5-v5.10.1
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -30,7 +30,7 @@
 DEALINGS IN THE SOFTWARE.
 
 
-PyPy Copyright holders 2003-2017
+PyPy Copyright holders 2003-2018
 --- 
 
 Except when otherwise stated (look for LICENSE files or information at
@@ -339,8 +339,10 @@
   Stanisław Halik
   Julien Phalip
   Roman Podoliaka
+  Steve Papanik
   Eli Stevens
   Boglarka Vezer
+  gabrielg
   PavloKapyshin
   Tomer Chachamu
   Christopher Groskopf
@@ -363,11 +365,13 @@
   Konrad Delong
   Dinu Gherman
   pizi
+  Tomáš Pružina
   James Robert
   Armin Ronacher
   Diana Popa
   Mads Kiilerich
   Brett Cannon
+  Caleb Hattingh
   aliceinwire
   Zooko Wilcox-O Hearn
   James Lan
@@ -388,6 +392,7 @@
   Jason Madden
   Yaroslav Fedevych
   Even Wiik Thomassen
+  m...@funkyhat.org
   Stefan Marr
 
   Heinrich-Heine University, Germany 
diff --git a/_pytest/terminal.py b/_pytest/terminal.py
--- a/_pytest/terminal.py
+++ b/_pytest/terminal.py
@@ -366,11 +366,11 @@
 EXIT_OK, EXIT_TESTSFAILED, EXIT_INTERRUPTED, EXIT_USAGEERROR,
 EXIT_NOTESTSCOLLECTED)
 if exitstatus in summary_exit_codes:
-self.config.hook.pytest_terminal_summary(terminalreporter=self)
 self.summary_errors()
 self.summary_failures()
 self.summary_warnings()
 self.summary_passes()
+self.config.hook.pytest_terminal_summary(terminalreporter=self)
 if exitstatus == EXIT_INTERRUPTED:
 self._report_keyboardinterrupt()
 del self._keyboardinterrupt_memo
diff --git a/extra_tests/requirements.txt b/extra_tests/requirements.txt
new file mode 100644
--- /dev/null
+++ b/extra_tests/requirements.txt
@@ -0,0 +1,3 @@
+pytest
+hypothesis
+vmprof
diff --git a/extra_tests/test_bytes.py b/extra_tests/test_bytes.py
new file mode 100644
--- /dev/null
+++ b/extra_tests/test_bytes.py
@@ -0,0 +1,84 @@
+from hypothesis import strategies as st
+from hypothesis import given, example
+
+st_bytestring = st.binary() | st.binary().map(bytearray)
+
+@given(st_bytestring, st_bytestring, st_bytestring)
+def test_find(u, prefix, suffix):
+s = prefix + u + suffix
+assert 0 <= s.find(u) <= len(prefix)
+assert s.find(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+@given(st_bytestring, st_bytestring, st_bytestring)
+def test_index(u, prefix, suffix):
+s = prefix + u + suffix
+assert 0 <= s.index(u) <= len(prefix)
+assert s.index(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+@given(st_bytestring, st_bytestring, st_bytestring)
+def test_rfind(u, prefix, suffix):
+s = prefix + u + suffix
+assert s.rfind(u) >= len(prefix)
+assert s.rfind(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+@given(st_bytestring, st_bytestring, st_bytestring)
+def test_rindex(u, prefix, suffix):
+s = prefix + u + suffix
+assert s.rindex(u) >= len(prefix)
+assert s.rindex(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+def adjust_indices(u, start, end):
+if end < 0:
+end = max(end + len(u), 0)
+else:
+end = min(end, len(u))
+if start < 0:
+start = max(start + len(u), 0)
+return start, end
+
+@given(st_bytestring, st_bytestring)
+def test_startswith_basic(u, v):
+assert u.startswith(v) is (u[:len(v)] == v)
+
+@example(b'x', b'', 1)
+@example(b'x', b'', 2)
+@given(st_bytestring, st_bytestring, st.integers())
+def test_startswith_start(u, v, start):
+expected = u[start:].startswith(v) if v else (start <= len(u))
+assert u.startswith(v, start) is expected
+
+@example(b'x', b'', 1, 0)
+@example(b'xx', b'', -1, 0)
+@given(st_bytestring, st_bytestring, st.integers(), st.integers())
+def test_startswith_3(u, v, start, end):
+if v:
+expected = u[start:end].startswith(v)
+else:  # CPython leaks implementation details in this case
+start0, end0 = adjust_indices(u, start, end)
+expected = start0 <= len(u) and start0 <= end0
+   

[pypy-commit] pypy cppyy-packaging: fix C++ warnings

2018-04-20 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94401:edb9132eda33
Date: 2017-10-30 13:17 -0700
http://bitbucket.org/pypy/pypy/changeset/edb9132eda33/

Log:fix C++ warnings

diff --git a/pypy/module/_cppyy/test/advancedcpp.h 
b/pypy/module/_cppyy/test/advancedcpp.h
--- a/pypy/module/_cppyy/test/advancedcpp.h
+++ b/pypy/module/_cppyy/test/advancedcpp.h
@@ -59,7 +59,7 @@
 class a_class {// for esoteric inheritance testing
 public:
 a_class() { m_a = 1; m_da = 1.1; }
-~a_class() {}
+virtual ~a_class() {}
 virtual int get_value() = 0;
 
 public:
@@ -221,6 +221,7 @@
 //===
 class some_abstract_class {// to test abstract class handling
 public:
+virtual ~some_abstract_class() {}
 virtual void a_virtual_method() = 0;
 };
 
diff --git a/pypy/module/_cppyy/test/fragile.h 
b/pypy/module/_cppyy/test/fragile.h
--- a/pypy/module/_cppyy/test/fragile.h
+++ b/pypy/module/_cppyy/test/fragile.h
@@ -30,6 +30,7 @@
 void overload(int, no_such_class* p = 0) {}
 };
 
+
 static const int dummy_location = 0xdead;
 
 class E {
@@ -105,6 +106,7 @@
 
 class M {
 public:
+virtual ~M() {}
 enum E1 { kOnce=42 };
 enum E2 { kTwice=12 };
 };
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: upgrade to backend 0.6.0

2018-04-20 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94404:e98cf77f5b72
Date: 2018-04-20 16:00 -0700
http://bitbucket.org/pypy/pypy/changeset/e98cf77f5b72/

Log:upgrade to backend 0.6.0

diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -121,11 +121,11 @@
 
 # TODO: the following need to match up with the globally defined C_XYZ 
low-level
 # types (see capi/__init__.py), but by using strings here, that isn't 
guaranteed
-c_opaque_ptr = state.c_ulong
+c_opaque_ptr = state.c_ulong# not ptrdiff_t (which is signed)
  
 c_scope   = c_opaque_ptr
 c_type= c_scope
-c_object  = c_opaque_ptr
+c_object  = c_opaque_ptr# not voidp (to stick with one handle 
type)
 c_method  = c_opaque_ptr
 c_index   = state.c_long
 c_index_array = state.c_voidp
@@ -150,16 +150,17 @@
 
 self.capi_call_ifaces = {
 # name to opaque C++ scope representation
-'num_scopes'   : ([c_scope],  c_int),
-'scope_name'   : ([c_scope, c_int],   
c_ccharp),
-
 'resolve_name' : ([c_ccharp], 
c_ccharp),
+'resolve_enum' : ([c_ccharp], 
c_ccharp),
 'get_scope': ([c_ccharp], c_scope),
 'actual_class' : ([c_type, c_object], c_type),
+'size_of_klass': ([c_type],   
c_size_t),
+'size_of_type' : ([c_ccharp], 
c_size_t),
 
 # memory management
 'allocate' : ([c_type],   
c_object),
 'deallocate'   : ([c_type, c_object], c_void),
+'construct': ([c_type],   
c_object),
 'destruct' : ([c_type, c_object], c_void),
 
 # method/function dispatching
@@ -182,7 +183,8 @@
 'constructor'  : ([c_method, c_object, c_int, c_voidp],   
c_object),
 'call_o'   : ([c_method, c_object, c_int, c_voidp, c_type],
 c_object),
 
-'get_function_address' : ([c_scope, c_index], 
c_voidp), # TODO: verify
+'function_address_from_index'  : ([c_scope, c_index], 
c_voidp), # TODO: verify
+'function_address_from_method' : ([c_method], 
c_voidp), # id.
 
 # handling of function argument buffer
 'allocate_function_args'   : ([c_int],c_voidp),
@@ -196,6 +198,8 @@
 'is_abstract'  : ([c_type],   c_int),
 'is_enum'  : ([c_ccharp], c_int),
 
+'get_all_cpp_names': ([c_scope, c_voidp], 
c_voidp), # const char**
+
 # type/class reflection information
 'final_name'   : ([c_type],   
c_ccharp),
 'scoped_final_name': ([c_type],   
c_ccharp),
@@ -208,10 +212,10 @@
 
 # method/function reflection information
 'num_methods'  : ([c_scope],  c_int),
-'method_index_at'  : ([c_scope, c_int],   c_index),
 'method_indices_from_name' : ([c_scope, c_ccharp],
c_index_array),
 
 'method_name'  : ([c_scope, c_index], 
c_ccharp),
+'method_mangled_name'  : ([c_scope, c_index], 
c_ccharp),
 'method_result_type'   : ([c_scope, c_index], 
c_ccharp),
 'method_num_args'  : ([c_scope, c_index], c_int),
 'method_req_args'  : ([c_scope, c_index], c_int),
@@ -219,7 +223,9 @@
 'method_arg_default'   : ([c_scope, c_index, c_int],  
c_ccharp),
 'method_signature' : ([c_scope, c_index, c_int],  
c_ccharp),
 'method_prototype' : ([c_scope, c_index, c_int],  
c_ccharp),
+'is_const_method'  : ([c_method], c_int),
 
+'exists_method_template'   : ([c_scope, c_ccharp],c_int),
 'method_is_template'   : ([c_scope, c_index], c_int),
 'method_num_template_args' : ([c_scope, c_index], c_int),
 'method_template_arg_name' : ([c_scope, c_index, c_index], 
 c_ccharp),
@@ -228,7 +234,9 @@
 'get_global_operator'  : ([c_scope, c_scope, c_scope, 
c_ccharp],   c_index),
 
 # method properties
+'is_public_method' : ([c_type, c_index],  c_int),
 'is_constructor'   : ([c_ty

[pypy-commit] pypy cppyy-packaging: translator fix

2018-04-20 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94405:55cdebafb2de
Date: 2018-04-20 17:15 -0700
http://bitbucket.org/pypy/pypy/changeset/55cdebafb2de/

Log:translator fix

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
@@ -848,7 +848,7 @@
 alldir = capi.c_get_all_cpp_names(self.space, self)
 w_alldir = self.space.newlist([])
 for name in alldir:
-w_alldir.append(self.space.wrap(name))
+w_alldir.append(self.space.newtext(name))
 return w_alldir
 
 def missing_attribute_error(self, name):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: merge default into branch

2018-04-20 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94403:60b72b97202f
Date: 2018-04-19 10:47 -0700
http://bitbucket.org/pypy/pypy/changeset/60b72b97202f/

Log:merge default into branch

diff too long, truncating to 2000 out of 19728 lines

diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -6,36 +6,36 @@
 Except when otherwise stated (look for LICENSE files in directories or
 information at the beginning of each file) all software and documentation in
 the 'rpython', 'pypy', 'ctype_configure', 'dotviewer', 'demo', 'lib_pypy',
-'py', and '_pytest' directories is licensed as follows: 
+'py', and '_pytest' directories is licensed as follows:
 
 The MIT License
 
-Permission is hereby granted, free of charge, to any person 
-obtaining a copy of this software and associated documentation 
-files (the "Software"), to deal in the Software without 
-restriction, including without limitation the rights to use, 
-copy, modify, merge, publish, distribute, sublicense, and/or 
-sell copies of the Software, and to permit persons to whom the 
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following conditions:
 
-The above copyright notice and this permission notice shall be included 
+The above copyright notice and this permission notice shall be included
 in all copies or substantial portions of the Software.
 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY, 
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 DEALINGS IN THE SOFTWARE.
 
 
 PyPy Copyright holders 2003-2018
 
+
 
 Except when otherwise stated (look for LICENSE files or information at
 the beginning of each file) the files in the 'pypy' directory are each
-copyrighted by one or more of the following people and organizations:
+copyrighted by one or more of the following people and organizations:
 
   Armin Rigo
   Maciej Fijalkowski
@@ -89,13 +89,13 @@
   Niko Matsakis
   Alexander Hesse
   Ludovic Aubry
+  stian
   Jacob Hallen
   Jason Creighton
   Mark Young
   Alex Martelli
   Spenser Bauman
   Michal Bendowski
-  stian
   Jan de Mooij
   Tyler Wade
   Vincent Legoll
@@ -123,10 +123,10 @@
   Wenzhu Man
   Konstantin Lopuhin
   John Witulski
+  Jeremy Thurgood
   Greg Price
   Ivan Sichmann Freitas
   Dario Bertini
-  Jeremy Thurgood
   Mark Pearse
   Simon Cross
   Tobias Pape
@@ -145,18 +145,19 @@
   Adrian Kuhn
   tav
   Georg Brandl
+  Joannah Nanjekye
   Bert Freudenberg
   Stian Andreassen
   Wanja Saatkamp
   Mike Blume
-  Joannah Nanjekye
   Gerald Klix
   Oscar Nierstrasz
   Rami Chowdhury
   Stefan H. Muller
+  Dodan Mihai
   Tim Felgentreff
   Eugene Oden
-  Dodan Mihai
+  Colin Valliant
   Jeff Terrace
   Henry Mason
   Vasily Kuznetsov
@@ -225,12 +226,14 @@
   Vaibhav Sood
   Reuben Cummings
   Attila Gobi
+  Floris Bruynooghe
   Christopher Pope
   Tristan Arthur
   Christian Tismer 
   Dan Stromberg
   Carl Meyer
   Florin Papa
+  Arianna Avanzini
   Jens-Uwe Mager
   Valentina Mukhamedzhanova
   Stefano Parmesan
@@ -250,9 +253,11 @@
   Alejandro J. Cura
   Vladimir Kryachko
   Gabriel
+  Thomas Hisch
   Mark Williams
   Kunal Grover
   Nathan Taylor
+  Barry Hart
   Travis Francis Athougies
   Yasir Suhail
   Sergey Kishchenko
@@ -260,6 +265,7 @@
   Lutz Paelike
   Ian Foote
   Philipp Rustemeuer
+  Logan Chien
   Catalin Gabriel Manciu
   Jacob Oscarson
   Ryan Gonzalez
@@ -295,7 +301,6 @@
   Akira Li
   Gustavo Niemeyer
   Rafał Gałczyński
-  Logan Chien
   Lucas Stadler
   roberto@goyle
   Matt Bogosian
@@ -308,6 +313,7 @@
   Anna Katrina Dominguez
   Kim Jin Su
   Amber Brown
+  Miro Hrončok
   Anthony Sottile
   Nate Bragg
   Ben Darnell
@@ -315,7 +321,6 @@
   Godefroid Chappelle
   

[pypy-commit] pypy cppyy-packaging: initial support for exception handling from wrapped functions

2018-04-23 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94431:dd967ce1da92
Date: 2018-04-23 15:52 -0700
http://bitbucket.org/pypy/pypy/changeset/dd967ce1da92/

Log:initial support for exception handling from wrapped functions

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
@@ -16,6 +16,8 @@
 typedef long  cppyy_index_t;
 typedef void* cppyy_funcaddr_t;
 
+typedef unsigned long cppyy_exctype_t;
+
 /* name to opaque C++ scope representation 
 */
 RPY_EXTERN
 char* cppyy_resolve_name(const char* cppitem_name);
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
@@ -19,6 +19,9 @@
 INSTANCE_FLAGS_IS_REF  = 0x0002
 INSTANCE_FLAGS_IS_R_VALUE  = 0x0004
 
+OVERLOAD_FLAGS_USE_FFI = 0x0001
+
+
 class FastCallNotPossible(Exception):
 pass
 
@@ -186,7 +189,7 @@
 return rffi.cast(rffi.VOIDP, loc_idx)
 
 @jit.unroll_safe
-def call(self, cppthis, args_w):
+def call(self, cppthis, args_w, useffi):
 jit.promote(self)
 
 assert lltype.typeOf(cppthis) == capi.C_OBJECT
@@ -218,16 +221,25 @@
 
 try:
 # attempt to call directly through ffi chain
-if self._funcaddr:
+if useffi and self._funcaddr:
 try:
 return self.do_fast_call(cppthis, args_w, call_local)
 except FastCallNotPossible:
 pass  # can happen if converters or executor does not 
implement ffi
 
 # ffi chain must have failed; using stub functions instead
-args = self.prepare_arguments(args_w, call_local)
+args, stat = self.prepare_arguments(args_w, call_local)
 try:
-return self.executor.execute(self.space, self.cppmethod, 
cppthis, len(args_w), args)
+result = self.executor.execute(
+self.space, self.cppmethod, cppthis, len(args_w), args)
+if stat[0] != rffi.cast(rffi.ULONG, 0):
+what = rffi.cast(rffi.CCHARP, stat[1])
+pywhat = rffi.charp2str(what)
+capi.c_free(self.space, rffi.cast(rffi.VOIDP, what))
+if hasattr(self.space, "fake"):
+raise OperationError(self.space.w_Exception, 
self.space.newtext("C++ exception"))
+raise oefmt(self.space.w_Exception, pywhat)
+return result
 finally:
 self.finalize_call(args, args_w, call_local)
 finally:
@@ -373,7 +385,10 @@
 conv.free_argument(self.space, rffi.cast(capi.C_OBJECT, 
arg_j), loc_j)
 capi.c_deallocate_function_args(self.space, args)
 raise
-return args
+stat = rffi.cast(rffi.ULONGP,
+lltype.direct_ptradd(rffi.cast(rffi.CCHARP, args), 
int(len(args_w))*stride))
+stat[0] = rffi.cast(rffi.ULONG, 0)
+return args, stat
 
 @jit.unroll_safe
 def finalize_call(self, args, args_w, call_local):
@@ -435,7 +450,7 @@
 # TODO: might have to specialize for CPPTemplatedCall on 
CPPMethod/CPPFunction here
 CPPMethod.__init__(self, space, declaring_scope, method_index, 
arg_defs, args_required)
 
-def call(self, cppthis, args_w):
+def call(self, cppthis, args_w, useffi):
 assert lltype.typeOf(cppthis) == capi.C_OBJECT
 for i in range(len(args_w)):
 try:
@@ -447,10 +462,10 @@
 raise oefmt(self.space.w_TypeError,
 "non-matching template (got %s where %s expected)",
 s, self.templ_args[i])
-return W_CPPBoundMethod(cppthis, self)
+return W_CPPBoundMethod(cppthis, self, useffi)
 
-def bound_call(self, cppthis, args_w):
-return CPPMethod.call(self, cppthis, args_w)
+def bound_call(self, cppthis, args_w, useffi):
+return CPPMethod.call(self, cppthis, args_w, useffi)
 
 def __repr__(self):
 return "CPPTemplatedCall: %s" % self.prototype()
@@ -468,11 +483,11 @@
 def unpack_cppthis(space, w_cppinstance, declaring_scope):
 return rffi.cast(capi.C_OBJECT, declaring_scope.handle)
 
-def call(self, cppthis, args_w):
+def call(self, cppthis, args_w, useffi):
 # Note: this does not return a wrapped instance, just a pointer to the
 # new instance; the overload must still wrap it before returning. Also,
 # cppthis is declaring_scope.handle (as per unpack_cppthis(), above).
-return CPPMethod.call(self, cppthis, args_w)
+return CPPMethod.call(self, cppthis, args_w, useffi)
 
 def __repr__(self):
 return "CPPConstructor: %s" % self.prototype()
@@ -485,7 +5

[pypy-commit] pypy cppyy-packaging: update enum handling

2018-04-23 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94433:3f9d98258560
Date: 2018-04-23 19:46 -0700
http://bitbucket.org/pypy/pypy/changeset/3f9d98258560/

Log:update enum handling

diff --git a/pypy/module/_cppyy/src/dummy_backend.cxx 
b/pypy/module/_cppyy/src/dummy_backend.cxx
--- a/pypy/module/_cppyy/src/dummy_backend.cxx
+++ b/pypy/module/_cppyy/src/dummy_backend.cxx
@@ -408,6 +408,8 @@
 
 /* name to opaque C++ scope representation  */
 char* cppyy_resolve_name(const char* cppitem_name) {
+if (cppyy_is_enum(cppitem_name))
+return cppstring_to_cstring("internal_enum_type_t");
 return cppstring_to_cstring(cppitem_name);
 }
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: fix translation

2018-04-23 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94434:43f7036815b1
Date: 2018-04-23 19:46 -0700
http://bitbucket.org/pypy/pypy/changeset/43f7036815b1/

Log:fix translation

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
@@ -236,9 +236,7 @@
 what = rffi.cast(rffi.CCHARP, stat[1])
 pywhat = rffi.charp2str(what)
 capi.c_free(self.space, rffi.cast(rffi.VOIDP, what))
-if hasattr(self.space, "fake"):
-raise OperationError(self.space.w_Exception, 
self.space.newtext("C++ exception"))
-raise oefmt(self.space.w_Exception, pywhat)
+raise OperationError(self.space.w_Exception, 
self.space.newtext(pywhat))
 return result
 finally:
 self.finalize_call(args, args_w, call_local)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: merge default into branch

2018-04-23 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94432:4f2df82b0b9f
Date: 2018-04-23 15:52 -0700
http://bitbucket.org/pypy/pypy/changeset/4f2df82b0b9f/

Log:merge default into branch

diff --git a/pypy/doc/release-v6.0.0.rst b/pypy/doc/release-v6.0.0.rst
--- a/pypy/doc/release-v6.0.0.rst
+++ b/pypy/doc/release-v6.0.0.rst
@@ -18,6 +18,8 @@
 getting started writing code. We have improved our parser to emit more friendly
 `syntax errors`_,  making PyPy not only faster but more friendly.
 
+The GC now has `hooks`_ to gain more insights into its performance
+
 The Windows PyPy3.5 release is still considered beta-quality. There are open
 issues with unicode handling especially around system calls and c-extensions.
 
@@ -53,6 +55,7 @@
 .. _`blog post`: 
https://morepypy.blogspot.it/2017/10/cape-of-good-hope-for-pypy-hello-from.html
 .. _pygobject: https://lazka.github.io/posts/2018-04_pypy-pygobject/index.html
 .. _`syntax errors`: 
https://morepypy.blogspot.com/2018/04/improving-syntaxerror-in-pypy.html
+.. _`hooks`: gc_info.html#gc-hooks
 
 What is PyPy?
 =
@@ -101,8 +104,9 @@
 * Added missing attributes to C-API ``instancemethod`` on pypy3
 * Store error state in thread-local storage for C-API.
 * Fix JIT bugs exposed in the sre module
-* Improve speed of Python parser, improve ParseError messages slightly
+* Improve speed of Python parser, improve ParseError messages and SyntaxError
 * Handle JIT hooks more efficiently
+* Fix a rare GC bug exposed by intensive use of cpyext `Buffer` s
 
 We also refactored many parts of the JIT bridge optimizations, as well as 
cpyext
 internals, and together with new contributors fixed issues, added new
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -3,18 +3,7 @@
 ==
 
 .. this is a revision shortly after release-pypy-6.0.0
-.. startrev: f22145c34985
+.. startrev: ad79cc0ce9a8
 
 
-.. branch: issue2752
 
-Fix a rare GC bug that was introduced more than one year ago, but was
-not diagnosed before issue #2752.
-
-.. branch: gc-hooks
-
-Introduce GC hooks, as documented in doc/gc_info.rst
-
-.. branch: gc-hook-better-timestamp
-
-Improve GC hooks
diff --git a/pypy/doc/whatsnew-pypy2-6.0.0.rst 
b/pypy/doc/whatsnew-pypy2-6.0.0.rst
--- a/pypy/doc/whatsnew-pypy2-6.0.0.rst
+++ b/pypy/doc/whatsnew-pypy2-6.0.0.rst
@@ -109,3 +109,16 @@
 
 Improve line offsets that are reported by SyntaxError. Improve error messages
 for a few situations, including mismatched parenthesis.
+
+.. branch: issue2752
+
+Fix a rare GC bug that was introduced more than one year ago, but was
+not diagnosed before issue #2752.
+
+.. branch: gc-hooks
+
+Introduce GC hooks, as documented in doc/gc_info.rst
+
+.. branch: gc-hook-better-timestamp
+
+Improve GC hooksd
diff --git a/pypy/interpreter/executioncontext.py 
b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -491,11 +491,17 @@
 # 'action.fire()' happens to be called any time before
 # the corresponding perform(), the fire() has no
 # effect---which is the effect we want, because
-# perform() will be called anyway.
+# perform() will be called anyway.  All such pending
+# actions with _fired == True are still inside the old
+# chained list.  As soon as we reset _fired to False,
+# we also reset _next to None and we are ready for
+# another fire().
 while action is not None:
+next_action = action._next
+action._next = None
 action._fired = False
 action.perform(ec, frame)
-action._next, action = None, action._next
+action = next_action
 
 self.action_dispatcher = action_dispatcher
 
diff --git a/pypy/interpreter/test/test_executioncontext.py 
b/pypy/interpreter/test/test_executioncontext.py
--- a/pypy/interpreter/test/test_executioncontext.py
+++ b/pypy/interpreter/test/test_executioncontext.py
@@ -67,6 +67,47 @@
 """)
 assert events == ['one']
 
+def test_fire_inside_perform(self):
+# test what happens if we call AsyncAction.fire() while we are in the
+# middle of an AsyncAction.perform(). In particular, this happens when
+# PyObjectDeallocAction.fire() is called by rawrefcount: see issue
+# 2805
+events = []
+
+class Action1(executioncontext.AsyncAction):
+_count = 0
+
+def perform(self, ec, frame):
+events.append('one')
+if self._count == 0:
+# a1 is no longer in the queue, so it will be enqueued
+a1.fire()
+#
+# a2 is still in the queue, so the fir

[pypy-commit] pypy default: merge cppyy-packaging: move to latest backend (0.6.0) and support exceptions through wrappers

2018-04-23 Thread wlav
Author: Wim Lavrijsen 
Branch: 
Changeset: r94435:e50e11af23f1
Date: 2018-04-23 19:57 -0700
http://bitbucket.org/pypy/pypy/changeset/e50e11af23f1/

Log:merge cppyy-packaging: move to latest backend (0.6.0) and support
exceptions through wrappers

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
@@ -13,7 +13,7 @@
 '_set_function_generator': 'interp_cppyy.set_function_generator',
 '_register_class': 'interp_cppyy.register_class',
 '_get_nullptr'   : 'interp_cppyy.get_nullptr',
-'CPPClassBase'   : 'interp_cppyy.W_CPPClass',
+'CPPInstanceBase': 'interp_cppyy.W_CPPInstance',
 'addressof'  : 'interp_cppyy.addressof',
 '_bind_object'   : 'interp_cppyy._bind_object',
 'bind_object': 'interp_cppyy.bind_object',
diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -121,11 +121,11 @@
 
 # TODO: the following need to match up with the globally defined C_XYZ 
low-level
 # types (see capi/__init__.py), but by using strings here, that isn't 
guaranteed
-c_opaque_ptr = state.c_ulong
+c_opaque_ptr = state.c_ulong# not ptrdiff_t (which is signed)
  
 c_scope   = c_opaque_ptr
 c_type= c_scope
-c_object  = c_opaque_ptr
+c_object  = c_opaque_ptr# not voidp (to stick with one handle 
type)
 c_method  = c_opaque_ptr
 c_index   = state.c_long
 c_index_array = state.c_voidp
@@ -150,16 +150,17 @@
 
 self.capi_call_ifaces = {
 # name to opaque C++ scope representation
-'num_scopes'   : ([c_scope],  c_int),
-'scope_name'   : ([c_scope, c_int],   
c_ccharp),
-
 'resolve_name' : ([c_ccharp], 
c_ccharp),
+'resolve_enum' : ([c_ccharp], 
c_ccharp),
 'get_scope': ([c_ccharp], c_scope),
 'actual_class' : ([c_type, c_object], c_type),
+'size_of_klass': ([c_type],   
c_size_t),
+'size_of_type' : ([c_ccharp], 
c_size_t),
 
 # memory management
 'allocate' : ([c_type],   
c_object),
 'deallocate'   : ([c_type, c_object], c_void),
+'construct': ([c_type],   
c_object),
 'destruct' : ([c_type, c_object], c_void),
 
 # method/function dispatching
@@ -182,7 +183,8 @@
 'constructor'  : ([c_method, c_object, c_int, c_voidp],   
c_object),
 'call_o'   : ([c_method, c_object, c_int, c_voidp, c_type],
 c_object),
 
-'get_function_address' : ([c_scope, c_index], 
c_voidp), # TODO: verify
+'function_address_from_index'  : ([c_scope, c_index], 
c_voidp), # TODO: verify
+'function_address_from_method' : ([c_method], 
c_voidp), # id.
 
 # handling of function argument buffer
 'allocate_function_args'   : ([c_int],c_voidp),
@@ -196,6 +198,8 @@
 'is_abstract'  : ([c_type],   c_int),
 'is_enum'  : ([c_ccharp], c_int),
 
+'get_all_cpp_names': ([c_scope, c_voidp], 
c_voidp), # const char**
+
 # type/class reflection information
 'final_name'   : ([c_type],   
c_ccharp),
 'scoped_final_name': ([c_type],   
c_ccharp),
@@ -208,10 +212,10 @@
 
 # method/function reflection information
 'num_methods'  : ([c_scope],  c_int),
-'method_index_at'  : ([c_scope, c_int],   c_index),
 'method_indices_from_name' : ([c_scope, c_ccharp],
c_index_array),
 
 'method_name'  : ([c_scope, c_index], 
c_ccharp),
+'method_mangled_name'  : ([c_scope, c_index], 
c_ccharp),
 'method_result_type'   : ([c_scope, c_index], 
c_ccharp),
 'method_num_args'  : ([c_scope, c_index], c_int),
 'method_req_args'  : ([c_scope, c_index], c_int),
@@ -219,7 +223,9 @@
 'method_arg_default'   : ([c_scope, c_index, c_int],  
c_ccharp),
 'method_signature' : ([c_scope, c_index, c_int],  
c_ccharp),
 '

[pypy-commit] pypy cppyy-packaging: const correctness for data members and associated tests

2018-04-26 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94449:e7331182c14c
Date: 2018-04-24 13:39 -0700
http://bitbucket.org/pypy/pypy/changeset/e7331182c14c/

Log:const correctness for data members and associated tests

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
@@ -7,6 +7,7 @@
 interpleveldefs = {
 '_resolve_name'  : 'interp_cppyy.resolve_name',
 '_scope_byname'  : 'interp_cppyy.scope_byname',
+'_is_static_data': 'interp_cppyy.is_static_data',
 '_is_template'   : 'interp_cppyy.is_template',
 '_std_string_name'   : 'interp_cppyy.std_string_name',
 '_set_class_generator'   : 'interp_cppyy.set_class_generator',
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
@@ -149,6 +149,24 @@
 W_CPPLibrary.typedef.acceptable_as_base_class = True
 
 
+#-
+# Classes involved with methods and functions:
+#
+#  CPPMethod: base class wrapping a single function or method
+#  CPPConstructor:specialization for allocating a new object
+#  CPPFunction:   specialization for free and static functions
+#  CPPSetItem:specialization for Python's __setitem__
+#  CPPTemplatedCall:  trampoline to instantiate and bind templated functions
+#  W_CPPOverload, W_CPPConstructorOverload, W_CPPTemplateOverload:
+# user-facing, app-level, collection of overloads, with specializations
+# for constructors and templates
+#  W_CPPBoundMethod:  instantiated template method
+#
+# All methods/functions derive from CPPMethod and are collected as overload
+# candidates in user-facing overload classes. Templated methods are a two-step
+# process, where first the template is instantiated (or selected if already
+# available), which returns a callable object that is the actual bound method.
+
 class CPPMethod(object):
 """Dispatcher of methods. Checks the arguments, find the corresponding FFI
 function if available, makes the call, and returns the wrapped result. It
@@ -688,6 +706,18 @@
 )
 
 
+#-
+# Classes for data members:
+#
+#  W_CPPDataMember:instance data members
+#  W_CPPConstDataMember:   specialization for const data members
+#  W_CPPStaticData:class-level and global/static data
+#  W_CPPConstStaticData:   specialization for const global/static data
+#
+# Data is represented by an offset which is either a global pointer (static 
data)
+# or an offset from the start of an instance (data members). The "const"
+# specializations raise when attempting to set their value.
+
 class W_CPPDataMember(W_Root):
 _attrs_ = ['space', 'scope', 'converter', 'offset']
 _immutable_fields = ['scope', 'converter', 'offset']
@@ -698,9 +728,6 @@
 self.converter = converter.get_converter(self.space, type_name, '')
 self.offset = offset
 
-def is_static(self):
-return self.space.w_False
-
 def _get_offset(self, cppinstance):
 if cppinstance:
 assert lltype.typeOf(cppinstance.clsdecl.handle) == 
lltype.typeOf(self.scope.handle)
@@ -728,16 +755,25 @@
 
 W_CPPDataMember.typedef = TypeDef(
 'CPPDataMember',
-is_static = interp2app(W_CPPDataMember.is_static),
 __get__ = interp2app(W_CPPDataMember.get),
 __set__ = interp2app(W_CPPDataMember.set),
 )
 W_CPPDataMember.typedef.acceptable_as_base_class = False
 
+
+class W_CPPConstDataMember(W_CPPDataMember):
+def set(self, w_cppinstance, w_value):
+raise oefmt(self.space.w_TypeError, "assignment to const data not 
allowed")
+
+W_CPPConstDataMember.typedef = TypeDef(
+'CPPConstDataMember',
+__get__ = interp2app(W_CPPDataMember.get),
+__set__ = interp2app(W_CPPConstDataMember.set),
+)
+W_CPPConstDataMember.typedef.acceptable_as_base_class = False
+
+
 class W_CPPStaticData(W_CPPDataMember):
-def is_static(self):
-return self.space.w_True
-
 @jit.elidable_promote()
 def _get_offset(self, cppinstance):
 return self.offset
@@ -751,19 +787,34 @@
 
 W_CPPStaticData.typedef = TypeDef(
 'CPPStaticData',
-is_static = interp2app(W_CPPStaticData.is_static),
 __get__ = interp2app(W_CPPStaticData.get),
 __set__ = interp2app(W_CPPStaticData.set),
 )
 W_CPPStaticData.typedef.acceptable_as_base_class = False
 
-def is_static(space, w_obj):
+
+class W_CPPConstStaticData(W_CPPStaticData):
+def set(self, w_cppinstance, w_value):
+raise oefmt(self.space.w_TypeError, "assignment to const data not 
allowed")
+
+W_CPPConstStaticData.typedef = TypeDef(
+'CPPConstStaticData',
+__get__ = interp2app(W_CPPConstStaticData.get),
+__set__ = interp2app(W_CPPConstStaticData.set),
+)
+W_CPPConstStaticData.typedef.acceptable_as_base_class = False
+
+
+def is_static_data(space, w_obj):
 try:
 space.interp_w(W_C

[pypy-commit] pypy cppyy-packaging: initial support for function pointer arguments

2018-04-26 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94451:f8f27990a737
Date: 2018-04-25 16:59 -0700
http://bitbucket.org/pypy/pypy/changeset/f8f27990a737/

Log:initial support for function pointer arguments

diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -421,7 +421,7 @@
 _cdata_to_ptr(space, call_capi(space, 'function_address_from_index', 
args)))
 def c_function_address_from_method(space, cppmethod):
 return rffi.cast(C_FUNC_PTR,
-_cdata_to_ptr(space, call_capi(space, 'function_address_from_method', 
_ArgH(cppmethod
+_cdata_to_ptr(space, call_capi(space, 'function_address_from_method', 
[_ArgH(cppmethod)])))
 
 # handling of function argument buffer ---
 def c_allocate_function_args(space, size):
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
@@ -686,6 +686,32 @@
 decref(space, rffi.cast(PyObject, rffi.cast(rffi.VOIDPP, arg)[0]))
 
 
+class FunctionPointerConverter(TypeConverter):
+def __init__(self, space, signature):
+self.signature = signature
+
+def convert_argument(self, space, w_obj, address, call_local):
+# TODO: atm, does not actually get an overload, but a staticmethod
+from pypy.module._cppyy.interp_cppyy import W_CPPOverload
+cppol = space.interp_w(W_CPPOverload, w_obj)
+
+# find the function with matching signature
+for i in range(len(cppol.functions)):
+m = cppol.functions[i]
+if m.signature(False) == self.signature:
+x = rffi.cast(rffi.VOIDPP, address)
+x[0] = rffi.cast(rffi.VOIDP,
+capi.c_function_address_from_method(space, m.cppmethod))
+address = rffi.cast(capi.C_OBJECT, address)
+ba = rffi.cast(rffi.CCHARP, address)
+ba[capi.c_function_arg_typeoffset(space)] = 'p'
+return
+
+# lookup failed
+raise oefmt(space.w_TypeError,
+"no overload found matching %s", self.signature)
+
+
 class MacroConverter(TypeConverter):
 def from_memory(self, space, w_obj, w_pycppclass, offset):
 # TODO: get the actual type info from somewhere ...
@@ -752,6 +778,9 @@
 elif "(anonymous)" in name:
 # special case: enum w/o a type name
 return _converters["internal_enum_type_t"](space, default)
+elif "(*)" in name or "::*)" in name:
+# function pointer
+return FunctionPointerConverter(space, name[name.find("*)")+2:])
 
 #   5) void* or void converter (which fails on use)
 if 0 <= compound.find('*'):
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
@@ -128,7 +128,7 @@
 
 def register_class(space, w_pycppclass):
 w_cppclass = space.findattr(w_pycppclass, space.newtext("__cppdecl__"))
-cppclass = space.interp_w(W_CPPClassDecl, w_cppclass, can_be_None=False)
+cppclass = space.interp_w(W_CPPClassDecl, w_cppclass)
 # add back-end specific method pythonizations (doing this on the wrapped
 # class allows simple aliasing of methods)
 capi.pythonize(space, cppclass.name, w_pycppclass)
@@ -195,7 +195,7 @@
 
 @staticmethod
 def unpack_cppthis(space, w_cppinstance, declaring_scope):
-cppinstance = space.interp_w(W_CPPInstance, w_cppinstance, 
can_be_None=False)
+cppinstance = space.interp_w(W_CPPInstance, w_cppinstance)
 cppinstance._nullcheck()
 return cppinstance.get_cppthis(declaring_scope)
 
@@ -442,7 +442,7 @@
 
 
 class CPPFunction(CPPMethod):
-"""Global (namespaced) function dispatcher."""
+"""Global (namespaced) / static function dispatcher."""
 
 _immutable_ = True
 
@@ -807,7 +807,7 @@
 
 def is_static_data(space, w_obj):
 try:
-space.interp_w(W_CPPStaticData, w_obj, can_be_None=False)
+space.interp_w(W_CPPStaticData, w_obj)
 return space.w_True
 except Exception:
 return space.w_False
@@ -1183,7 +1183,7 @@
 # scopes of the argument classes (TODO: implement that last option)
 try:
 # TODO: expecting w_other to be an W_CPPInstance is too limiting
-other = self.space.interp_w(W_CPPInstance, w_other, 
can_be_None=False)
+other = self.space.interp_w(W_CPPInstance, w_other)
 for name in ["", "__gnu_cxx", "__1"]:
 nss = scope_byname(self.space, name)
 meth_idx = capi.c_get_global_operator(
@@ -1205,7 +1205,7 @@
 
 # fallback 2: direct pointer comparison (the class comparison is 
needed since
 # the first data member in a struct and the struct have the same 
ad

[pypy-commit] pypy cppyy-packaging: support anonymous enums

2018-04-26 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94450:682a43ef7a89
Date: 2018-04-24 14:28 -0700
http://bitbucket.org/pypy/pypy/changeset/682a43ef7a89/

Log:support anonymous enums

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
@@ -749,6 +749,9 @@
 return InstancePtrPtrConverter(space, clsdecl)
 elif compound == "":
 return InstanceConverter(space, clsdecl)
+elif "(anonymous)" in name:
+# special case: enum w/o a type name
+return _converters["internal_enum_type_t"](space, default)
 
 #   5) void* or void converter (which fails on use)
 if 0 <= compound.find('*'):
diff --git a/pypy/module/_cppyy/executor.py b/pypy/module/_cppyy/executor.py
--- a/pypy/module/_cppyy/executor.py
+++ b/pypy/module/_cppyy/executor.py
@@ -289,6 +289,9 @@
 return InstancePtrExecutor(space, cppclass)
 elif compound == '**' or compound == '*&':
 return InstancePtrPtrExecutor(space, cppclass)
+elif "(anonymous)" in name:
+# special case: enum w/o a type name
+return _executors["internal_enum_type_t"](space, None)
 
 # 4) additional special cases
 if compound == '*':
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: add extra info in dummy_backend for const_int test

2018-04-26 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94453:b762bdca4513
Date: 2018-04-26 10:16 -0700
http://bitbucket.org/pypy/pypy/changeset/b762bdca4513/

Log:add extra info in dummy_backend for const_int test

diff --git a/pypy/module/_cppyy/src/dummy_backend.cxx 
b/pypy/module/_cppyy/src/dummy_backend.cxx
--- a/pypy/module/_cppyy/src/dummy_backend.cxx
+++ b/pypy/module/_cppyy/src/dummy_backend.cxx
@@ -348,6 +348,7 @@
 PUBLIC_CPPYY_DATA3(short,   short,  h);
 PUBLIC_CPPYY_DATA3(ushort,  unsigned short, H);
 PUBLIC_CPPYY_DATA3(int, int,i);
+PUBLIC_CPPYY_DATA (const_int, const int);
 PUBLIC_CPPYY_DATA3(uint,unsigned int,   I);
 PUBLIC_CPPYY_DATA3(long,long,   l);
 PUBLIC_CPPYY_DATA3(ulong,   unsigned long,  L);
@@ -1032,7 +1033,9 @@
 return s_scopes[handle].m_datambrs[idatambr].m_isstatic;
 }
 
-int cppyy_is_const_data(cppyy_scope_t /* handle */, cppyy_index_t /* idatambr 
*/) {
+int cppyy_is_const_data(cppyy_scope_t handle, cppyy_index_t idatambr) {
+if (s_scopes[handle].m_datambrs[idatambr].m_name == "m_const_int")
+return 1;
 return 0;
 }
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: anotator fixes

2018-04-26 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94452:ae0244400329
Date: 2018-04-26 10:08 -0700
http://bitbucket.org/pypy/pypy/changeset/ae0244400329/

Log:anotator fixes

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
@@ -687,6 +687,8 @@
 
 
 class FunctionPointerConverter(TypeConverter):
+_immutable_fields_ = ['signature']
+
 def __init__(self, space, signature):
 self.signature = signature
 
@@ -780,7 +782,9 @@
 return _converters["internal_enum_type_t"](space, default)
 elif "(*)" in name or "::*)" in name:
 # function pointer
-return FunctionPointerConverter(space, name[name.find("*)")+2:])
+pos = name.find("*)")
+if pos > 0:
+return FunctionPointerConverter(space, name[pos+2:])
 
 #   5) void* or void converter (which fails on use)
 if 0 <= compound.find('*'):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: merge default into branch

2018-05-07 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94497:0eee6ab380c7
Date: 2018-05-07 13:34 -0700
http://bitbucket.org/pypy/pypy/changeset/0eee6ab380c7/

Log:merge default into branch

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -51,3 +51,5 @@
  release-pypy3.5-v5.10.0
 09f9160b643e3f02ccb8c843b2fbb4e5cbf54082 release-pypy3.5-v5.10.0
 3f6eaa010fce78cc7973bdc1dfdb95970f08fed2 release-pypy3.5-v5.10.1
+ab0b9caf307db6592905a80b8faffd69b39005b8 release-pypy2.7-v6.0.0
+fdd60ed87e941677e8ea11acf9f1819466521bf2 release-pypy3.5-v6.0.0
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -247,6 +247,7 @@
   Lukas Vacek
   Omer Katz
   Jacek Generowicz
+  Tomasz Dziopa
   Sylvain Thenault
   Jakub Stasiak
   Andrew Dalke
@@ -307,6 +308,7 @@
   Yury V. Zaytsev
   florinpapa
   Anders Sigfridsson
+  Matt Jackson
   Nikolay Zinov
   rafalgalczyn...@gmail.com
   Joshua Gilbert
diff --git a/dotviewer/font/NOTICE b/dotviewer/font/COPYING.txt
rename from dotviewer/font/NOTICE
rename to dotviewer/font/COPYING.txt
diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -82,8 +82,11 @@
 def _CData_output(self, resarray, base=None, index=-1):
 from _rawffi.alt import types
 # If a char_p or unichar_p is received, skip the string interpretation
-if base._ffiargtype != types.Pointer(types.char_p) and \
-   base._ffiargtype != types.Pointer(types.unichar_p):
+try:
+deref = type(base)._deref_ffiargtype()
+except AttributeError:
+deref = None
+if deref != types.char_p and deref != types.unichar_p:
 # this seems to be a string if we're array of char, surprise!
 from ctypes import c_char, c_wchar
 if self._type_ is c_char:
@@ -120,6 +123,12 @@
 value = self(*value)
 return _CDataMeta.from_param(self, value)
 
+def _build_ffiargtype(self):
+return _ffi.types.Pointer(self._type_.get_ffi_argtype())
+
+def _deref_ffiargtype(self):
+return self._type_.get_ffi_argtype()
+
 def array_get_slice_params(self, index):
 if hasattr(self, '_length_'):
 start, stop, step = index.indices(self._length_)
@@ -248,6 +257,5 @@
 _type_ = base
 )
 cls = ArrayMeta(name, (Array,), tpdict)
-cls._ffiargtype = _ffi.types.Pointer(base.get_ffi_argtype())
 ARRAY_CACHE[key] = cls
 return cls
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -49,10 +49,13 @@
 else:
 return self.from_param(as_parameter)
 
+def _build_ffiargtype(self):
+return _shape_to_ffi_type(self._ffiargshape_)
+
 def get_ffi_argtype(self):
 if self._ffiargtype:
 return self._ffiargtype
-self._ffiargtype = _shape_to_ffi_type(self._ffiargshape_)
+self._ffiargtype = self._build_ffiargtype()
 return self._ffiargtype
 
 def _CData_output(self, resbuffer, base=None, index=-1):
diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -70,7 +70,12 @@
 self._ffiarray = ffiarray
 self.__init__ = __init__
 self._type_ = TP
-self._ffiargtype = _ffi.types.Pointer(TP.get_ffi_argtype())
+
+def _build_ffiargtype(self):
+return _ffi.types.Pointer(self._type_.get_ffi_argtype())
+
+def _deref_ffiargtype(self):
+return self._type_.get_ffi_argtype()
 
 from_address = cdata_from_address
 
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -160,6 +160,10 @@
 raise AttributeError("_fields_ is final")
 if self in [f[1] for f in value]:
 raise AttributeError("Structure or union cannot contain itself")
+if self._ffiargtype is not None:
+raise NotImplementedError("Too late to set _fields_: we already "
+"said to libffi that the structure type %s is opaque"
+% (self,))
 names_and_fields(
 self,
 value, self.__bases__[0],
diff --git a/pypy/doc/contributor.rst b/pypy/doc/contributor.rst
--- a/pypy/doc/contributor.rst
+++ b/pypy/doc/contributor.rst
@@ -214,6 +214,7 @@
   Lukas Vacek
   Omer Katz
   Jacek Generowicz
+  Tomasz Dziopa
   Sylvain Thenault
   Jakub Stasiak
   Andrew Dalke
@@ -274,6 +275,7 @@
   Yury V. Zaytsev
   florinpapa
   Anders Sigfridsson
+  Matt Jackson
   Nikolay Zinov
   rafalgalczyn...@gmail.com
   Joshua Gilbert
diff --git a/pypy/doc/gc_info.rst b/pypy/doc/gc_info.rst
--- a/pypy/doc/gc_info.rst
+++ b/pypy/doc/gc_info.rst
@@ -152,7 +152,7 @@
 to wait until it reaches a point in which th

[pypy-commit] pypy cppyy-packaging: do not pull in the backend until the very last moment to prevent errors when importing _cppyy for doc purposes

2018-05-07 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94498:4600e4a5a904
Date: 2018-05-07 19:25 -0700
http://bitbucket.org/pypy/pypy/changeset/4600e4a5a904/

Log:do not pull in the backend until the very last moment to prevent
errors when importing _cppyy for doc purposes

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
@@ -22,7 +22,7 @@
 }
 
 appleveldefs = {
-'_init_pythonify': 'pythonify._init_pythonify',
+'_post_import_startup'   : 'pythonify._post_import_startup',
 'add_pythonization'  : 'pythonify.add_pythonization',
 'Template'   : 'pythonify.CPPTemplate',
 }
@@ -35,9 +35,3 @@
 # code generation is not, so give it a chance to run now
 from pypy.module._cppyy import capi
 capi.register_pythonizations(space)
-
-def startup(self, space):
-from pypy.module._cppyy import capi
-capi.verify_backend(space)  # may raise ImportError
-
-space.call_method(self, '_init_pythonify')
diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -308,7 +308,7 @@
 c_call = state.capi_calls[name]
 except KeyError:
 if state.backend is None:
-load_backend(space)
+verify_backend(space)
 iface = state.capi_call_ifaces[name]
 cfunc = W_RCTypeFunc(space, iface[0], iface[1], False)
 c_call = state.backend.load_function(cfunc, 'cppyy_'+name)
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
@@ -1,5 +1,5 @@
 # NOT_RPYTHON
-# do not load _cppyy here, see _init_pythonify()
+# do not load _cppyy here, see _post_import_startup()
 import types
 import sys
 
@@ -22,7 +22,7 @@
 class CPPClass(CPPScope):
 pass
 
-# namespace base class (class base class defined in _init_pythonify)
+# namespace base class (class base class defined in _post_import_startup()
 class CPPNamespace(object):
 __metatype__ = CPPMetaNamespace
 
@@ -407,7 +407,7 @@
 pyclass.__len__ = return2
 
 
-def _init_pythonify():
+def _post_import_startup():
 # _cppyy should not be loaded at the module level, as that will trigger a
 # call to space.getbuiltinmodule(), which will cause _cppyy to be loaded
 # at pypy-c startup, rather than on the "import _cppyy" statement
diff --git a/pypy/module/_cppyy/test/test_advancedcpp.py 
b/pypy/module/_cppyy/test/test_advancedcpp.py
--- a/pypy/module/_cppyy/test/test_advancedcpp.py
+++ b/pypy/module/_cppyy/test/test_advancedcpp.py
@@ -22,7 +22,8 @@
 def setup_class(cls):
 cls.w_test_dct = cls.space.newtext(test_dct)
 cls.w_advanced = cls.space.appexec([], """():
-import ctypes
+import ctypes, _cppyy
+_cppyy._post_import_startup()
 return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, ))
 
 def test01_default_arguments(self):
diff --git a/pypy/module/_cppyy/test/test_cpp11features.py 
b/pypy/module/_cppyy/test/test_cpp11features.py
--- a/pypy/module/_cppyy/test/test_cpp11features.py
+++ b/pypy/module/_cppyy/test/test_cpp11features.py
@@ -14,7 +14,8 @@
 def setup_class(cls):
 cls.w_test_dct  = cls.space.newtext(test_dct)
 cls.w_example01 = cls.space.appexec([], """():
-import ctypes
+import ctypes, _cppyy
+_cppyy._post_import_startup()
 return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, ))
 
 def test01_shared_ptr(self):
diff --git a/pypy/module/_cppyy/test/test_cppyy.py 
b/pypy/module/_cppyy/test/test_cppyy.py
--- a/pypy/module/_cppyy/test/test_cppyy.py
+++ b/pypy/module/_cppyy/test/test_cppyy.py
@@ -33,6 +33,7 @@
 cls.w_lib, cls.w_instantiate, cls.w_example01, cls.w_payload = \
cls.space.unpackiterable(cls.space.appexec([], """():
 import _cppyy, ctypes
+_cppyy._post_import_startup()
 lib = ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)
 def cpp_instantiate(tt, *args):
 inst = _cppyy._bind_object(0, tt, True)
diff --git a/pypy/module/_cppyy/test/test_crossing.py 
b/pypy/module/_cppyy/test/test_crossing.py
--- a/pypy/module/_cppyy/test/test_crossing.py
+++ b/pypy/module/_cppyy/test/test_crossing.py
@@ -72,7 +72,9 @@
 # to allow the generated extension module be loaded first)
 cls.w_test_dct= cls.space.newtext(test_dct)
 cls.w_pre_imports = cls.space.appexec([], """():
-import ctypes, _cppyy""")   # prevents leak-checking complaints on 
ctypes' statics
+import ctypes, _cppyy
+_cppyy._post_import_startup()""")   # early import of ctypes
+  # prevents le

[pypy-commit] pypy default: Merge of cppyy-packaging: pulls in fully deferred loading for the backend (needed for pydoc tests in p3.5 branch), support for function pointer arguments, proper types for

2018-05-07 Thread wlav
Author: Wim Lavrijsen 
Branch: 
Changeset: r94499:a4c2916c877f
Date: 2018-05-07 21:02 -0700
http://bitbucket.org/pypy/pypy/changeset/a4c2916c877f/

Log:Merge of cppyy-packaging: pulls in fully deferred loading for the
backend (needed for pydoc tests in p3.5 branch), support for
function pointer arguments, proper types for anonymous enums, and
correct handling of const data.

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
@@ -7,6 +7,7 @@
 interpleveldefs = {
 '_resolve_name'  : 'interp_cppyy.resolve_name',
 '_scope_byname'  : 'interp_cppyy.scope_byname',
+'_is_static_data': 'interp_cppyy.is_static_data',
 '_is_template'   : 'interp_cppyy.is_template',
 '_std_string_name'   : 'interp_cppyy.std_string_name',
 '_set_class_generator'   : 'interp_cppyy.set_class_generator',
@@ -21,7 +22,7 @@
 }
 
 appleveldefs = {
-'_init_pythonify': 'pythonify._init_pythonify',
+'_post_import_startup'   : 'pythonify._post_import_startup',
 'add_pythonization'  : 'pythonify.add_pythonization',
 'Template'   : 'pythonify.CPPTemplate',
 }
@@ -34,9 +35,3 @@
 # code generation is not, so give it a chance to run now
 from pypy.module._cppyy import capi
 capi.register_pythonizations(space)
-
-def startup(self, space):
-from pypy.module._cppyy import capi
-capi.verify_backend(space)  # may raise ImportError
-
-space.call_method(self, '_init_pythonify')
diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -308,7 +308,7 @@
 c_call = state.capi_calls[name]
 except KeyError:
 if state.backend is None:
-load_backend(space)
+verify_backend(space)
 iface = state.capi_call_ifaces[name]
 cfunc = W_RCTypeFunc(space, iface[0], iface[1], False)
 c_call = state.backend.load_function(cfunc, 'cppyy_'+name)
@@ -421,7 +421,7 @@
 _cdata_to_ptr(space, call_capi(space, 'function_address_from_index', 
args)))
 def c_function_address_from_method(space, cppmethod):
 return rffi.cast(C_FUNC_PTR,
-_cdata_to_ptr(space, call_capi(space, 'function_address_from_method', 
_ArgH(cppmethod
+_cdata_to_ptr(space, call_capi(space, 'function_address_from_method', 
[_ArgH(cppmethod)])))
 
 # handling of function argument buffer ---
 def c_allocate_function_args(space, size):
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
@@ -686,6 +686,34 @@
 decref(space, rffi.cast(PyObject, rffi.cast(rffi.VOIDPP, arg)[0]))
 
 
+class FunctionPointerConverter(TypeConverter):
+_immutable_fields_ = ['signature']
+
+def __init__(self, space, signature):
+self.signature = signature
+
+def convert_argument(self, space, w_obj, address, call_local):
+# TODO: atm, does not actually get an overload, but a staticmethod
+from pypy.module._cppyy.interp_cppyy import W_CPPOverload
+cppol = space.interp_w(W_CPPOverload, w_obj)
+
+# find the function with matching signature
+for i in range(len(cppol.functions)):
+m = cppol.functions[i]
+if m.signature(False) == self.signature:
+x = rffi.cast(rffi.VOIDPP, address)
+x[0] = rffi.cast(rffi.VOIDP,
+capi.c_function_address_from_method(space, m.cppmethod))
+address = rffi.cast(capi.C_OBJECT, address)
+ba = rffi.cast(rffi.CCHARP, address)
+ba[capi.c_function_arg_typeoffset(space)] = 'p'
+return
+
+# lookup failed
+raise oefmt(space.w_TypeError,
+"no overload found matching %s", self.signature)
+
+
 class MacroConverter(TypeConverter):
 def from_memory(self, space, w_obj, w_pycppclass, offset):
 # TODO: get the actual type info from somewhere ...
@@ -749,6 +777,14 @@
 return InstancePtrPtrConverter(space, clsdecl)
 elif compound == "":
 return InstanceConverter(space, clsdecl)
+elif "(anonymous)" in name:
+# special case: enum w/o a type name
+return _converters["internal_enum_type_t"](space, default)
+elif "(*)" in name or "::*)" in name:
+# function pointer
+pos = name.find("*)")
+if pos > 0:
+return FunctionPointerConverter(space, name[pos+2:])
 
 #   5) void* or void converter (which fails on use)
 if 0 <= compound.find('*'):
diff --git a/pypy/module/_cppyy/executor.py b/pypy/module/_cppyy/exe

[pypy-commit] pypy cppyy-packaging: fix typo in comment

2018-05-07 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94500:49f83bfa0c9e
Date: 2018-05-07 21:08 -0700
http://bitbucket.org/pypy/pypy/changeset/49f83bfa0c9e/

Log:fix typo in comment

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
@@ -1,7 +1,7 @@
 from pypy.interpreter.mixedmodule import MixedModule
 
 class Module(MixedModule):
-"This module brigdes the cppyy frontend with its backend, through PyPy.\n\
+"This module bridges the cppyy frontend with its backend, through PyPy.\n\
 See http://cppyy.readthedocs.io/en/latest for full details."
 
 interpleveldefs = {
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: add helper to extract outer namespace from a C++ name

2018-05-15 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94595:ba933501a318
Date: 2018-05-07 22:29 -0700
http://bitbucket.org/pypy/pypy/changeset/ba933501a318/

Log:add helper to extract outer namespace from a C++ name

diff --git a/pypy/module/_cppyy/helper.py b/pypy/module/_cppyy/helper.py
--- a/pypy/module/_cppyy/helper.py
+++ b/pypy/module/_cppyy/helper.py
@@ -59,6 +59,26 @@
 name = name[:_find_qualifier_index(name)]
 return name.strip(' ')
 
+def extract_namespace(name):
+# find the namespace the named class lives in, take care of templates
+tpl_open = 0
+for pos in xrange(len(name)-1, 1, -1):
+c = name[pos]
+
+# count '<' and '>' to be able to skip template contents
+if c == '>':
+tpl_open += 1
+elif c == '<':
+tpl_open -= 1
+
+# collect name up to "::"
+elif tpl_open == 0 and c == ':' and name[pos-1] == ':':
+# found the extend of the scope ... done
+return name[0:pos-1]
+
+# no namespace; assume outer scope
+return ""
+
 
 #- operator mappings 
 _operator_mappings = {}
diff --git a/pypy/module/_cppyy/test/test_helper.py 
b/pypy/module/_cppyy/test/test_helper.py
--- a/pypy/module/_cppyy/test/test_helper.py
+++ b/pypy/module/_cppyy/test/test_helper.py
@@ -50,3 +50,14 @@
 
 assert helper.map_operator_name(None, "func", 0, "")== "func"
 assert helper.map_operator_name(None, "some_method", 0, "") == 
"some_method"
+
+
+def test_namespace_extraction():
+assert helper.extract_namespace("vector")== ""
+assert helper.extract_namespace("std::vector")   == "std"
+assert helper.extract_namespace("std::vector")   == "std"
+assert helper.extract_namespace("std::vector")  == "std"
+assert helper.extract_namespace("vector")== ""
+assert helper.extract_namespace("vector")   == ""
+assert helper.extract_namespace("aap::noot::mies::zus")  == 
"aap::noot::mies"
+
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: pythonization improvements

2018-05-15 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94596:10c6393b2cd5
Date: 2018-05-15 20:59 -0700
http://bitbucket.org/pypy/pypy/changeset/10c6393b2cd5/

Log:pythonization improvements

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
@@ -19,12 +19,14 @@
 '_bind_object'   : 'interp_cppyy._bind_object',
 'bind_object': 'interp_cppyy.bind_object',
 'move'   : 'interp_cppyy.move',
+'_pin_type'  : 'interp_cppyy._pin_type',
 }
 
 appleveldefs = {
 '_post_import_startup'   : 'pythonify._post_import_startup',
+'Template'   : 'pythonify.CPPTemplate',
 'add_pythonization'  : 'pythonify.add_pythonization',
-'Template'   : 'pythonify.CPPTemplate',
+'remove_pythonization'   : 'pythonify.remove_pythonization',
 }
 
 def __init__(self, space, *args):
diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -676,7 +676,7 @@
 space.setattr(w_pycppclass, space.newtext(m1),
   space.getattr(w_pycppclass, space.newtext(m2)))
 
-def pythonize(space, name, w_pycppclass):
+def pythonize(space, w_pycppclass, name):
 if name == "string":
 space.setattr(w_pycppclass, space.newtext("c_str"), 
_pythonizations["stdstring_c_str"])
 _method_alias(space, w_pycppclass, "_cppyy_as_builtin", "c_str")
diff --git a/pypy/module/_cppyy/helper.py b/pypy/module/_cppyy/helper.py
--- a/pypy/module/_cppyy/helper.py
+++ b/pypy/module/_cppyy/helper.py
@@ -59,26 +59,6 @@
 name = name[:_find_qualifier_index(name)]
 return name.strip(' ')
 
-def extract_namespace(name):
-# find the namespace the named class lives in, take care of templates
-tpl_open = 0
-for pos in xrange(len(name)-1, 1, -1):
-c = name[pos]
-
-# count '<' and '>' to be able to skip template contents
-if c == '>':
-tpl_open += 1
-elif c == '<':
-tpl_open -= 1
-
-# collect name up to "::"
-elif tpl_open == 0 and c == ':' and name[pos-1] == ':':
-# found the extend of the scope ... done
-return name[0:pos-1]
-
-# no namespace; assume outer scope
-return ""
-
 
 #- operator mappings 
 _operator_mappings = {}
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
@@ -14,6 +14,7 @@
 from pypy.module._cffi_backend import ctypefunc
 from pypy.module._cppyy import converter, executor, ffitypes, helper
 
+CLASS_FLAGS_IS_PINNED  = 0x0001
 
 INSTANCE_FLAGS_PYTHON_OWNS = 0x0001
 INSTANCE_FLAGS_IS_REF  = 0x0002
@@ -131,7 +132,7 @@
 cppclass = space.interp_w(W_CPPClassDecl, w_cppclass)
 # add back-end specific method pythonizations (doing this on the wrapped
 # class allows simple aliasing of methods)
-capi.pythonize(space, cppclass.name, w_pycppclass)
+capi.pythonize(space, w_pycppclass, cppclass.name)
 state = space.fromcache(State)
 state.cppclass_registry[rffi.cast(rffi.LONG, cppclass.handle)] = 
w_pycppclass
 
@@ -816,14 +817,15 @@
 
 
 class W_CPPScopeDecl(W_Root):
-_attrs_ = ['space', 'handle', 'name', 'methods', 'datamembers']
+_attrs_ = ['space', 'handle', 'flags', 'name', 'methods', 'datamembers']
 _immutable_fields_ = ['handle', 'name']
 
 def __init__(self, space, opaque_handle, final_scoped_name):
 self.space = space
-self.name = final_scoped_name
 assert lltype.typeOf(opaque_handle) == capi.C_SCOPE
 self.handle = opaque_handle
+self.flags = 0
+self.name = final_scoped_name
 self.methods = {}
 # Do not call "self._build_methods()" here, so that a distinction can
 #  be made between testing for existence (i.e. existence in the cache
@@ -1316,7 +1318,7 @@
 
 # cast to actual if requested and possible
 w_pycppclass = None
-if do_cast and rawobject:
+if do_cast and rawobject and not (clsdecl.flags & CLASS_FLAGS_IS_PINNED):
 actual = capi.c_actual_class(space, clsdecl, rawobject)
 if actual != clsdecl.handle:
 try:
@@ -1390,3 +1392,13 @@
 if obj:
 obj.flags |= INSTANCE_FLAGS_IS_R_VALUE
 return w_obj
+
+
+# pythonization interface ---
+
+# do not auto-cast to given type
+@unwrap_spec(w_pycppclass=W_Root)
+def _pin_type(space, w_pycppclass):
+w_clsdecl = space.findattr(w_pycppclass, space.newtext("__cppdecl__"))
+decl = space.interp_w(W_CPPClassDecl, w_clsdecl)
+decl.flags |= CLASS_FLAGS_IS_PINNED
diff --git a/pypy/m

[pypy-commit] pypy cppyy-packaging: add support for unsigned char arrays and general cleanup of array binding code + tests

2018-05-17 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94611:eb16b0aff1e3
Date: 2018-05-17 09:39 -0700
http://bitbucket.org/pypy/pypy/changeset/eb16b0aff1e3/

Log:add support for unsigned char arrays and general cleanup of array
binding code + tests

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
@@ -11,6 +11,3 @@
 assert lltype.typeOf(ptr) == C_OBJECT
 address = rffi.cast(rffi.CCHARP, ptr)
 return rffi.cast(C_OBJECT, lltype.direct_ptradd(address, offset))
-
-def exchange_address(ptr, cif_descr, index):
-return rffi.ptradd(ptr, cif_descr.exchange_args[index])
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
@@ -7,7 +7,7 @@
 from rpython.rlib import rfloat, rawrefcount
 
 from pypy.module._rawffi.interp_rawffi import letter2tp
-from pypy.module._rawffi.array import W_Array, W_ArrayInstance
+from pypy.module._rawffi.array import W_ArrayInstance
 
 from pypy.module._cppyy import helper, capi, ffitypes
 
@@ -130,20 +130,6 @@
 pass
 
 
-class ArrayCache(object):
-def __init__(self, space):
-self.space = space
-def __getattr__(self, name):
-if name.startswith('array_'):
-typecode = name[len('array_'):]
-arr = self.space.interp_w(W_Array, letter2tp(self.space, typecode))
-setattr(self, name, arr)
-return arr
-raise AttributeError(name)
-
-def _freeze_(self):
-return True
-
 class ArrayTypeConverterMixin(object):
 _mixin_ = True
 _immutable_fields_ = ['size']
@@ -162,9 +148,7 @@
 # read access, so no copy needed
 address_value = self._get_raw_address(space, w_obj, offset)
 address = rffi.cast(rffi.ULONG, address_value)
-cache = space.fromcache(ArrayCache)
-arr = getattr(cache, 'array_' + self.typecode)
-return arr.fromaddress(space, address, self.size)
+return W_ArrayInstance(space, letter2tp(space, self.typecode), 
self.size, address)
 
 def to_memory(self, space, w_obj, w_value, offset):
 # copy the full array (uses byte copy for now)
@@ -205,17 +189,15 @@
 # read access, so no copy needed
 address_value = self._get_raw_address(space, w_obj, offset)
 address = rffi.cast(rffi.ULONGP, address_value)
-cache = space.fromcache(ArrayCache)
-arr = getattr(cache, 'array_' + self.typecode)
-return arr.fromaddress(space, address[0], self.size)
+return W_ArrayInstance(space, letter2tp(space, self.typecode), 
self.size, address[0])
 
 def to_memory(self, space, w_obj, w_value, offset):
 # copy only the pointer value
 rawobject = get_rawobject_nonnull(space, w_obj)
-byteptr = rffi.cast(rffi.CCHARPP, capi.direct_ptradd(rawobject, 
offset))
+byteptr = rffi.cast(rffi.VOIDPP, capi.direct_ptradd(rawobject, offset))
 buf = space.getarg_w('s*', w_value)
 try:
-byteptr[0] = buf.get_raw_address()
+byteptr[0] = rffi.cast(rffi.VOIDP, buf.get_raw_address())
 except ValueError:
 raise oefmt(space.w_TypeError,
 "raw buffer interface not supported")
@@ -337,6 +319,10 @@
 address = rffi.cast(rffi.CCHARP, self._get_raw_address(space, w_obj, 
offset))
 address[0] = self._unwrap_object(space, w_value)
 
+
+class UCharConverter(ffitypes.typeid(rffi.UCHAR), CharConverter):
+pass
+
 class FloatConverter(ffitypes.typeid(rffi.FLOAT), FloatTypeConverterMixin, 
TypeConverter):
 _immutable_fields_ = ['default']
 
@@ -449,12 +435,12 @@
 # returned as a long value for the address (INTPTR_T is not proper
 # per se, but rffi does not come with a PTRDIFF_T)
 address = self._get_raw_address(space, w_obj, offset)
-ptrval = rffi.cast(rffi.ULONG, rffi.cast(rffi.VOIDPP, address)[0])
-if ptrval == 0:
+ptrval = rffi.cast(rffi.ULONGP, address)[0]
+if ptrval == rffi.cast(rffi.ULONG, 0):
 from pypy.module._cppyy import interp_cppyy
 return interp_cppyy.get_nullptr(space)
-arr = space.interp_w(W_Array, letter2tp(space, 'P'))
-return arr.fromaddress(space, ptrval, sys.maxint)
+shape = letter2tp(space, 'P')
+return W_ArrayInstance(space, shape, sys.maxint/shape.size, ptrval)
 
 def to_memory(self, space, w_obj, w_value, offset):
 address = rffi.cast(rffi.VOIDPP, self._get_raw_address(space, w_obj, 
offset))
@@ -797,6 +783,7 @@
 
 _converters["bool"] = BoolConverter
 _converters["char"] = CharConverter
+_converters["unsigned char"]= UCharConverter
 _converters["float"]= FloatConverter
 _converters["const float&"] = ConstFloatRefConverter
 

[pypy-commit] pypy cppyy-packaging: first stab at transparent smart pointer support and improved templated methods

2018-06-07 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94732:a1135702ca77
Date: 2018-05-18 10:28 -0700
http://bitbucket.org/pypy/pypy/changeset/a1135702ca77/

Log:first stab at transparent smart pointer support and improved
templated methods

diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -207,6 +207,8 @@
 'num_bases': ([c_type],   c_int),
 'base_name': ([c_type, c_int],
c_ccharp),
 'is_subtype'   : ([c_type, c_type],   c_int),
+'smartptr_info': ([c_ccharp, c_voidp, c_voidp],
 c_int),
+'add_smartptr_type': ([c_ccharp], c_void),
 
 'base_offset'  : ([c_type, c_type, c_object, c_int],   
 c_ptrdiff_t),
 
@@ -479,6 +481,21 @@
 if derived == base:
 return bool(1)
 return space.bool_w(call_capi(space, 'is_subtype', [_ArgH(derived.handle), 
_ArgH(base.handle)]))
+def c_smartptr_info(space, name):
+out_raw   = lltype.malloc(rffi.ULONGP.TO, 1, flavor='raw', zero=True)
+out_deref = lltype.malloc(rffi.ULONGP.TO, 1, flavor='raw', zero=True)
+try:
+args = [_ArgS(name),
+   _ArgP(rffi.cast(rffi.VOIDP, out_raw)), _ArgP(rffi.cast(rffi.VOIDP, 
out_deref))]
+result = space.bool_w(call_capi(space, 'smartptr_info', args))
+raw   = rffi.cast(C_TYPE, out_raw[0])
+deref = rffi.cast(C_METHOD, out_deref[0])
+finally:
+lltype.free(out_deref, flavor='raw')
+lltype.free(out_raw, flavor='raw')
+return (result, raw, deref)
+def c_add_smartptr_type(space, name):
+return space.bool_w(call_capi(space, 'add_smartptr_type', [_ArgS(name)]))
 
 def _c_base_offset(space, derived_h, base_h, address, direction):
 args = [_ArgH(derived_h), _ArgH(base_h), _ArgH(address), _ArgL(direction)]
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
@@ -700,6 +700,24 @@
 "no overload found matching %s", self.signature)
 
 
+class SmartPtrCppObjectConverter(TypeConverter):
+_immutable_fields = ['smart', 'raw', 'deref']
+
+def __init__(self, space, smartdecl, raw, deref):
+from pypy.module._cppyy.interp_cppyy import W_CPPClassDecl, 
get_pythonized_cppclass
+self.smartdecl = smartdecl
+w_raw   = get_pythonized_cppclass(space, raw)
+self.rawdecl   = space.interp_w(W_CPPClassDecl,
+space.findattr(w_raw, space.newtext("__cppdecl__")))
+self.deref = deref
+
+def from_memory(self, space, w_obj, w_pycppclass, offset):
+address = rffi.cast(capi.C_OBJECT, self._get_raw_address(space, w_obj, 
offset))
+from pypy.module._cppyy import interp_cppyy
+return interp_cppyy.wrap_cppinstance(space, address,
+self.rawdecl, smartdecl=self.smartdecl, deref=self.deref, 
do_cast=False)
+
+
 class MacroConverter(TypeConverter):
 def from_memory(self, space, w_obj, w_pycppclass, offset):
 # TODO: get the actual type info from somewhere ...
@@ -715,26 +733,25 @@
 #   1) full, exact match
 #   1a) const-removed match
 #   2) match of decorated, unqualified type
-#   3) accept ref as pointer (for the stubs, const& can be
-#   by value, but that does not work for the ffi path)
-#   4) generalized cases (covers basically all user classes)
-#   5) void* or void converter (which fails on use)
+#   3) generalized cases (covers basically all user classes)
+#   3a) smart pointers
+#   4) void* or void converter (which fails on use)
 
 name = capi.c_resolve_name(space, _name)
 
-#   1) full, exact match
+# full, exact match
 try:
 return _converters[name](space, default)
 except KeyError:
 pass
 
-#   1a) const-removed match
+# const-removed match
 try:
 return _converters[helper.remove_const(name)](space, default)
 except KeyError:
 pass
 
-#   2) match of decorated, unqualified type
+# match of decorated, unqualified type
 compound = helper.compound(name)
 clean_name = capi.c_resolve_name(space, helper.clean_type(name))
 try:
@@ -744,15 +761,19 @@
 except KeyError:
 pass
 
-#   3) TODO: accept ref as pointer
-
-#   4) generalized cases (covers basically all user classes)
+# generalized cases (covers basically all user classes)
 from pypy.module._cppyy import interp_cppyy
 scope_decl = interp_cppyy.scope_byname(space, clean_name)
 if scope_decl:
-# type check for the benefit of the annotator
 from pypy.module._cppyy.interp_cppyy import W_CPPClassDecl
 clsdecl = space.interp_w(W_CPPClassDecl, scope_de

[pypy-commit] pypy cppyy-packaging: fix memory leak in test

2018-06-07 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94734:83daee4823bc
Date: 2018-05-21 14:30 -0700
http://bitbucket.org/pypy/pypy/changeset/83daee4823bc/

Log:fix memory leak in test

diff --git a/pypy/module/_cppyy/test/datatypes.cxx 
b/pypy/module/_cppyy/test/datatypes.cxx
--- a/pypy/module/_cppyy/test/datatypes.cxx
+++ b/pypy/module/_cppyy/test/datatypes.cxx
@@ -80,6 +80,7 @@
 void CppyyTestData::destroy_arrays() {
 if (m_owns_arrays == true) {
 delete[] m_bool_array2;
+delete[] m_uchar_array2;
 delete[] m_short_array2;
 delete[] m_ushort_array2;
 delete[] m_int_array2;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: finish pythonization of smart pointers

2018-06-07 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94736:bf4f9f2a4234
Date: 2018-05-21 20:56 -0700
http://bitbucket.org/pypy/pypy/changeset/bf4f9f2a4234/

Log:finish pythonization of smart pointers

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
@@ -699,8 +699,8 @@
 "no overload found matching %s", self.signature)
 
 
-class SmartPtrCppObjectConverter(TypeConverter):
-_immutable_fields = ['smartdecl', 'rawdecl', 'deref']
+class SmartPointerConverter(TypeConverter):
+_immutable_fields = ['typecode', 'smartdecl', 'rawdecl', 'deref']
 typecode= 'V'
 
 def __init__(self, space, smartdecl, raw, deref):
@@ -746,6 +746,19 @@
 return interp_cppyy.wrap_cppinstance(space, address,
 self.rawdecl, smartdecl=self.smartdecl, deref=self.deref, 
do_cast=False)
 
+class SmartPointerPtrConverter(SmartPointerConverter):
+typecode= 'o'
+
+def from_memory(self, space, w_obj, w_pycppclass, offset):
+self._is_abstract(space)
+
+def to_memory(self, space, w_obj, w_value, offset):
+self._is_abstract(space)
+
+
+class SmartPointerRefConverter(SmartPointerPtrConverter):
+typecode= 'V'
+
 
 class MacroConverter(TypeConverter):
 def from_memory(self, space, w_obj, w_pycppclass, offset):
@@ -800,7 +813,13 @@
 # check smart pointer type
 check_smart = capi.c_smartptr_info(space, clean_name)
 if check_smart[0]:
-return SmartPtrCppObjectConverter(space, clsdecl, check_smart[1], 
check_smart[2])
+if compound == '':
+return SmartPointerConverter(space, clsdecl, check_smart[1], 
check_smart[2])
+elif compound == '*':
+return SmartPointerPtrConverter(space, clsdecl, 
check_smart[1], check_smart[2])
+elif compound == '&':
+return SmartPointerRefConverter(space, clsdecl, 
check_smart[1], check_smart[2])
+# fall through: can still return smart pointer in non-smart way
 
 # type check for the benefit of the annotator
 if compound == "*":
diff --git a/pypy/module/_cppyy/executor.py b/pypy/module/_cppyy/executor.py
--- a/pypy/module/_cppyy/executor.py
+++ b/pypy/module/_cppyy/executor.py
@@ -125,7 +125,6 @@
 
 
 class CStringExecutor(FunctionExecutor):
-
 def execute(self, space, cppmethod, cppthis, num_args, args):
 lresult = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
 ccpresult = rffi.cast(rffi.CCHARP, lresult)
@@ -136,7 +135,6 @@
 
 
 class ConstructorExecutor(FunctionExecutor):
-
 def execute(self, space, cppmethod, cpptype, num_args, args):
 from pypy.module._cppyy import interp_cppyy
 newthis = capi.c_constructor(space, cppmethod, cpptype, num_args, args)
@@ -144,80 +142,77 @@
 return space.newlong(rffi.cast(rffi.LONG, newthis))   # really want 
ptrdiff_t here
 
 
-class InstancePtrExecutor(FunctionExecutor):
-_immutable_fields_ = ['cppclass']
+class InstanceExecutor(FunctionExecutor):
+# For return of a C++ instance by pointer: MyClass* func()
+_immutable_fields_ = ['clsdecl']
 
-def __init__(self, space, cppclass):
-FunctionExecutor.__init__(self, space, cppclass)
-self.cppclass = cppclass
+def __init__(self, space, clsdecl):
+FunctionExecutor.__init__(self, space, clsdecl)
+self.clsdecl = clsdecl
+
+def _wrap_result(self, space, obj):
+from pypy.module._cppyy import interp_cppyy
+return interp_cppyy.wrap_cppinstance(space,
+obj, self.clsdecl, do_cast=False, python_owns=True, fresh=True)
+
+def execute(self, space, cppmethod, cppthis, num_args, args):
+oresult = capi.c_call_o(space, cppmethod, cppthis, num_args, args, 
self.clsdecl)
+return self._wrap_result(space, rffi.cast(capi.C_OBJECT, oresult))
+
+
+class InstancePtrExecutor(InstanceExecutor):
+# For return of a C++ instance by pointer: MyClass* func()
 
 def cffi_type(self, space):
 state = space.fromcache(ffitypes.State)
 return state.c_voidp
 
+def _wrap_result(self, space, obj):
+from pypy.module._cppyy import interp_cppyy
+return interp_cppyy.wrap_cppinstance(space, obj, self.clsdecl)
+
 def execute(self, space, cppmethod, cppthis, num_args, args):
-from pypy.module._cppyy import interp_cppyy
-long_result = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
-ptr_result = rffi.cast(capi.C_OBJECT, long_result)
-pyres = interp_cppyy.wrap_cppinstance(space, ptr_result, self.cppclass)
-return pyres
+lresult = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
+return self._wrap_result(space, rffi.cast(capi.C_OBJECT, lresult))
 
 def execute_libffi(self, space, cif_descr, funcaddr, buffer):
 jit_libffi.jit_ffi_call(cif_descr, funcadd

[pypy-commit] pypy cppyy-packaging: reduce layers in method dispatch for simplicity, performance, and support of templated methods (this requires backend

2018-06-07 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94737:264a0794b659
Date: 2018-06-07 08:40 -0700
http://bitbucket.org/pypy/pypy/changeset/264a0794b659/

Log:reduce layers in method dispatch for simplicity, performance, and
support of templated methods (this requires backend 1.1.0)

diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -88,7 +88,7 @@
 assert obj._voidp != rffi.cast(rffi.VOIDP, 0)
 data = rffi.cast(rffi.VOIDPP, data)
 data[0] = obj._voidp
-else:# only other use is sring
+else:# only other use is string
 assert obj.tc == 's'
 n = len(obj._string)
 assert raw_string == rffi.cast(rffi.CCHARP, 0)
@@ -183,8 +183,7 @@
 'constructor'  : ([c_method, c_object, c_int, c_voidp],   
c_object),
 'call_o'   : ([c_method, c_object, c_int, c_voidp, c_type],
 c_object),
 
-'function_address_from_index'  : ([c_scope, c_index], 
c_voidp), # TODO: verify
-'function_address_from_method' : ([c_method], 
c_voidp), # id.
+'function_address' : ([c_method], 
c_voidp), # TODO: verify
 
 # handling of function argument buffer
 'allocate_function_args'   : ([c_int],c_voidp),
@@ -216,30 +215,30 @@
 'num_methods'  : ([c_scope],  c_int),
 'method_indices_from_name' : ([c_scope, c_ccharp],
c_index_array),
 
-'method_name'  : ([c_scope, c_index], 
c_ccharp),
-'method_mangled_name'  : ([c_scope, c_index], 
c_ccharp),
-'method_result_type'   : ([c_scope, c_index], 
c_ccharp),
-'method_num_args'  : ([c_scope, c_index], c_int),
-'method_req_args'  : ([c_scope, c_index], c_int),
-'method_arg_type'  : ([c_scope, c_index, c_int],  
c_ccharp),
-'method_arg_default'   : ([c_scope, c_index, c_int],  
c_ccharp),
-'method_signature' : ([c_scope, c_index, c_int],  
c_ccharp),
-'method_prototype' : ([c_scope, c_index, c_int],  
c_ccharp),
+'get_method'   : ([c_scope, c_index], 
c_method),
+
+'method_name'  : ([c_method], 
c_ccharp),
+'method_mangled_name'  : ([c_method], 
c_ccharp),
+'method_result_type'   : ([c_method], 
c_ccharp),
+'method_num_args'  : ([c_method], c_int),
+'method_req_args'  : ([c_method], c_int),
+'method_arg_type'  : ([c_method, c_int],  
c_ccharp),
+'method_arg_default'   : ([c_method, c_int],  
c_ccharp),
+'method_signature' : ([c_method, c_int],  
c_ccharp),
+'method_prototype' : ([c_scope, c_method, c_int], 
c_ccharp),
 'is_const_method'  : ([c_method], c_int),
 
 'exists_method_template'   : ([c_scope, c_ccharp],c_int),
 'method_is_template'   : ([c_scope, c_index], c_int),
-'method_num_template_args' : ([c_scope, c_index], c_int),
-'method_template_arg_name' : ([c_scope, c_index, c_index], 
 c_ccharp),
+'get_method_template'  : ([c_scope, c_ccharp, c_ccharp],   
 c_method),
 
-'get_method'   : ([c_scope, c_index], 
c_method),
 'get_global_operator'  : ([c_scope, c_scope, c_scope, 
c_ccharp],   c_index),
 
 # method properties
-'is_public_method' : ([c_type, c_index],  c_int),
-'is_constructor'   : ([c_type, c_index],  c_int),
-'is_destructor': ([c_type, c_index],  c_int),
-'is_staticmethod'  : ([c_type, c_index],  c_int),
+'is_public_method' : ([c_method], c_int),
+'is_constructor'   : ([c_method], c_int),
+'is_destructor': ([c_method], c_int),
+'is_staticmethod'  : ([c_method], c_int),
 
 # data member reflection information
 'num_datamembers'  : ([c_scope],  c_int),
@@ -417,13 +416,9 @@
 args = [_ArgH(cppmethod), _ArgH(cppobject), _ArgL(nargs), _ArgP(cargs), 
_ArgH(cppclass.handle)]
 return _cdata_to_cobject(space, call_capi(space, 'call_o', args))
 
-def c_functio

[pypy-commit] pypy cppyy-packaging: more smart pointer support

2018-06-07 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94733:fba8c8e53f31
Date: 2018-05-18 11:23 -0700
http://bitbucket.org/pypy/pypy/changeset/fba8c8e53f31/

Log:more smart pointer support

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
@@ -625,7 +625,6 @@
 
 class StdStringRefConverter(InstancePtrConverter):
 _immutable_fields_ = ['cppclass', 'typecode']
-
 typecode= 'V'
 
 def __init__(self, space, extra):
@@ -701,7 +700,8 @@
 
 
 class SmartPtrCppObjectConverter(TypeConverter):
-_immutable_fields = ['smart', 'raw', 'deref']
+_immutable_fields = ['smartdecl', 'rawdecl', 'deref']
+typecode= 'V'
 
 def __init__(self, space, smartdecl, raw, deref):
 from pypy.module._cppyy.interp_cppyy import W_CPPClassDecl, 
get_pythonized_cppclass
@@ -711,6 +711,35 @@
 space.findattr(w_raw, space.newtext("__cppdecl__")))
 self.deref = deref
 
+def _unwrap_object(self, space, w_obj):
+from pypy.module._cppyy.interp_cppyy import W_CPPInstance
+if isinstance(w_obj, W_CPPInstance):
+# w_obj could carry a 'hidden' smart ptr or be one, cover both 
cases
+have_match = False
+if w_obj.smartdecl and capi.c_is_subtype(space, w_obj.smartdecl, 
self.smartdecl):
+# hidden case, do not derefence when getting obj address
+have_match = True
+rawobject = w_obj._rawobject  # TODO: this direct access 
if fugly
+offset = capi.c_base_offset(space, w_obj.smartdecl, 
self.smartdecl, rawobject, 1)
+elif capi.c_is_subtype(space, w_obj.clsdecl, self.smartdecl):
+# exposed smart pointer
+have_match = True
+rawobject = w_obj.get_rawobject()
+offset = capi.c_base_offset(space, w_obj.clsdecl, 
self.smartdecl, rawobject, 1)
+if have_match:
+obj_address = capi.direct_ptradd(rawobject, offset)
+return rffi.cast(capi.C_OBJECT, obj_address)
+
+raise oefmt(space.w_TypeError,
+"cannot pass %T as %s", w_obj, self.clsdecl.name)
+
+def convert_argument(self, space, w_obj, address, call_local):
+x = rffi.cast(rffi.VOIDPP, address)
+x[0] = rffi.cast(rffi.VOIDP, self._unwrap_object(space, w_obj))
+address = rffi.cast(capi.C_OBJECT, address)
+ba = rffi.cast(rffi.CCHARP, address)
+ba[capi.c_function_arg_typeoffset(space)] = self.typecode
+
 def from_memory(self, space, w_obj, w_pycppclass, offset):
 address = rffi.cast(capi.C_OBJECT, self._get_raw_address(space, w_obj, 
offset))
 from pypy.module._cppyy import interp_cppyy
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: add pythonization tests

2018-06-07 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94735:3fd316125c15
Date: 2018-05-21 14:44 -0700
http://bitbucket.org/pypy/pypy/changeset/3fd316125c15/

Log:add pythonization tests

diff --git a/pypy/module/_cppyy/test/pythonizables.cxx 
b/pypy/module/_cppyy/test/pythonizables.cxx
new file mode 100644
--- /dev/null
+++ b/pypy/module/_cppyy/test/pythonizables.cxx
@@ -0,0 +1,29 @@
+#include "pythonizables.h"
+
+
+pyzables::MyBase::~MyBase() {}
+pyzables::MyDerived::~MyDerived() {}
+
+pyzables::MyBase* pyzables::GimeDerived() {
+   return new MyDerived();
+}
+
+
+//===
+int pyzables::Countable::sInstances = 0;
+pyzables::SharedCountable_t pyzables::mine =
+pyzables::SharedCountable_t(new pyzables::Countable);
+
+void pyzables::renew_mine() { mine = std::shared_ptr(new 
Countable); }
+
+pyzables::SharedCountable_t pyzables::gime_mine() { return mine; }
+pyzables::SharedCountable_t* pyzables::gime_mine_ptr() { return &mine; }
+pyzables::SharedCountable_t& pyzables::gime_mine_ref() { return mine; }
+
+unsigned int pyzables::pass_mine_sp(std::shared_ptr ptr) { return 
ptr->m_check; }
+unsigned int pyzables::pass_mine_sp_ref(std::shared_ptr& ptr) { 
return ptr->m_check; }
+unsigned int pyzables::pass_mine_sp_ptr(std::shared_ptr* ptr) { 
return (*ptr)->m_check; }
+
+unsigned int pyzables::pass_mine_rp(Countable c) { return c.m_check; }
+unsigned int pyzables::pass_mine_rp_ref(const Countable& c) { return 
c.m_check; }
+unsigned int pyzables::pass_mine_rp_ptr(const Countable* c) { return 
c->m_check; }
diff --git a/pypy/module/_cppyy/test/pythonizables.h 
b/pypy/module/_cppyy/test/pythonizables.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/_cppyy/test/pythonizables.h
@@ -0,0 +1,60 @@
+#include 
+#include 
+
+
+namespace pyzables {
+
+//===
+class SomeDummy1 {};
+class SomeDummy2 {};
+
+
+//===
+class MyBase {
+public:
+virtual ~MyBase();
+};
+class MyDerived : public MyBase {
+public:
+virtual ~MyDerived();
+};
+
+MyBase* GimeDerived();
+
+
+//===
+class Countable {
+public:
+Countable() { ++sInstances; }
+Countable(const Countable&) { ++sInstances; }
+Countable& operator=(const Countable&) { return *this; }
+~Countable() { --sInstances; }
+
+public:
+virtual const char* say_hi() { return "Hi!"; }
+
+public:
+unsigned int m_check = 0xcdcdcdcd;
+
+public:
+static int sInstances;
+};
+
+typedef std::shared_ptr SharedCountable_t; 
+extern SharedCountable_t mine;
+
+void renew_mine();
+
+SharedCountable_t gime_mine();
+SharedCountable_t* gime_mine_ptr();
+SharedCountable_t& gime_mine_ref();
+
+unsigned int pass_mine_sp(SharedCountable_t p);
+unsigned int pass_mine_sp_ref(SharedCountable_t& p);
+unsigned int pass_mine_sp_ptr(SharedCountable_t* p);
+
+unsigned int pass_mine_rp(Countable);
+unsigned int pass_mine_rp_ref(const Countable&);
+unsigned int pass_mine_rp_ptr(const Countable*);
+
+} // namespace pyzables
diff --git a/pypy/module/_cppyy/test/pythonizables.xml 
b/pypy/module/_cppyy/test/pythonizables.xml
new file mode 100644
--- /dev/null
+++ b/pypy/module/_cppyy/test/pythonizables.xml
@@ -0,0 +1,7 @@
+
+
+  
+  
+  
+
+
diff --git a/pypy/module/_cppyy/test/test_pythonization.py 
b/pypy/module/_cppyy/test/test_pythonization.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_cppyy/test/test_pythonization.py
@@ -0,0 +1,147 @@
+import py, os, sys
+from pytest import raises
+from .support import setup_make
+
+
+currpath = py.path.local(__file__).dirpath()
+test_dct = str(currpath.join("pythonizablesDict.so"))
+
+def setup_module(mod):
+setup_make("pythonizablesDict.so")
+
+class AppTestPYTHONIZATION:
+spaceconfig = dict(usemodules=['_cppyy', '_rawffi', 'itertools'])
+
+def setup_class(cls):
+cls.w_test_dct  = cls.space.newtext(test_dct)
+cls.w_datatypes = cls.space.appexec([], """():
+import ctypes, _cppyy
+_cppyy._post_import_startup()
+return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, ))
+
+def test00_api(self):
+"""Test basic semantics of the pythonization API"""
+
+import _cppyy
+
+raises(TypeError, _cppyy.add_pythonization, 1)
+
+def pythonizor1(klass, name):
+pass
+
+def pythonizor2(klass, name):
+pass
+
+pythonizor3 = pythonizor1
+
+_cppyy.add_pythonization(pythonizor1)
+assert _cppyy.remove_pythonization(pythonizor2) == False
+assert _cppyy.remove_pythonization(pythonizor3) == True
+
+def test01_more_api(self):
+"""Further API semantics"""
+
+import _cppyy as cppyy
+
+def pythonizor(klass, name):
+if name == 'pyzables::SomeDummy1':
+kla

[pypy-commit] pypy cppyy-packaging: bring the dummy backend for testing up-to-date

2018-06-07 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94738:9820fab951d5
Date: 2018-06-07 15:57 -0700
http://bitbucket.org/pypy/pypy/changeset/9820fab951d5/

Log:bring the dummy backend for testing up-to-date

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
@@ -68,9 +68,11 @@
 pass
 # array type
 try:
+if hasattr(space, "fake"):
+raise NotImplementedError
 arr = space.interp_w(W_ArrayInstance, w_obj, can_be_None=True)
-#if arr:
-#return rffi.cast(rffi.VOIDP, space.uint_w(arr.getbuffer(space)))
+if arr:
+return rffi.cast(rffi.VOIDP, space.uint_w(arr.getbuffer(space)))
 except Exception:
 pass
 # pre-defined nullptr
diff --git a/pypy/module/_cppyy/src/dummy_backend.cxx 
b/pypy/module/_cppyy/src/dummy_backend.cxx
--- a/pypy/module/_cppyy/src/dummy_backend.cxx
+++ b/pypy/module/_cppyy/src/dummy_backend.cxx
@@ -60,7 +60,6 @@
const std::string& returntype,
EMethodType mtype = kNormal) :
 m_name(name), m_argtypes(argtypes), m_returntype(returntype), 
m_type(mtype) {}
-
 std::string m_name;
 std::vector m_argtypes;
 std::string m_returntype;
@@ -72,7 +71,6 @@
 const std::string& type,
 ptrdiff_t offset, bool isstatic) :
 m_name(name), m_type(type), m_offset(offset), m_isstatic(isstatic) {}
-
 std::string m_name;
 std::string m_type;
 ptrdiff_t m_offset;
@@ -81,20 +79,20 @@
 
 struct Cppyy_PseudoClassInfo {
 Cppyy_PseudoClassInfo() {}
-Cppyy_PseudoClassInfo(const std::vector& methods,
-  long method_offset,
+Cppyy_PseudoClassInfo(const std::vector& methods,
   const std::vector& data) :
-m_methods(methods), m_method_offset(method_offset), m_datambrs(data) {}
-
-std::vector m_methods;
-long m_method_offset;
+m_methods(methods), m_datambrs(data) {}
+std::vector m_methods;
 std::vector m_datambrs;
 };
 
 typedef std::map Scopes_t;
 static Scopes_t s_scopes;
 
-static std::map s_methods;
+static std::map s_methods;
+struct CleanPseudoMethods {
+~CleanPseudoMethods() { for (auto& x : s_methods) delete x.second; }
+} _clean;
 
 int Pseudo_kNothing   = 6;
 int Pseudo_kSomething = 111;
@@ -105,28 +103,28 @@
 offsetof(dummy::CppyyTestData, m_##dmname), false));  \
 /*  get_() */ \
 argtypes.clear(); \
-methods.push_back(Cppyy_PseudoMethodInfo( \
+methods.push_back(new Cppyy_PseudoMethodInfo( \
  "get_"#dmname, argtypes, #dmtype));  \
-s_methods["CppyyTestData::get_"#dmname] = s_method_id++;  \
+s_methods["CppyyTestData::get_"#dmname] = methods.back(); \
 /* & get__r() */  \
-methods.push_back(Cppyy_PseudoMethodInfo( \
+methods.push_back(new Cppyy_PseudoMethodInfo( \
  "get_"#dmname"_r", argtypes, #dmtype"&"));   \
-s_methods["CppyyTestData::get_"#dmname"_r"] = s_method_id++;  \
+s_methods["CppyyTestData::get_"#dmname"_r"] = methods.back(); \
 /* const & get__cr() */   \
-methods.push_back(Cppyy_PseudoMethodInfo( \
+methods.push_back(new Cppyy_PseudoMethodInfo( \
  "get_"#dmname"_cr", argtypes, "const "#dmtype"&"));  \
-s_methods["CppyyTestData::get_"#dmname"_cr"] = s_method_id++; \
+s_methods["CppyyTestData::get_"#dmname"_cr"] = methods.back();\
 /* void set_() */ \
 argtypes.push_back(#dmtype);  \
-methods.push_back(Cppyy_PseudoMethodInfo( \
+methods.push_back(new Cppyy_PseudoMethodInfo( \
  "set_"#dmname, argtypes, "void"));   \
-s_methods["CppyyTestData::set_"#dmname] = s_method_id++;  \
+s_methods["CppyyTestData::set_"#dmname] = methods.back(); \
 argtypes.clear(); \
 /* void set_(const &) */  \
 argtypes.push_back("const "#dmtype"&");   \
-methods.push_back(Cppyy_PseudoMethodInfo( \
+methods.push_back(new Cppyy_PseudoMethodInfo(

[pypy-commit] pypy cppyy-packaging: further support for templated methods and for sfinae

2018-06-08 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94742:c68cd6b1c308
Date: 2018-06-08 22:26 -0700
http://bitbucket.org/pypy/pypy/changeset/c68cd6b1c308/

Log:further support for templated methods and for sfinae

diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -69,7 +69,8 @@
 space = self.space
 cif_descr = self.cif_descr
 size = cif_descr.exchange_size
-raw_string = rffi.cast(rffi.CCHARP, 0)# only ever have one in the 
CAPI
+raw_string1 = rffi.cast(rffi.CCHARP, 0)
+raw_string2 = rffi.cast(rffi.CCHARP, 0)   # have max two in any CAPI
 buffer = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw')
 try:
 for i in range(len(args)):
@@ -91,11 +92,15 @@
 else:# only other use is string
 assert obj.tc == 's'
 n = len(obj._string)
-assert raw_string == rffi.cast(rffi.CCHARP, 0)
-# XXX could use rffi.get_nonmovingbuffer_final_null()
-raw_string = rffi.str2charp(obj._string)
 data = rffi.cast(rffi.CCHARPP, data)
-data[0] = raw_string
+if raw_string1 == rffi.cast(rffi.CCHARP, 0):
+# XXX could use rffi.get_nonmovingbuffer_final_null()
+raw_string1 = rffi.str2charp(obj._string)
+data[0] = raw_string1
+else:
+assert raw_string2 == rffi.cast(rffi.CCHARP, 0)
+raw_string2 = rffi.str2charp(obj._string)
+data[0] = raw_string2
 
 jit_libffi.jit_ffi_call(cif_descr,
 rffi.cast(rffi.VOIDP, funcaddr),
@@ -106,8 +111,10 @@
 # immediate unwrapping, the round-trip is removed
 w_res = self.ctitem.copy_and_convert_to_object(resultdata)
 finally:
-if raw_string != rffi.cast(rffi.CCHARP, 0):
-rffi.free_charp(raw_string)
+if raw_string1 != rffi.cast(rffi.CCHARP, 0):
+rffi.free_charp(raw_string1)
+if raw_string2 != rffi.cast(rffi.CCHARP, 0):
+rffi.free_charp(raw_string2)
 lltype.free(buffer, flavor='raw')
 return w_res
 
@@ -218,6 +225,7 @@
 'get_method'   : ([c_scope, c_index], 
c_method),
 
 'method_name'  : ([c_method], 
c_ccharp),
+'method_full_name' : ([c_method], 
c_ccharp),
 'method_mangled_name'  : ([c_method], 
c_ccharp),
 'method_result_type'   : ([c_method], 
c_ccharp),
 'method_num_args'  : ([c_method], c_int),
@@ -528,6 +536,8 @@
 
 def c_method_name(space, cppmeth):
 return charp2str_free(space, call_capi(space, 'method_name', 
[_ArgH(cppmeth)]))
+def c_method_full_name(space, cppmeth):
+return charp2str_free(space, call_capi(space, 'method_full_name', 
[_ArgH(cppmeth)]))
 def c_method_mangled_name(space, cppmeth):
 return charp2str_free(space, call_capi(space, 'method_mangled_name', 
[_ArgH(cppmeth)]))
 def c_method_result_type(space, cppmeth):
@@ -558,8 +568,8 @@
 args = [_ArgH(cppscope.handle), _ArgL(index)]
 return space.bool_w(call_capi(space, 'method_is_template', args))
 
-def c_get_method_template(space, cppscope, name):
-args = [_ArgH(cppscope.handle), _ArgS(name)]
+def c_get_method_template(space, cppscope, name, proto):
+args = [_ArgH(cppscope.handle), _ArgS(name), _ArgS(proto)]
 return rffi.cast(C_METHOD, space.uint_w(call_capi(space, 
'get_method_template', args)))
 def c_get_global_operator(space, nss, lc, rc, op):
 if nss is not None:
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
@@ -492,8 +492,8 @@
 def _unwrap_object(self, space, w_obj):
 from pypy.module._cppyy.interp_cppyy import W_CPPInstance
 if isinstance(w_obj, W_CPPInstance):
-from pypy.module._cppyy.interp_cppyy import 
INSTANCE_FLAGS_IS_R_VALUE
-if w_obj.flags & INSTANCE_FLAGS_IS_R_VALUE:
+from pypy.module._cppyy.interp_cppyy import 
INSTANCE_FLAGS_IS_RVALUE
+if w_obj.flags & INSTANCE_FLAGS_IS_RVALUE:
 # reject moves as all are explicit
 raise ValueError("lvalue expected")
 if capi.c_is_subtype(space, w_obj.clsdecl, self.clsdecl):
@@ -522,11 +522,18 @@
 class InstanceMoveConverter(InstanceRefConverter):
 def _unwrap_object(self, space, w_obj):
 # moving is same as by-ref, but have to check that move is allowed
-from pypy.mo

[pypy-commit] pypy cppyy-packaging: method template improvements

2018-06-08 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94741:068d5604f6e9
Date: 2018-06-07 22:35 -0700
http://bitbucket.org/pypy/pypy/changeset/068d5604f6e9/

Log:method template improvements

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
@@ -677,7 +677,7 @@
  W_CPPOverload.__init__(self, space, declaring_scope, functions, flags)
  self.name = name
  self.overloads = {}
- self.master = None
+ self.master = self
 
 @unwrap_spec(args_w='args_w')
 def descr_get(self, w_cppinstance, args_w):
@@ -685,15 +685,36 @@
 return self  # unbound
 cppol = W_CPPTemplateOverload(self.space, self.name, self.scope, 
self.functions, self.flags)
 cppol.w_this = w_cppinstance
-cppol.master = self
+cppol.master = self.master
 return cppol # bound
 
 @unwrap_spec(args_w='args_w')
+def call(self, args_w):
+# direct call means attempt to deduce types ourselves
+# first, try to match with existing methods
+for cppol in self.master.overloads.values():
+try:
+cppol.descr_get(self.w_this, []).call(args_w)
+except Exception as e:
+pass# completely ignore for now; have to see whether 
errors become confusing
+
+# if all failed, then try to deduce type
+types_w = [self.space.type(obj_w) for obj_w in args_w]
+method = self.getitem(types_w)
+return method.call(args_w)
+
+@unwrap_spec(args_w='args_w')
 def getitem(self, args_w):
 space = self.space
+
+if space.isinstance_w(args_w[0], space.w_tuple):
+w_args = args_w[0]
+else:
+w_args = space.newtuple(args_w)
+
 tmpl_args = ''
-for i in range(len(args_w)):
-w_obj = args_w[i]
+for i in range(space.len_w(w_args)):
+w_obj = space.getitem(w_args, space.newint(i))
 if space.isinstance_w(w_obj, space.w_text):
 s = space.text_w(w_obj)  # string describing type
 elif space.isinstance_w(w_obj, space.w_type):
@@ -712,22 +733,23 @@
 fullname = self.name+'<'+tmpl_args+'>'
 
 # find/instantiate new callable function
-master = self.master
-if not master:
-master = self
 try:
-return master.overloads[fullname].descr_get(self.w_this, [])
+return self.master.overloads[fullname].descr_get(self.w_this, [])
 except KeyError:
 pass
 
 cppmeth = capi.c_get_method_template(space, self.scope, fullname)
+if not cppmeth:
+raise oefmt(self.space.w_AttributeError,
+"scope '%s' has no function %s", self.scope.name, fullname)
+
 funcs = []
 ftype = self.scope._make_cppfunction(fullname, cppmeth, funcs)
 if ftype & FUNCTION_IS_STATIC:
 cppol = W_CPPStaticOverload(space, self.scope, funcs[:], 
self.flags)
 else:
 cppol = W_CPPOverload(space, self.scope, funcs[:], self.flags)
-master.overloads[fullname] = cppol
+self.master.overloads[fullname] = cppol
 return cppol.descr_get(self.w_this, [])
 
 def __repr__(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: further template function use cases

2018-06-09 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94746:6e179cce7824
Date: 2018-06-09 16:42 -0700
http://bitbucket.org/pypy/pypy/changeset/6e179cce7824/

Log:further template function use cases

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
@@ -162,10 +162,11 @@
 #   - overloads: user-facing collections of overloaded functions
 #   - wrappers: internal holders of the individual C++ methods
 #
-#  W_CPPOverload: instance methods (base class)
-#  W_CPPConstructorOverload:  constructors
-#  W_CPPStaticOverload:   free and static functions
-#  W_CPPTemplateOverload: templated methods/functions
+#  W_CPPOverload: instance methods (base class)
+#  W_CPPConstructorOverload:  constructors
+#  W_CPPStaticOverload:   free and static functions
+#  W_CPPTemplateOverload: templated methods
+#  W_CPPTemplateStaticOveload:templated free and static functions
 #
 #  CPPMethod: a single function or method (base class)
 #  CPPSetItem:specialization for Python's __setitem__
@@ -666,18 +667,10 @@
 )
 
 
-class W_CPPTemplateOverload(W_CPPOverload):
-"""App-level dispatcher to allow both lookup/instantiation of templated 
methods and
-dispatch among overloads between templated and non-templated overloads."""
+class TemplateOverloadMixin(object):
+"""Mixin to instantiate templated methods/functions."""
 
-_attrs_ = ['name', 'overloads', 'master']
-_immutable_fields_ = ['name']
-
-def __init__(self, space, name, declaring_scope, functions, flags = 
OVERLOAD_FLAGS_USE_FFI):
- W_CPPOverload.__init__(self, space, declaring_scope, functions, flags)
- self.name = name
- self.overloads = {}
- self.master = self
+_mixin_ = True
 
 def construct_template_args(self, w_args):
 space = self.space
@@ -719,19 +712,8 @@
 cppol = W_CPPOverload(space, self.scope, funcs[:], self.flags)
 return cppol
 
-@unwrap_spec(args_w='args_w')
-def descr_get(self, w_cppinstance, args_w):
-if self.space.is_w(w_cppinstance, self.space.w_None):
-return self  # unbound
-cppol = W_CPPTemplateOverload(self.space, self.name, self.scope, 
self.functions, self.flags)
-cppol.w_this = w_cppinstance
-cppol.master = self.master
-return cppol # bound
-
-@unwrap_spec(args_w='args_w')
-def call(self, args_w):
-# direct call means attempt to deduce types ourselves
-# first, try to match with existing methods
+def instantiation_from_args(self, args_w):
+# try to match with run-time instantiations
 for cppol in self.master.overloads.values():
 try:
 cppol.descr_get(self.w_this, []).call(args_w)
@@ -772,6 +754,42 @@
 
 return method.descr_get(self.w_this, [])
 
+
+class W_CPPTemplateOverload(W_CPPOverload, TemplateOverloadMixin):
+"""App-level dispatcher to allow both lookup/instantiation of templated 
methods and
+dispatch among overloads between templated and non-templated method."""
+
+_attrs_ = ['name', 'overloads', 'master']
+_immutable_fields_ = ['name']
+
+def __init__(self, space, name, declaring_scope, functions, flags = 
OVERLOAD_FLAGS_USE_FFI):
+ W_CPPOverload.__init__(self, space, declaring_scope, functions, flags)
+ self.name = name
+ self.overloads = {}
+ self.master = self
+
+@unwrap_spec(args_w='args_w')
+def descr_get(self, w_cppinstance, args_w):
+# like W_CPPOverload, but returns W_CPPTemplateOverload
+if self.space.is_w(w_cppinstance, self.space.w_None):
+return self  # unbound, so no new instance needed
+cppol = W_CPPTemplateOverload(self.space, self.name, self.scope, 
self.functions, self.flags)
+cppol.w_this = w_cppinstance
+return cppol # bound
+
+@unwrap_spec(args_w='args_w')
+def call(self, args_w):
+# direct call: either pick non-templated overload or attempt to deduce
+# the template instantiation from the argument types
+
+# try existing overloads or compile-time instantiations
+try:
+return W_CPPOverload.call(self, args_w)
+except Exception:
+pass
+
+return self.instantiation_from_args(args_w)
+
 def __repr__(self):
 return "W_CPPTemplateOverload(%s)" % [f.prototype() for f in 
self.functions]
 
@@ -784,6 +802,57 @@
 __doc__ = GetSetProperty(W_CPPTemplateOverload.fget_doc)
 )
 
+class W_CPPTemplateStaticOverload(W_CPPStaticOverload, TemplateOverloadMixin):
+"""App-level dispatcher to allow both lookup/instantiation of templated 
methods and
+dispatch among overloads between templated and non-templated method."""
+
+_attrs_ = ['name', 'overloads', 'master']
+_immutable_fields_ = ['nam

[pypy-commit] pypy cppyy-packaging: translator fixes

2018-06-09 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94748:fc284f4dd3f0
Date: 2018-06-09 20:17 -0700
http://bitbucket.org/pypy/pypy/changeset/fc284f4dd3f0/

Log:translator fixes

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
@@ -712,7 +712,7 @@
 cppol = W_CPPOverload(space, self.scope, funcs[:], self.flags)
 return cppol
 
-def instantiation_from_args(self, args_w):
+def instantiation_from_args(self, name, args_w):
 # try to match with run-time instantiations
 for cppol in self.master.overloads.values():
 try:
@@ -723,7 +723,7 @@
 # if all failed, then try to deduce from argument types
 w_types = self.space.newtuple([self.space.type(obj_w) for obj_w in 
args_w])
 proto = self.construct_template_args(w_types)
-method = self.find_method_template(self.name, proto)
+method = self.find_method_template(name, proto)
 
 # only cache result if the name retains the full template
 if len(method.functions) == 1:
@@ -733,8 +733,7 @@
 
 return method.descr_get(self.w_this, []).call(args_w)
 
-@unwrap_spec(args_w='args_w')
-def getitem(self, args_w):
+def getitem_impl(self, name, args_w):
 space = self.space
 
 if space.isinstance_w(args_w[0], space.w_tuple):
@@ -743,7 +742,7 @@
 w_args = space.newtuple(args_w)
 
 tmpl_args = self.construct_template_args(w_args)
-fullname = self.name+'<'+tmpl_args+'>'
+fullname = name+'<'+tmpl_args+'>'
 try:
 method = self.master.overloads[fullname]
 except KeyError:
@@ -788,7 +787,11 @@
 except Exception:
 pass
 
-return self.instantiation_from_args(args_w)
+return self.instantiation_from_args(self.name, args_w)
+
+@unwrap_spec(args_w='args_w')
+def getitem(self, args_w):
+return self.getitem_impl(self.name, args_w)
 
 def __repr__(self):
 return "W_CPPTemplateOverload(%s)" % [f.prototype() for f in 
self.functions]
@@ -839,7 +842,11 @@
 pass
 
 # try new instantiation
-return self.instantiation_from_args(args_w)
+return self.instantiation_from_args(self.name, args_w)
+
+@unwrap_spec(args_w='args_w')
+def getitem(self, args_w):
+return self.getitem_impl(self.name, args_w)
 
 def __repr__(self):
 return "W_CPPTemplateStaticOverload(%s)" % [f.prototype() for f in 
self.functions]
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: more template tesst

2018-06-09 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94747:c1d70477c996
Date: 2018-06-09 17:44 -0700
http://bitbucket.org/pypy/pypy/changeset/c1d70477c996/

Log:more template tesst

diff --git a/pypy/module/_cppyy/test/test_templates.py 
b/pypy/module/_cppyy/test/test_templates.py
--- a/pypy/module/_cppyy/test/test_templates.py
+++ b/pypy/module/_cppyy/test/test_templates.py
@@ -89,6 +89,13 @@
 #_cppyy.gbl.SomeNS.tuplify(s, 1, 4., "aap")
 #assert s.str() == '(1, 4, aap)
 
+_cppyy.gbl.gInterpreter.Declare("""
+template
+int test04_variadic_func() { return sizeof...(myTypes); }
+""")
+
+assert _cppyy.gbl.test04_variadic_func['int', 'double', 'void*']() == 3
+
 def test05_variadic_overload(self):
 """Call an overloaded variadic function"""
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: merge default into branch

2018-06-09 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94749:d72f3ca3c3fd
Date: 2018-06-09 21:45 -0700
http://bitbucket.org/pypy/pypy/changeset/d72f3ca3c3fd/

Log:merge default into branch

diff too long, truncating to 2000 out of 12609 lines

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -33,7 +33,12 @@
 050d84dd78997f021acf0e133934275d63547cc0 release-pypy2.7-v5.4.1
 050d84dd78997f021acf0e133934275d63547cc0 release-pypy2.7-v5.4.1
 0e2d9a73f5a1818d0245d75daccdbe21b2d5c3ef release-pypy2.7-v5.4.1
+4909c06daf41ce88f87dc01c57959cadad4df4a8 RevDB-pypy2.7-v5.4.1
+4909c06daf41ce88f87dc01c57959cadad4df4a8 RevDB-pypy2.7-v5.4.1
+d7724c0a5700b895a47de44074cdf5fd659a988f RevDB-pypy2.7-v5.4.1
 aff251e543859ce4508159dd9f1a82a2f553de00 release-pypy2.7-v5.6.0
+e90317857d27917bf840caf675832292ee070510 RevDB-pypy2.7-v5.6.1
+a24d6c7000c8099c73d3660857f7e3cee5ac045c RevDB-pypy2.7-v5.6.2
 fa3249d55d15b9829e1be69cdf45b5a44cec902d release-pypy2.7-v5.7.0
 b16a4363e930f6401bceb499b9520955504c6cb0 release-pypy3.5-v5.7.0
 1aa2d8e03cdfab54b7121e93fda7e98ea88a30bf release-pypy2.7-v5.7.1
diff --git a/lib-python/2.7/opcode.py b/lib-python/2.7/opcode.py
--- a/lib-python/2.7/opcode.py
+++ b/lib-python/2.7/opcode.py
@@ -194,5 +194,6 @@
 def_op('CALL_METHOD', 202)# #args not including 'self'
 def_op('BUILD_LIST_FROM_ARG', 203)
 jrel_op('JUMP_IF_NOT_DEBUG', 204) # jump over assert statements
+def_op('LOAD_REVDB_VAR', 205) # reverse debugger (syntax example: $5)
 
 del def_op, name_op, jrel_op, jabs_op
diff --git a/lib_pypy/grp.py b/lib_pypy/grp.py
--- a/lib_pypy/grp.py
+++ b/lib_pypy/grp.py
@@ -4,6 +4,8 @@
 
 from _pwdgrp_cffi import ffi, lib
 import _structseq
+import thread
+_lock = thread.allocate_lock()
 
 try: from __pypy__ import builtinify
 except ImportError: builtinify = lambda f: f
@@ -33,32 +35,35 @@
 
 @builtinify
 def getgrgid(gid):
-res = lib.getgrgid(gid)
-if not res:
-# XXX maybe check error eventually
-raise KeyError(gid)
-return _group_from_gstruct(res)
+with _lock:
+res = lib.getgrgid(gid)
+if not res:
+# XXX maybe check error eventually
+raise KeyError(gid)
+return _group_from_gstruct(res)
 
 @builtinify
 def getgrnam(name):
 if not isinstance(name, basestring):
 raise TypeError("expected string")
 name = str(name)
-res = lib.getgrnam(name)
-if not res:
-raise KeyError("'getgrnam(): name not found: %s'" % name)
-return _group_from_gstruct(res)
+with _lock:
+res = lib.getgrnam(name)
+if not res:
+raise KeyError("'getgrnam(): name not found: %s'" % name)
+return _group_from_gstruct(res)
 
 @builtinify
 def getgrall():
-lib.setgrent()
 lst = []
-while 1:
-p = lib.getgrent()
-if not p:
-break
-lst.append(_group_from_gstruct(p))
-lib.endgrent()
+with _lock:
+lib.setgrent()
+while 1:
+p = lib.getgrent()
+if not p:
+break
+lst.append(_group_from_gstruct(p))
+lib.endgrent()
 return lst
 
 __all__ = ('struct_group', 'getgrgid', 'getgrnam', 'getgrall')
diff --git a/lib_pypy/pwd.py b/lib_pypy/pwd.py
--- a/lib_pypy/pwd.py
+++ b/lib_pypy/pwd.py
@@ -12,6 +12,8 @@
 
 from _pwdgrp_cffi import ffi, lib
 import _structseq
+import thread
+_lock = thread.allocate_lock()
 
 try: from __pypy__ import builtinify
 except ImportError: builtinify = lambda f: f
@@ -55,10 +57,11 @@
 Return the password database entry for the given numeric user ID.
 See pwd.__doc__ for more on password database entries.
 """
-pw = lib.getpwuid(uid)
-if not pw:
-raise KeyError("getpwuid(): uid not found: %s" % uid)
-return _mkpwent(pw)
+with _lock:
+pw = lib.getpwuid(uid)
+if not pw:
+raise KeyError("getpwuid(): uid not found: %s" % uid)
+return _mkpwent(pw)
 
 @builtinify
 def getpwnam(name):
@@ -71,10 +74,11 @@
 if not isinstance(name, basestring):
 raise TypeError("expected string")
 name = str(name)
-pw = lib.getpwnam(name)
-if not pw:
-raise KeyError("getpwname(): name not found: %s" % name)
-return _mkpwent(pw)
+with _lock:
+pw = lib.getpwnam(name)
+if not pw:
+raise KeyError("getpwname(): name not found: %s" % name)
+return _mkpwent(pw)
 
 @builtinify
 def getpwall():
@@ -84,13 +88,14 @@
 See pwd.__doc__ for more on password database entries.
 """
 users = []
-lib.setpwent()
-while True:
-pw = lib.getpwent()
-if not pw:
-break
-users.append(_mkpwent(pw))
-lib.endpwent()
+with _lock:
+lib.setpwent()
+while True:
+pw = lib.getpwent()
+if not pw:
+break
+users.append(_mkpwent(pw))
+lib.endpwent()
 return users
 
 __all__ = ('struct_passwd', 'g

[pypy-commit] pypy cppyy-packaging: py3 fixes

2018-06-10 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94750:749cd13269b0
Date: 2018-06-10 16:10 -0700
http://bitbucket.org/pypy/pypy/changeset/749cd13269b0/

Log:py3 fixes

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
@@ -14,7 +14,7 @@
 '_set_function_generator': 'interp_cppyy.set_function_generator',
 '_register_class': 'interp_cppyy.register_class',
 '_get_nullptr'   : 'interp_cppyy.get_nullptr',
-'CPPInstanceBase': 'interp_cppyy.W_CPPInstance',
+'CPPInstance': 'interp_cppyy.W_CPPInstance',
 'addressof'  : 'interp_cppyy.addressof',
 '_bind_object'   : 'interp_cppyy._bind_object',
 'bind_object': 'interp_cppyy.bind_object',
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
@@ -391,7 +391,7 @@
 def from_memory(self, space, w_obj, w_pycppclass, offset):
 address = self._get_raw_address(space, w_obj, offset)
 charpptr = rffi.cast(rffi.CCHARPP, address)
-return space.newbytes(rffi.charp2str(charpptr[0]))
+return space.newtext(rffi.charp2str(charpptr[0]))
 
 def free_argument(self, space, arg, call_local):
 lltype.free(rffi.cast(rffi.CCHARPP, arg)[0], flavor='raw')
@@ -408,7 +408,7 @@
 strsize = self.size
 if charpptr[self.size-1] == '\0':
 strsize = self.size-1  # rffi will add \0 back
-return space.newbytes(rffi.charpsize2str(charpptr, strsize))
+return space.newtext(rffi.charpsize2str(charpptr, strsize))
 
 
 class VoidPtrConverter(TypeConverter):
diff --git a/pypy/module/_cppyy/ffitypes.py b/pypy/module/_cppyy/ffitypes.py
--- a/pypy/module/_cppyy/ffitypes.py
+++ b/pypy/module/_cppyy/ffitypes.py
@@ -79,10 +79,13 @@
 
 value = rffi.cast(rffi.CHAR, space.c_int_w(w_value))
 else:
-value = space.text_w(w_value)
+if space.isinstance_w(w_value, space.w_text):
+value = space.text_w(w_value)
+else:
+value = space.bytes_w(w_value)
 if len(value) != 1:
 raise oefmt(space.w_ValueError,
-"char expected, got string of size %d", len(value))
+"char expected, got string of size %d", len(value))
 
 value = rffi.cast(rffi.CHAR, value[0])
 return value # turn it into a "char" to the annotator
@@ -110,10 +113,13 @@
 
 value = rffi.cast(rffi.CHAR, space.c_int_w(w_value))
 else:
-value = space.text_w(w_value)
+if space.isinstance_w(w_value, space.w_text):
+value = space.text_w(w_value)
+else:
+value = space.bytes_w(w_value)
 if len(value) != 1:
 raise oefmt(space.w_ValueError,
-"char expected, got string of size %d", len(value))
+"usigned char expected, got string of size %d", 
len(value))
 
 value = rffi.cast(rffi.CHAR, value[0])
 return value # turn it into a "char" to the annotator
diff --git a/pypy/module/_cppyy/helper.py b/pypy/module/_cppyy/helper.py
--- a/pypy/module/_cppyy/helper.py
+++ b/pypy/module/_cppyy/helper.py
@@ -1,3 +1,4 @@
+import sys
 from rpython.rlib import rstring
 
 
@@ -116,6 +117,17 @@
 # TODO: perhaps absorb or "pythonify" these operators?
 return cppname
 
+if sys.hexversion < 0x300:
+CPPYY__div__  = "__div__"
+CPPYY__idiv__ = "__idiv__"
+CPPYY__long__ = "__long__"
+CPPYY__bool__ = "__nonzero__"
+else:
+CPPYY__div__  = "__truediv__"
+CPPYY__idiv__ = "__itruediv__"
+CPPYY__long__ = "__int__"
+CPPYY__bool__ = "__bool__"
+
 # _operator_mappings["[]"]  = "__setitem__"  # depends on return type
 # _operator_mappings["+"]   = "__add__"  # depends on # of args (see 
__pos__)
 # _operator_mappings["-"]   = "__sub__"  # id. (eq. __neg__)
@@ -123,7 +135,7 @@
 
 # _operator_mappings["[]"]  = "__getitem__"  # depends on return type
 _operator_mappings["()"]  = "__call__"
-_operator_mappings["/"]   = "__div__"# __truediv__ in p3
+_operator_mappings["/"]   = CPPYY__div__
 _operator_mappings["%"]   = "__mod__"
 _operator_mappings["**"]  = "__pow__"# not C++
 _operator_mappings["<<"]  = "__lshift__"
@@ -136,7 +148,7 @@
 _operator_mappings["+="]  = "__iadd__"
 _operator_mappings["-="]  = "__isub__"
 _operator_mappings["*="]  = "__imul__"
-_operator_mappings["/="]  = "__idiv__"   # __itruediv__ in p3
+_operator_mappings["/="]  = CPPYY__idiv__
 _operator_mappings["%="]  = "__imod__"
 _operator_mappings["**="] = "__ipow__"
 _operator_mappings["<<="] = "__ilshift__"
@@ -154,7 +166,7 @@
 # the following type mappings are 

[pypy-commit] pypy default: Upgrade to backend 1.1.0, improved handling of templated methods and

2018-06-10 Thread wlav
Author: Wim Lavrijsen 
Branch: 
Changeset: r94751:b505aee6a14e
Date: 2018-06-10 16:52 -0700
http://bitbucket.org/pypy/pypy/changeset/b505aee6a14e/

Log:Upgrade to backend 1.1.0, improved handling of templated methods and
functions (in particular automatic deduction of types), improved
pythonization interface, and a range of compatibility fixes for
Python3

diff too long, truncating to 2000 out of 4635 lines

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -7,9 +7,9 @@
 
 .. branch: cppyy-packaging
 
-Upgrade to backend 0.6.0, support exception handling from wrapped functions,
-update enum handling, const correctness for data members and associated tests,
-support anonymous enums, support for function pointer arguments
+Upgrade to backend 1.1.0, improved handling of templated methods and
+functions (in particular automatic deduction of types), improved pythonization
+interface, and a range of compatibility fixes for Python3
 
 .. branch: socket_default_timeout_blockingness
 
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
@@ -1,7 +1,7 @@
 from pypy.interpreter.mixedmodule import MixedModule
 
 class Module(MixedModule):
-"This module brigdes the cppyy frontend with its backend, through PyPy.\n\
+"This module bridges the cppyy frontend with its backend, through PyPy.\n\
 See http://cppyy.readthedocs.io/en/latest for full details."
 
 interpleveldefs = {
@@ -14,17 +14,19 @@
 '_set_function_generator': 'interp_cppyy.set_function_generator',
 '_register_class': 'interp_cppyy.register_class',
 '_get_nullptr'   : 'interp_cppyy.get_nullptr',
-'CPPInstanceBase': 'interp_cppyy.W_CPPInstance',
+'CPPInstance': 'interp_cppyy.W_CPPInstance',
 'addressof'  : 'interp_cppyy.addressof',
 '_bind_object'   : 'interp_cppyy._bind_object',
 'bind_object': 'interp_cppyy.bind_object',
 'move'   : 'interp_cppyy.move',
+'_pin_type'  : 'interp_cppyy._pin_type',
 }
 
 appleveldefs = {
 '_post_import_startup'   : 'pythonify._post_import_startup',
+'Template'   : 'pythonify.CPPTemplate',
 'add_pythonization'  : 'pythonify.add_pythonization',
-'Template'   : 'pythonify.CPPTemplate',
+'remove_pythonization'   : 'pythonify.remove_pythonization',
 }
 
 def __init__(self, space, *args):
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
@@ -11,6 +11,3 @@
 assert lltype.typeOf(ptr) == C_OBJECT
 address = rffi.cast(rffi.CCHARP, ptr)
 return rffi.cast(C_OBJECT, lltype.direct_ptradd(address, offset))
-
-def exchange_address(ptr, cif_descr, index):
-return rffi.ptradd(ptr, cif_descr.exchange_args[index])
diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -69,7 +69,8 @@
 space = self.space
 cif_descr = self.cif_descr
 size = cif_descr.exchange_size
-raw_string = rffi.cast(rffi.CCHARP, 0)# only ever have one in the 
CAPI
+raw_string1 = rffi.cast(rffi.CCHARP, 0)
+raw_string2 = rffi.cast(rffi.CCHARP, 0)   # have max two in any CAPI
 buffer = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw')
 try:
 for i in range(len(args)):
@@ -88,14 +89,18 @@
 assert obj._voidp != rffi.cast(rffi.VOIDP, 0)
 data = rffi.cast(rffi.VOIDPP, data)
 data[0] = obj._voidp
-else:# only other use is sring
+else:# only other use is string
 assert obj.tc == 's'
 n = len(obj._string)
-assert raw_string == rffi.cast(rffi.CCHARP, 0)
-# XXX could use rffi.get_nonmovingbuffer_final_null()
-raw_string = rffi.str2charp(obj._string)
 data = rffi.cast(rffi.CCHARPP, data)
-data[0] = raw_string
+if raw_string1 == rffi.cast(rffi.CCHARP, 0):
+# XXX could use rffi.get_nonmovingbuffer_final_null()
+raw_string1 = rffi.str2charp(obj._string)
+data[0] = raw_string1
+else:
+assert raw_string2 == rffi.cast(rffi.CCHARP, 0)
+raw_string2 = rffi.str2charp(obj._string)
+data[0] = raw_string2
 
 jit_libffi.jit_ffi_call(cif_descr,
 

[pypy-commit] pypy cppyy-packaging: call reserve before push_backing a python container

2018-06-15 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94765:a94f77177791
Date: 2018-06-12 20:29 -0700
http://bitbucket.org/pypy/pypy/changeset/a94f77177791/

Log:call reserve before push_backing a python container

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
@@ -408,10 +408,16 @@
 
 # map push_back -> __iadd__ (generally true for STL)
 if 'push_back' in pyclass.__dict__ and not '__iadd__' in pyclass.__dict__:
-def __iadd__(self, ll):
-[self.push_back(x) for x in ll]
-return self
-pyclass.__iadd__ = __iadd__
+if 'reserve' in pyclass.__dict__:
+def iadd(self, ll):
+self.reserve(len(ll))
+for x in ll: self.push_back(x)
+return self
+else:
+def iadd(self, ll):
+for x in ll: self.push_back(x)
+return self
+pyclass.__iadd__ = iadd
 
 # map begin()/end() protocol to iter protocol on STL(-like) classes, but
 # not on vector, which is pythonized in the capi (interp-level; there is
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: naming consistency with CPython/cppyy

2018-06-15 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94766:ebebd445c6d1
Date: 2018-06-14 13:56 -0700
http://bitbucket.org/pypy/pypy/changeset/ebebd445c6d1/

Log:naming consistency with CPython/cppyy

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
@@ -706,7 +706,7 @@
 "no overload found matching %s", self.signature)
 
 
-class SmartPointerConverter(TypeConverter):
+class SmartPtrConverter(TypeConverter):
 _immutable_fields = ['typecode', 'smartdecl', 'rawdecl', 'deref']
 typecode= 'V'
 
@@ -753,7 +753,7 @@
 return interp_cppyy.wrap_cppinstance(space, address,
 self.rawdecl, smartdecl=self.smartdecl, deref=self.deref, 
do_cast=False)
 
-class SmartPointerPtrConverter(SmartPointerConverter):
+class SmartPtrPtrConverter(SmartPtrConverter):
 typecode= 'o'
 
 def from_memory(self, space, w_obj, w_pycppclass, offset):
@@ -763,7 +763,7 @@
 self._is_abstract(space)
 
 
-class SmartPointerRefConverter(SmartPointerPtrConverter):
+class SmartPtrRefConverter(SmartPtrPtrConverter):
 typecode= 'V'
 
 
@@ -823,11 +823,11 @@
 check_smart = capi.c_smartptr_info(space, clean_name)
 if check_smart[0]:
 if compound == '':
-return SmartPointerConverter(space, clsdecl, check_smart[1], 
check_smart[2])
+return SmartPtrConverter(space, clsdecl, check_smart[1], 
check_smart[2])
 elif compound == '*':
-return SmartPointerPtrConverter(space, clsdecl, 
check_smart[1], check_smart[2])
+return SmartPtrPtrConverter(space, clsdecl, check_smart[1], 
check_smart[2])
 elif compound == '&':
-return SmartPointerRefConverter(space, clsdecl, 
check_smart[1], check_smart[2])
+return SmartPtrRefConverter(space, clsdecl, check_smart[1], 
check_smart[2])
 # fall through: can still return smart pointer in non-smart way
 
 # type check for the benefit of the annotator
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: improved template instantiation selection

2018-06-15 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94767:bda138593c45
Date: 2018-06-14 13:57 -0700
http://bitbucket.org/pypy/pypy/changeset/bda138593c45/

Log:improved template instantiation selection

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
@@ -672,24 +672,33 @@
 
 _mixin_ = True
 
-def construct_template_args(self, w_args):
+def construct_template_args(self, w_tpArgs, args_w = None):
 space = self.space
 tmpl_args = ''
-for i in range(space.len_w(w_args)):
-w_obj = space.getitem(w_args, space.newint(i))
-if space.isinstance_w(w_obj, space.w_text):
-s = space.text_w(w_obj)  # string describing type
-elif space.isinstance_w(w_obj, space.w_type):
+for i in range(space.len_w(w_tpArgs)):
+w_tp = space.getitem(w_tpArgs, space.newint(i))
+if space.isinstance_w(w_tp, space.w_text):
+s = space.text_w(w_tp)  # string describing type
+elif space.isinstance_w(w_tp, space.w_type):
 try:
 # cppyy bound types
-name = space.getattr(w_obj, space.newtext('__cppname__'))
+s = space.text_w(space.getattr(w_tp, 
space.newtext('__cppname__')))
+if args_w:
+# try to specialize the type match for the given object
+cppinstance = self.space.interp_w(W_CPPInstance, 
args_w[i])
+if cppinstance.flags & INSTANCE_FLAGS_IS_RVALUE:
+sugar = "&&"
+elif cppinstance.flags & INSTANCE_FLAGS_IS_REF:
+sugar = "*"
+else:
+sugar = "&"
+s += sugar
 except OperationError:
 # generic python types
-name = space.getattr(w_obj, space.newtext('__name__'))
-s = space.text_w(name)
+s = space.text_w(space.getattr(w_tp, 
space.newtext('__name__')))
 else:
 # builtin types etc.
-s = space.text_w(space.str(w_obj))
+s = space.text_w(space.str(w_tp))
 # map python types -> C++ types
 if s == 'str': s = 'std::string'
 if i != 0: tmpl_args += ', '
@@ -722,7 +731,7 @@
 
 # if all failed, then try to deduce from argument types
 w_types = self.space.newtuple([self.space.type(obj_w) for obj_w in 
args_w])
-proto = self.construct_template_args(w_types)
+proto = self.construct_template_args(w_types, args_w)
 method = self.find_method_template(name, proto)
 
 # only cache result if the name retains the full template
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: naming consistency with CPython/cppyy

2018-06-15 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94768:3d1957fa3897
Date: 2018-06-15 23:24 -0700
http://bitbucket.org/pypy/pypy/changeset/3d1957fa3897/

Log:naming consistency with CPython/cppyy

diff --git a/pypy/module/_cppyy/executor.py b/pypy/module/_cppyy/executor.py
--- a/pypy/module/_cppyy/executor.py
+++ b/pypy/module/_cppyy/executor.py
@@ -26,7 +26,7 @@
 
 NULL = lltype.nullptr(jit_libffi.FFI_TYPE_P.TO)
 
-class FunctionExecutor(object):
+class Executor(object):
 def __init__(self, space, extra):
 pass
 
@@ -43,7 +43,7 @@
 raise FastCallNotPossible
 
 
-class PtrTypeExecutor(FunctionExecutor):
+class PtrTypeExecutor(Executor):
 _immutable_fields_ = ['typecode']
 typecode = 'P'
 
@@ -63,7 +63,7 @@
 return W_ArrayInstance(space, shape, sys.maxint/shape.size, ptrval)
 
 
-class VoidExecutor(FunctionExecutor):
+class VoidExecutor(Executor):
 def cffi_type(self, space):
 state = space.fromcache(ffitypes.State)
 return state.c_void
@@ -96,7 +96,7 @@
 _mixin_ = True
 
 def __init__(self, space, extra):
-FunctionExecutor.__init__(self, space, extra)
+Executor.__init__(self, space, extra)
 self.do_assign = False
 self.item = rffi.cast(self.c_type, 0)
 
@@ -124,7 +124,7 @@
 rffi.cast(self.c_ptrtype, rffi.cast(rffi.VOIDPP, result)[0]))
 
 
-class CStringExecutor(FunctionExecutor):
+class CStringExecutor(Executor):
 def execute(self, space, cppmethod, cppthis, num_args, args):
 lresult = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
 ccpresult = rffi.cast(rffi.CCHARP, lresult)
@@ -134,7 +134,7 @@
 return space.newbytes(result)
 
 
-class ConstructorExecutor(FunctionExecutor):
+class ConstructorExecutor(Executor):
 def execute(self, space, cppmethod, cpptype, num_args, args):
 from pypy.module._cppyy import interp_cppyy
 newthis = capi.c_constructor(space, cppmethod, cpptype, num_args, args)
@@ -142,12 +142,12 @@
 return space.newlong(rffi.cast(rffi.LONG, newthis))   # really want 
ptrdiff_t here
 
 
-class InstanceExecutor(FunctionExecutor):
+class InstanceExecutor(Executor):
 # For return of a C++ instance by pointer: MyClass* func()
 _immutable_fields_ = ['clsdecl']
 
 def __init__(self, space, clsdecl):
-FunctionExecutor.__init__(self, space, clsdecl)
+Executor.__init__(self, space, clsdecl)
 self.clsdecl = clsdecl
 
 def _wrap_result(self, space, obj):
@@ -338,7 +338,7 @@
 return _executors['void*'](space, None)  # allow at least passing of 
the pointer
 
 # currently used until proper lazy instantiation available in interp_cppyy
-return FunctionExecutor(space, None)
+return Executor(space, None)
  
 
 _executors["void"]= VoidExecutor
@@ -374,10 +374,10 @@
 )
 
 for c_type, stub, names in type_info:
-class BasicExecutor(ffitypes.typeid(c_type), NumericExecutorMixin, 
FunctionExecutor):
+class BasicExecutor(ffitypes.typeid(c_type), NumericExecutorMixin, 
Executor):
 _immutable_ = True
 c_stubcall  = staticmethod(stub)
-class BasicRefExecutor(ffitypes.typeid(c_type), 
NumericRefExecutorMixin, FunctionExecutor):
+class BasicRefExecutor(ffitypes.typeid(c_type), 
NumericRefExecutorMixin, Executor):
 def cffi_type(self, space):
 state = space.fromcache(ffitypes.State)
 return state.c_voidp
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: improved handling of templated methods

2018-06-15 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94769:cb6f0a7dbc3a
Date: 2018-06-15 23:24 -0700
http://bitbucket.org/pypy/pypy/changeset/cb6f0a7dbc3a/

Log:improved handling of templated methods

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
@@ -804,6 +804,12 @@
 compound = helper.compound(name)
 clean_name = capi.c_resolve_name(space, helper.clean_type(name))
 try:
+return _converters[clean_name+compound](space, default)
+except KeyError:
+pass
+
+# arrays
+try:
 # array_index may be negative to indicate no size or no size found
 array_size = helper.array_size(_name) # uses original arg
 # TODO: using clean_name here drops const (e.g. const char[] will
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
@@ -721,11 +721,11 @@
 cppol = W_CPPOverload(space, self.scope, funcs[:], self.flags)
 return cppol
 
-def instantiation_from_args(self, name, args_w):
+def instantiate_and_call(self, name, args_w):
 # try to match with run-time instantiations
 for cppol in self.master.overloads.values():
 try:
-cppol.descr_get(self.w_this, []).call(args_w)
+return cppol.descr_get(self.w_this, []).call(args_w)
 except Exception:
 pass# completely ignore for now; have to see whether 
errors become confusing
 
@@ -735,9 +735,17 @@
 method = self.find_method_template(name, proto)
 
 # only cache result if the name retains the full template
-if len(method.functions) == 1:
-fullname = capi.c_method_full_name(self.space, 
method.functions[0].cppmethod)
-if 0 <= fullname.rfind('>'):
+fullname = capi.c_method_full_name(self.space, 
method.functions[0].cppmethod)
+if 0 <= fullname.rfind('>'):
+try:
+existing = self.master.overloads[fullname]
+allf = existing.functions + method.functions
+if isinstance(existing, W_CPPStaticOverload):
+cppol = W_CPPStaticOverload(self.space, self.scope, allf, 
self.flags)
+else:
+cppol = W_CPPOverload(self.space, self.scope, allf, 
self.flags)
+self.master.overloads[fullname] = cppol
+except KeyError:
 self.master.overloads[fullname] = method
 
 return method.descr_get(self.w_this, []).call(args_w)
@@ -756,9 +764,12 @@
 method = self.master.overloads[fullname]
 except KeyError:
 method = self.find_method_template(fullname)
-
-# cache result (name is always full templated name)
-self.master.overloads[fullname] = method
+# cache result (name is always full templated name)
+self.master.overloads[fullname] = method
+# also cache on "official" name (may include default template 
arguments)
+c_fullname = capi.c_method_full_name(self.space, 
method.functions[0].cppmethod)
+if c_fullname != fullname:
+self.master.overloads[c_fullname] = method
 
 return method.descr_get(self.w_this, [])
 
@@ -783,6 +794,7 @@
 return self  # unbound, so no new instance needed
 cppol = W_CPPTemplateOverload(self.space, self.name, self.scope, 
self.functions, self.flags)
 cppol.w_this = w_cppinstance
+cppol.master = self.master
 return cppol # bound
 
 @unwrap_spec(args_w='args_w')
@@ -796,7 +808,7 @@
 except Exception:
 pass
 
-return self.instantiation_from_args(self.name, args_w)
+return self.instantiate_and_call(self.name, args_w)
 
 @unwrap_spec(args_w='args_w')
 def getitem(self, args_w):
@@ -851,7 +863,7 @@
 pass
 
 # try new instantiation
-return self.instantiation_from_args(self.name, args_w)
+return self.instantiate_and_call(self.name, args_w)
 
 @unwrap_spec(args_w='args_w')
 def getitem(self, args_w):
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
@@ -422,8 +422,8 @@
 # map begin()/end() protocol to iter protocol on STL(-like) classes, but
 # not on vector, which is pythonized in the capi (interp-level; there is
 # also the fallback on the indexed __getitem__, but that is slower)
-if not 'vector' in name[:11] and \
-('begin' in pyclass.__dict__ and 'end' in pyclass.__dict__):
+# TODO:if not (0 <= name.find('vector') <= 5):
+if ('begin' in pyclass.__dict__ and 'end' in pyclass.__dict__):
 if _cppyy._scope_byname(name+'::iterator') or \
 _

[pypy-commit] pypy default: more templates and consistency with CPython/cppyy

2018-06-16 Thread wlav
Author: Wim Lavrijsen 
Branch: 
Changeset: r94771:20e8b110028c
Date: 2018-06-16 01:16 -0700
http://bitbucket.org/pypy/pypy/changeset/20e8b110028c/

Log:more templates and consistency with CPython/cppyy

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
@@ -706,7 +706,7 @@
 "no overload found matching %s", self.signature)
 
 
-class SmartPointerConverter(TypeConverter):
+class SmartPtrConverter(TypeConverter):
 _immutable_fields = ['typecode', 'smartdecl', 'rawdecl', 'deref']
 typecode= 'V'
 
@@ -753,7 +753,7 @@
 return interp_cppyy.wrap_cppinstance(space, address,
 self.rawdecl, smartdecl=self.smartdecl, deref=self.deref, 
do_cast=False)
 
-class SmartPointerPtrConverter(SmartPointerConverter):
+class SmartPtrPtrConverter(SmartPtrConverter):
 typecode= 'o'
 
 def from_memory(self, space, w_obj, w_pycppclass, offset):
@@ -763,7 +763,7 @@
 self._is_abstract(space)
 
 
-class SmartPointerRefConverter(SmartPointerPtrConverter):
+class SmartPtrRefConverter(SmartPtrPtrConverter):
 typecode= 'V'
 
 
@@ -804,6 +804,12 @@
 compound = helper.compound(name)
 clean_name = capi.c_resolve_name(space, helper.clean_type(name))
 try:
+return _converters[clean_name+compound](space, default)
+except KeyError:
+pass
+
+# arrays
+try:
 # array_index may be negative to indicate no size or no size found
 array_size = helper.array_size(_name) # uses original arg
 # TODO: using clean_name here drops const (e.g. const char[] will
@@ -823,11 +829,11 @@
 check_smart = capi.c_smartptr_info(space, clean_name)
 if check_smart[0]:
 if compound == '':
-return SmartPointerConverter(space, clsdecl, check_smart[1], 
check_smart[2])
+return SmartPtrConverter(space, clsdecl, check_smart[1], 
check_smart[2])
 elif compound == '*':
-return SmartPointerPtrConverter(space, clsdecl, 
check_smart[1], check_smart[2])
+return SmartPtrPtrConverter(space, clsdecl, check_smart[1], 
check_smart[2])
 elif compound == '&':
-return SmartPointerRefConverter(space, clsdecl, 
check_smart[1], check_smart[2])
+return SmartPtrRefConverter(space, clsdecl, check_smart[1], 
check_smart[2])
 # fall through: can still return smart pointer in non-smart way
 
 # type check for the benefit of the annotator
diff --git a/pypy/module/_cppyy/executor.py b/pypy/module/_cppyy/executor.py
--- a/pypy/module/_cppyy/executor.py
+++ b/pypy/module/_cppyy/executor.py
@@ -26,7 +26,7 @@
 
 NULL = lltype.nullptr(jit_libffi.FFI_TYPE_P.TO)
 
-class FunctionExecutor(object):
+class Executor(object):
 def __init__(self, space, extra):
 pass
 
@@ -43,7 +43,7 @@
 raise FastCallNotPossible
 
 
-class PtrTypeExecutor(FunctionExecutor):
+class PtrTypeExecutor(Executor):
 _immutable_fields_ = ['typecode']
 typecode = 'P'
 
@@ -63,7 +63,7 @@
 return W_ArrayInstance(space, shape, sys.maxint/shape.size, ptrval)
 
 
-class VoidExecutor(FunctionExecutor):
+class VoidExecutor(Executor):
 def cffi_type(self, space):
 state = space.fromcache(ffitypes.State)
 return state.c_void
@@ -96,7 +96,7 @@
 _mixin_ = True
 
 def __init__(self, space, extra):
-FunctionExecutor.__init__(self, space, extra)
+Executor.__init__(self, space, extra)
 self.do_assign = False
 self.item = rffi.cast(self.c_type, 0)
 
@@ -124,7 +124,7 @@
 rffi.cast(self.c_ptrtype, rffi.cast(rffi.VOIDPP, result)[0]))
 
 
-class CStringExecutor(FunctionExecutor):
+class CStringExecutor(Executor):
 def execute(self, space, cppmethod, cppthis, num_args, args):
 lresult = capi.c_call_l(space, cppmethod, cppthis, num_args, args)
 ccpresult = rffi.cast(rffi.CCHARP, lresult)
@@ -134,7 +134,7 @@
 return space.newbytes(result)
 
 
-class ConstructorExecutor(FunctionExecutor):
+class ConstructorExecutor(Executor):
 def execute(self, space, cppmethod, cpptype, num_args, args):
 from pypy.module._cppyy import interp_cppyy
 newthis = capi.c_constructor(space, cppmethod, cpptype, num_args, args)
@@ -142,12 +142,12 @@
 return space.newlong(rffi.cast(rffi.LONG, newthis))   # really want 
ptrdiff_t here
 
 
-class InstanceExecutor(FunctionExecutor):
+class InstanceExecutor(Executor):
 # For return of a C++ instance by pointer: MyClass* func()
 _immutable_fields_ = ['clsdecl']
 
 def __init__(self, space, clsdecl):
-FunctionExecutor.__init__(self, space, clsdecl)
+Executor.__init__(self, space, clsdecl)
 self.clsdecl = clsdecl
 
 def _wrap_result(self, space, obj):
@@ -338,7 +338,7 @@
 return _executors['void*'](space, None)  # allow at l

[pypy-commit] pypy cppyy-packaging: merge default into branch

2018-06-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94770:1e6f1f90453c
Date: 2018-06-15 23:27 -0700
http://bitbucket.org/pypy/pypy/changeset/1e6f1f90453c/

Log:merge default into branch

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -7,9 +7,9 @@
 
 .. branch: cppyy-packaging
 
-Upgrade to backend 0.6.0, support exception handling from wrapped functions,
-update enum handling, const correctness for data members and associated tests,
-support anonymous enums, support for function pointer arguments
+Upgrade to backend 1.1.0, improved handling of templated methods and
+functions (in particular automatic deduction of types), improved pythonization
+interface, and a range of compatibility fixes for Python3
 
 .. branch: socket_default_timeout_blockingness
 
diff --git a/pypy/interpreter/pyparser/automata.py 
b/pypy/interpreter/pyparser/automata.py
--- a/pypy/interpreter/pyparser/automata.py
+++ b/pypy/interpreter/pyparser/automata.py
@@ -23,6 +23,10 @@
 
 ERROR_STATE = chr(255)
 
+# NB: all non-ascii bytes (>= 128) will be turned into 128
+NON_ASCII = chr(128)
+
+
 class DFA:
 # 
 def __init__(self, states, accepts, start = 0):
@@ -36,7 +40,10 @@
 for key in state:
 if key == DEFAULT:
 continue
-maximum = max(ord(key), maximum)
+ordkey = ord(key)
+if ordkey > 128:
+raise ValueError("DFA does not support matching of 
specific non-ASCII character %r. Use NON_ASCII instead" % key)
+maximum = max(ordkey, maximum)
 self.max_char = maximum + 1
 
 defaults = []
@@ -72,6 +79,8 @@
 i = pos
 for i in range(pos, len(inVec)):
 item = inVec[i]
+if ord(item) > 0x80:
+item = NON_ASCII
 accept = self.accepts[crntState]
 crntState = self._next_state(item, crntState)
 if crntState != ERROR_STATE:
@@ -103,6 +112,8 @@
 i = pos
 for i in range(pos, len(inVec)):
 item = inVec[i]
+if ord(item) > 0x80:
+item = NON_ASCII
 accept = self.accepts[crntState]
 if accept:
 return i
diff --git a/pypy/interpreter/pyparser/test/test_automata.py 
b/pypy/interpreter/pyparser/test/test_automata.py
--- a/pypy/interpreter/pyparser/test/test_automata.py
+++ b/pypy/interpreter/pyparser/test/test_automata.py
@@ -1,4 +1,7 @@
-from pypy.interpreter.pyparser.automata import DFA, NonGreedyDFA, DEFAULT
+# coding: utf-8
+import pytest
+
+from pypy.interpreter.pyparser.automata import DFA, NonGreedyDFA, DEFAULT, 
NON_ASCII
 
 def test_states():
 d = DFA([{"\x00": 1}, {"\x01": 0}], [False, True])
@@ -27,3 +30,18 @@
 d = NonGreedyDFA([{"a": 1}, {DEFAULT: 0}], [False, True])
 assert d.recognize("a,a?ab") == 1
 assert d.recognize("c") == -1
+
+def test_nonascii():
+d = DFA([{"a": 1}, {NON_ASCII: 1}], [False, True])
+input = u"a".encode("utf-8")
+assert d.recognize(input) == len(input)
+assert d.recognize("c") == -1
+assert d.recognize("ü") == -1
+
+d = NonGreedyDFA([{NON_ASCII: 0, "b": 1}, {"b": 0}], [False, True])
+input = u"üü".encode("utf-8")
+assert d.recognize(input) == len(u"üüb".encode("utf-8"))
+assert d.recognize("c") == -1
+
+pytest.raises(ValueError, DFA, [{"\x81": 2}], [True])
+
diff --git a/pypy/interpreter/test/test_function.py 
b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -455,6 +455,8 @@
 assert repr(B().f).startswith(">")
 
+assert repr(type(A.f)) == repr(type(A().f)) == ""
+
 
 def test_method_call(self):
 class C(object):
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -688,7 +688,7 @@
 Function.typedef.acceptable_as_base_class = False
 
 Method.typedef = TypeDef(
-"method",
+"instancemethod",
 __doc__ = """instancemethod(function, instance, class)
 
 Create an instance method object.""",
diff --git a/pypy/module/_cppyy/ffitypes.py b/pypy/module/_cppyy/ffitypes.py
--- a/pypy/module/_cppyy/ffitypes.py
+++ b/pypy/module/_cppyy/ffitypes.py
@@ -119,7 +119,7 @@
 value = space.bytes_w(w_value)
 if len(value) != 1:
 raise oefmt(space.w_ValueError,
-"usigned char expected, got string of size %d", 
len(value))
+"unsigned char expected, got string of size %d", 
len(value))
 
 value = rffi.cast(rffi.CHAR, value[0])
 return value # turn it into a "char" to the annotator
___
pypy-commit mailing list
pypy-commit@python.

[pypy-commit] pypy cppyy-packaging: simplify use of converters

2018-06-20 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94774:df5f9ec89c17
Date: 2018-06-20 19:26 -0700
http://bitbucket.org/pypy/pypy/changeset/df5f9ec89c17/

Log:simplify use of converters

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
@@ -108,7 +108,7 @@
 from pypy.module._cppyy.interp_cppyy import FastCallNotPossible
 raise FastCallNotPossible
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 self._is_abstract(space)
 
 def convert_argument_libffi(self, space, w_obj, address, call_local):
@@ -125,10 +125,10 @@
 def to_memory(self, space, w_obj, w_value, offset):
 self._is_abstract(space)
 
-def finalize_call(self, space, w_obj, call_local):
+def finalize_call(self, space, w_obj):
 pass
 
-def free_argument(self, space, arg, call_local):
+def free_argument(self, space, arg):
 pass
 
 
@@ -172,7 +172,7 @@
 state = space.fromcache(ffitypes.State)
 return state.c_voidp
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 w_tc = space.findattr(w_obj, space.newtext('typecode'))
 if w_tc is not None and space.text_w(w_tc) != self.typecode:
 raise oefmt(space.w_TypeError,
@@ -247,7 +247,7 @@
 class IntTypeConverterMixin(NumericTypeConverterMixin):
 _mixin_ = True
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(self.c_ptrtype, address)
 x[0] = self._unwrap_object(space, w_obj)
 ba = rffi.cast(rffi.CCHARP, address)
@@ -256,7 +256,7 @@
 class FloatTypeConverterMixin(NumericTypeConverterMixin):
 _mixin_ = True
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(self.c_ptrtype, address)
 x[0] = self._unwrap_object(space, w_obj)
 ba = rffi.cast(rffi.CCHARP, address)
@@ -273,12 +273,12 @@
 state = space.fromcache(ffitypes.State)
 return state.c_void
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 self._is_abstract(space)
 
 
 class BoolConverter(ffitypes.typeid(bool), TypeConverter):
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(rffi.LONGP, address)
 x[0] = self._unwrap_object(space, w_obj)
 ba = rffi.cast(rffi.CCHARP, address)
@@ -303,7 +303,7 @@
 address[0] = '\x00'
 
 class CharConverter(ffitypes.typeid(rffi.CHAR), TypeConverter):
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(rffi.CCHARP, address)
 x[0] = self._unwrap_object(space, w_obj)
 ba = rffi.cast(rffi.CCHARP, address)
@@ -381,7 +381,7 @@
 
 
 class CStringConverter(TypeConverter):
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(rffi.LONGP, address)
 arg = space.text_w(w_obj)
 x[0] = rffi.cast(rffi.LONG, rffi.str2charp(arg))
@@ -393,7 +393,7 @@
 charpptr = rffi.cast(rffi.CCHARPP, address)
 return space.newtext(rffi.charp2str(charpptr[0]))
 
-def free_argument(self, space, arg, call_local):
+def free_argument(self, space, arg):
 lltype.free(rffi.cast(rffi.CCHARPP, arg)[0], flavor='raw')
 
 class CStringConverterWithSize(CStringConverter):
@@ -423,7 +423,7 @@
 state = space.fromcache(ffitypes.State)
 return state.c_voidp
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(rffi.VOIDPP, address)
 x[0] = self._unwrap_object(space, w_obj)
 ba = rffi.cast(rffi.CCHARP, address)
@@ -452,37 +452,39 @@
 address[0] = rffi.cast(rffi.VOIDP, self._unwrap_object(space, 
w_value))
 
 class VoidPtrPtrConverter(TypeConverter):
-_immutable_fields_ = ['uses_local', 'typecode']
+typecode = 'p'
 
-uses_local = True
-typecode = 'a'
+def __init__(self, space, extra):
+self.ref_buffer = lltype.nullptr(rffi.VOIDPP.TO)
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(rffi.VOIDPP, address)
-ba = rffi.cast(rffi.CCHARP, address)
 try:
 x[0] = get_rawbuffer(space, w_obj)
 except TypeError:
-r = rffi.cast(rffi.VOIDPP, call_local)
-r[0] = rffi.cast(rffi.VOIDP, get_rawobjec

  1   2   3   4   5   6   7   8   >