[pypy-commit] pypy cppyy-packaging: store free functions on namespace dict, not namespace's class dict

2018-07-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94871:ff8881eb57bb
Date: 2018-07-16 13:02 -0700
http://bitbucket.org/pypy/pypy/changeset/ff8881eb57bb/

Log:store free functions on namespace dict, not namespace's class dict

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
@@ -317,7 +317,7 @@
 if not cppitem:
 try:
 cppitem = scope.__cppdecl__.get_overload(name)
-setattr(scope.__class__, name, cppitem)
+setattr(scope, name, cppitem)
 pycppitem = getattr(scope, name)  # binds function as needed
 except AttributeError:
 pass
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: remove unused variable

2018-07-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94870:8e6c6830fc0c
Date: 2018-07-15 21:43 -0700
http://bitbucket.org/pypy/pypy/changeset/8e6c6830fc0c/

Log:remove unused variable

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
@@ -115,7 +115,7 @@
 from pypy.module._cppyy.interp_cppyy import FastCallNotPossible
 raise FastCallNotPossible
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, offset):
 self._is_abstract(space)
 
 def to_memory(self, space, w_obj, w_value, offset):
@@ -142,7 +142,7 @@
 state = space.fromcache(ffitypes.State)
 return state.c_voidp
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, offset):
 # read access, so no copy needed
 address_value = self._get_raw_address(space, w_obj, offset)
 address = rffi.cast(rffi.ULONG, address_value)
@@ -184,7 +184,7 @@
 ba = rffi.cast(rffi.CCHARP, address)
 ba[capi.c_function_arg_typeoffset(space)] = 'o'
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, offset):
 # read access, so no copy needed
 address_value = self._get_raw_address(space, w_obj, offset)
 address = rffi.cast(rffi.ULONGP, address_value)
@@ -214,7 +214,7 @@
 x = rffi.cast(self.c_ptrtype, address)
 x[0] = self.default
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, offset):
 address = self._get_raw_address(space, w_obj, offset)
 rffiptr = rffi.cast(self.c_ptrtype, address)
 return self._wrap_object(space, rffiptr[0])
@@ -283,7 +283,7 @@
 x = rffi.cast(rffi.LONGP, address)
 x[0] = self._unwrap_object(space, w_obj)
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, offset):
 address = rffi.cast(rffi.CCHARP, self._get_raw_address(space, w_obj, 
offset))
 if address[0] == '\x01':
 return space.w_True
@@ -308,7 +308,7 @@
 x = rffi.cast(self.c_ptrtype, address)
 x[0] = self._unwrap_object(space, w_obj)
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, offset):
 address = rffi.cast(rffi.CCHARP, self._get_raw_address(space, w_obj, 
offset))
 return space.newbytes(address[0])
 
@@ -330,7 +330,7 @@
 fval = float(0.)
 self.default = r_singlefloat(fval)
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, offset):
 address = self._get_raw_address(space, w_obj, offset)
 rffiptr = rffi.cast(self.c_ptrtype, address)
 return self._wrap_object(space, rffiptr[0])
@@ -383,7 +383,7 @@
 ba = rffi.cast(rffi.CCHARP, address)
 ba[capi.c_function_arg_typeoffset(space)] = 'p'
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, offset):
 address = self._get_raw_address(space, w_obj, offset)
 charpptr = rffi.cast(rffi.CCHARPP, address)
 return space.newtext(rffi.charp2str(charpptr[0]))
@@ -397,7 +397,7 @@
 def __init__(self, space, extra):
 self.size = extra
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, offset):
 address = self._get_raw_address(space, w_obj, offset)
 charpptr = rffi.cast(rffi.CCHARP, address)
 if 0 <= self.size and self.size != 2**31-1:   # cling's code for 
"unknown" (?)
@@ -430,7 +430,7 @@
 x = rffi.cast(rffi.VOIDPP, address)
 x[0] = self._unwrap_object(space, w_obj)
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, 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)
@@ -542,7 +542,7 @@
 from pypy.module._cppyy.interp_cppyy import FastCallNotPossible
 raise FastCallNotPossible   # TODO: by-value is a jit_libffi 
special case
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, 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.clsdecl, 
do_cast=False)
@@ -562,7 +562,7 @@
 return capi.C_NULL_OBJECT
 raise e
 
-def from_memory(self, space, w_obj, w_pycppclass, offset):
+def from_memory(self, space, w_obj, offset):
 address = rffi.ca

[pypy-commit] pypy cppyy-packaging: more settable overload properties

2018-07-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94868:c67865f23398
Date: 2018-07-15 20:17 -0700
http://bitbucket.org/pypy/pypy/changeset/c67865f23398/

Log:more settable overload properties

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
@@ -24,6 +24,7 @@
 INSTANCE_FLAGS_IS_RVALUE   = 0x0004
 
 OVERLOAD_FLAGS_USE_FFI = 0x0001
+OVERLOAD_FLAGS_CREATES = 0x0002
 
 FUNCTION_IS_GLOBAL = 0x0001
 FUNCTION_IS_STATIC = 0x0001
@@ -458,6 +459,36 @@
 # need forwarding, which the normal instancemethod does not provide, hence this
 # derived class.
 class MethodWithProps(Method):
+# set life management of result from the call
+def fget_creates(self, space):
+f = space.interp_w(W_CPPOverload, self.w_function)
+return f.fget_creates(space)
+
+@unwrap_spec(value=bool)
+def fset_creates(self, space, value):
+f = space.interp_w(W_CPPOverload, self.w_function)
+f.fset_creates(space, value)
+
+# set ownership policy of arguments (not yet implemented)
+def fget_mempolicy(self, space):
+f = space.interp_w(W_CPPOverload, self.w_function)
+return f.fget_mempolicy(space)
+
+@unwrap_spec(value=int)
+def fset_mempolicy(self, space, value):
+f = space.interp_w(W_CPPOverload, self.w_function)
+f.fset_mempolicy(space, value)
+
+# set to release the gil during call (not yet implemented)
+def fget_release_gil(self, space):
+f = space.interp_w(W_CPPOverload, self.w_function)
+return f.fget_release_gil(space)
+
+@unwrap_spec(value=bool)
+def fset_release_gil(self, space, value):
+f = space.interp_w(W_CPPOverload, self.w_function)
+f.fset_release_gil(space, value)
+
 # allow user to determine ffi use rules per overload
 def fget_useffi(self, space):
 f = space.interp_w(W_CPPOverload, self.w_function)
@@ -473,22 +504,25 @@
 __doc__ = """cpp_instancemethod(function, instance, class)
 
 Create an instance method object.""",
-__new__ = interp2app(MethodWithProps.descr_method__new__.im_func),
-__call__ = interp2app(MethodWithProps.descr_method_call),
-__get__ = interp2app(MethodWithProps.descr_method_get),
-im_func = interp_attrproperty_w('w_function', cls=MethodWithProps),
-__func__ = interp_attrproperty_w('w_function', cls=MethodWithProps),
-im_self = interp_attrproperty_w('w_instance', cls=MethodWithProps),
-__self__ = interp_attrproperty_w('w_instance', cls=MethodWithProps),
-im_class = interp_attrproperty_w('w_class', cls=MethodWithProps),
+__new__  = interp2app(MethodWithProps.descr_method__new__.im_func),
+__call__ = interp2app(MethodWithProps.descr_method_call),
+__get__  = interp2app(MethodWithProps.descr_method_get),
+im_func  = interp_attrproperty_w('w_function', 
cls=MethodWithProps),
+__func__ = interp_attrproperty_w('w_function', 
cls=MethodWithProps),
+im_self  = interp_attrproperty_w('w_instance', 
cls=MethodWithProps),
+__self__ = interp_attrproperty_w('w_instance', 
cls=MethodWithProps),
+im_class = interp_attrproperty_w('w_class', cls=MethodWithProps),
 __getattribute__ = interp2app(MethodWithProps.descr_method_getattribute),
-__eq__ = interp2app(MethodWithProps.descr_method_eq),
-__ne__ = descr_generic_ne,
-__hash__ = interp2app(MethodWithProps.descr_method_hash),
-__repr__ = interp2app(MethodWithProps.descr_method_repr),
-__reduce__ = interp2app(MethodWithProps.descr_method__reduce__),
-__weakref__ = make_weakref_descr(MethodWithProps),
-__useffi__ = GetSetProperty(MethodWithProps.fget_useffi, 
MethodWithProps.fset_useffi),
+__eq__   = interp2app(MethodWithProps.descr_method_eq),
+__ne__   = descr_generic_ne,
+__hash__ = interp2app(MethodWithProps.descr_method_hash),
+__repr__ = interp2app(MethodWithProps.descr_method_repr),
+__reduce__   = interp2app(MethodWithProps.descr_method__reduce__),
+__weakref__  = make_weakref_descr(MethodWithProps),
+__creates__  = GetSetProperty(MethodWithProps.fget_creates, 
MethodWithProps.fset_creates),
+__mempolicy__= GetSetProperty(MethodWithProps.fget_mempolicy,   
MethodWithProps.fset_mempolicy),
+__release_gil__  = GetSetProperty(MethodWithProps.fget_release_gil, 
MethodWithProps.fset_release_gil),
+__useffi__   = GetSetProperty(MethodWithProps.fget_useffi,  
MethodWithProps.fset_useffi),
 )
 MethodWithProps.typedef.acceptable_as_base_class = False
 
@@ -551,7 +585,12 @@
 for i in range(len(self.functions)):
 cppyyfunc = self.functions[i]
 try:
-return cppyyfunc.call(cppthis, args_w, self.flags & 
OVERLOAD_FLAGS_USE_FFI)
+w_result = cppyyfunc.call(cp

[pypy-commit] pypy cppyy-packaging: improved dir() for namespaces

2018-07-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94869:7fecec6b5a70
Date: 2018-07-15 21:43 -0700
http://bitbucket.org/pypy/pypy/changeset/7fecec6b5a70/

Log:improved dir() for namespaces

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
@@ -29,7 +29,14 @@
 
 class CPPNamespaceMeta(CPPScopeMeta):
 def __dir__(self):
-return self.__cppdecl__.__dir__()
+# For Py3: can actually call base class __dir__ (lives in type)
+values = set(self.__dict__.keys())
+values.update(object.__dict__.keys())
+values.update(type(self).__dict__.keys())
+
+# add C++ entities
+values.update(self.__cppdecl__.__dir__())
+return list(values)
 
 class CPPClassMeta(CPPScopeMeta):
 pass
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: make sure to pass w_this for non-templated overloads of templates

2018-07-16 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94872:1bad6c9de6b7
Date: 2018-07-16 22:41 -0700
http://bitbucket.org/pypy/pypy/changeset/1bad6c9de6b7/

Log:make sure to pass w_this for non-templated overloads of templates

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
@@ -926,7 +926,7 @@
 
 # try existing overloads or compile-time instantiations
 try:
-return W_CPPOverload.call_args(self, args_w)
+return W_CPPOverload.call_args(self, [self.w_this]+args_w)
 except Exception:
 pass
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit