[pypy-commit] pypy unicode-utf8-py3: str_w -> text_w

2018-07-11 Thread mattip
Author: Matti Picus 
Branch: unicode-utf8-py3
Changeset: r94843:0c716461ad5d
Date: 2018-07-10 21:48 -0700
http://bitbucket.org/pypy/pypy/changeset/0c716461ad5d/

Log:str_w -> text_w

diff --git a/pypy/objspace/std/test/test_bytesobject.py 
b/pypy/objspace/std/test/test_bytesobject.py
--- a/pypy/objspace/std/test/test_bytesobject.py
+++ b/pypy/objspace/std/test/test_bytesobject.py
@@ -97,7 +97,7 @@
 monkeypatch.setattr(jit, 'isconstant', lambda x: True)
 space = self.space
 w_res = space.call_function(space.w_bytes, space.wrap([42]))
-assert space.str_w(w_res) == '*'
+assert space.text_w(w_res) == '*'
 
 
 class AppTestBytesObject:
diff --git a/pypy/objspace/std/test/test_liststrategies.py 
b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -616,7 +616,7 @@
 space = self.space
 w_l = self.space.newlist([self.space.wrap('a'), self.space.wrap('b')])
 w_l.getitems = None
-assert space.str_w(space.call_method(space.wrap("c"), "join", w_l)) == 
"acb"
+assert space.text_w(space.call_method(space.wrap("c"), "join", w_l)) 
== "acb"
 #
 # the same for unicode
 w_l = self.space.newlist([self.space.wrap(u'a'), 
self.space.wrap(u'b')])
diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -920,7 +920,7 @@
 #
 def check(space, w_func, name):
 w_code = space.getattr(w_func, space.wrap('__code__'))
-nameindex = map(space.str_w, w_code.co_names_w).index(name)
+nameindex = map(space.text_w, w_code.co_names_w).index(name)
 entry = w_code._mapdict_caches[nameindex]
 entry.failure_counter = 0
 entry.success_counter = 0
diff --git a/pypy/objspace/std/test/test_memoryobject.py 
b/pypy/objspace/std/test/test_memoryobject.py
--- a/pypy/objspace/std/test/test_memoryobject.py
+++ b/pypy/objspace/std/test/test_memoryobject.py
@@ -307,7 +307,7 @@
 self.w_arr = w_arr
 self.arr = []
 self.ndim = space.int_w(w_dim)
-self.format = space.str_w(w_fmt)
+self.format = space.text_w(w_fmt)
 self.itemsize = space.int_w(w_itemsize)
 self.strides = []
 for w_i in w_strides.getitems_unroll():
diff --git a/pypy/objspace/std/test/test_methodcache.py 
b/pypy/objspace/std/test/test_methodcache.py
--- a/pypy/objspace/std/test/test_methodcache.py
+++ b/pypy/objspace/std/test/test_methodcache.py
@@ -52,7 +52,7 @@
 # if cached_name is name:
 
 # in py3k, identifiers are stored in W_UnicodeObject and unwrapped by
-# calling space.str_w, which .encode('ascii') the string, thus
+# calling space.text_w, which .encode('ascii') the string, thus
 # creating new strings all the time. The problem should be solved when
 # we implement proper unicode identifiers in py3k
 @self.retry
diff --git a/pypy/objspace/std/test/test_setobject.py 
b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -49,9 +49,9 @@
 
 def test_space_newset(self):
 s = self.space.newset()
-assert self.space.str_w(self.space.repr(s)) == 'set()'
+assert self.space.text_w(self.space.repr(s)) == 'set()'
 # check that the second time we don't get 'set(...)'
-assert self.space.str_w(self.space.repr(s)) == 'set()'
+assert self.space.text_w(self.space.repr(s)) == 'set()'
 
 def test_intersection_order(self):
 # theses tests make sure that intersection is done in the correct order
diff --git a/pypy/objspace/std/test/test_stdobjspace.py 
b/pypy/objspace/std/test/test_stdobjspace.py
--- a/pypy/objspace/std/test/test_stdobjspace.py
+++ b/pypy/objspace/std/test/test_stdobjspace.py
@@ -16,9 +16,9 @@
 assert self.space.isinstance_w(self.space.newtext("abc"), 
self.space.w_unicode)
 assert self.space.eq_w(self.space.newtext("üöä"), 
self.space.newtext(u"üöä"))
 
-def test_str_w_non_str(self):
-raises(OperationError,self.space.str_w,self.space.wrap(None))
-raises(OperationError,self.space.str_w,self.space.wrap(0))
+def test_text_w_non_str(self):
+raises(OperationError,self.space.text_w,self.space.wrap(None))
+raises(OperationError,self.space.text_w,self.space.wrap(0))
 
 def test_int_w_non_int(self):
 raises(OperationError,self.space.int_w,self.space.wrap(None))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy unicode-utf8-py3: small tweaks, copy partition from py3.5

2018-07-11 Thread mattip
Author: Matti Picus 
Branch: unicode-utf8-py3
Changeset: r94847:e8413e4a1934
Date: 2018-07-11 06:51 -0700
http://bitbucket.org/pypy/pypy/changeset/e8413e4a1934/

Log:small tweaks, copy partition from py3.5

diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -404,9 +404,9 @@
 _KIND1 = "byte"
 _KIND2 = "bytes"
 
-def __init__(self, str):
-assert str is not None
-self._value = str
+def __init__(self, s):
+assert s is not None
+self._value = s
 
 def __repr__(self):
 """representation for debugging purposes"""
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -327,7 +327,7 @@
 return W_ListObject.newlist_bytes(self, list_s)
 
 def newlist_text(self, list_t):
-return self.newlist_utf8([decode_utf8sp(self, s) for s in list_t])
+return self.newlist_utf8([decode_utf8sp(self, s)[0] for s in list_t])
 
 def newlist_utf8(self, list_u, is_ascii=True):
 # TODO ignoring is_ascii, is that correct?
@@ -762,7 +762,7 @@
 if not e.match(self, self.w_TypeError):
 raise
 else:
-classname = b'%s.%s' % (modulename, classname)
+classname = u'%s.%s' % (modulename.decode('utf8'), 
classname)
 else:
 classname = w_type.name.decode('utf-8')
 return classname
diff --git a/pypy/objspace/std/stringmethods.py 
b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -478,39 +478,56 @@
 from pypy.objspace.std.bytearrayobject import W_BytearrayObject
 value = self._val(space)
 
-sub = _get_buffer(space, w_sub)
-sublen = sub.getlength()
-if sublen == 0:
-raise oefmt(space.w_ValueError, "empty separator")
+if self._use_rstr_ops(space, w_sub):
+sub = self._op_val(space, w_sub)
+sublen = len(sub)
+if sublen == 0:
+raise oefmt(space.w_ValueError, "empty separator")
 
-pos = find(value, sub, 0, len(value))
-if pos != -1 and isinstance(self, W_BytearrayObject):
-w_sub = self._new_from_buffer(sub)
+pos = value.find(sub)
+else:
+sub = space.readbuf_w(w_sub)
+sublen = sub.getlength()
+if sublen == 0:
+raise oefmt(space.w_ValueError, "empty separator")
+
+pos = find(value, sub, 0, len(value))
+if pos != -1 and isinstance(self, W_BytearrayObject):
+w_sub = self._new_from_buffer(sub)
 
 if pos == -1:
-self = self._new(value)
+if isinstance(self, W_BytearrayObject):
+self = self._new(value)
 return space.newtuple([self, self._empty(), self._empty()])
 else:
 return space.newtuple(
 [self._sliced(space, value, 0, pos, self), w_sub,
  self._sliced(space, value, pos + sublen, len(value), self)])
 
-# This is not used for W_UnicodeObject.
 def descr_rpartition(self, space, w_sub):
 from pypy.objspace.std.bytearrayobject import W_BytearrayObject
 value = self._val(space)
 
-sub = _get_buffer(space, w_sub)
-sublen = sub.getlength()
-if sublen == 0:
-raise oefmt(space.w_ValueError, "empty separator")
+if self._use_rstr_ops(space, w_sub):
+sub = self._op_val(space, w_sub)
+sublen = len(sub)
+if sublen == 0:
+raise oefmt(space.w_ValueError, "empty separator")
 
-pos = rfind(value, sub, 0, len(value))
-if pos != -1 and isinstance(self, W_BytearrayObject):
-w_sub = self._new_from_buffer(sub)
+pos = value.rfind(sub)
+else:
+sub = space.readbuf_w(w_sub)
+sublen = sub.getlength()
+if sublen == 0:
+raise oefmt(space.w_ValueError, "empty separator")
+
+pos = rfind(value, sub, 0, len(value))
+if pos != -1 and isinstance(self, W_BytearrayObject):
+w_sub = self._new_from_buffer(sub)
 
 if pos == -1:
-self = self._new(value)
+if isinstance(self, W_BytearrayObject):
+self = self._new(value)
 return space.newtuple([self._empty(), self._empty(), self])
 else:
 return space.newtuple(
diff --git a/pypy/objspace/std/test/test_stdobjspace.py 
b/pypy/objspace/std/test/test_stdobjspace.py
--- a/pypy/objspace/std/test/test_stdobjspace.py
+++ b/pypy/objspace/std/test/test_stdobjspace.py
@@ -84,7 +84,7 @@
 from pypy.objspace.std.unicodeobject import W_UnicodeObject
 w_x = self.spa

[pypy-commit] pypy unicode-utf8: modify never used rpython surrogate_in_utf8 to return index

2018-07-11 Thread mattip
Author: Matti Picus 
Branch: unicode-utf8
Changeset: r94848:6ebf80250b71
Date: 2018-07-11 06:46 -0700
http://bitbucket.org/pypy/pypy/changeset/6ebf80250b71/

Log:modify never used rpython surrogate_in_utf8 to return index

diff --git a/rpython/rlib/rutf8.py b/rpython/rlib/rutf8.py
--- a/rpython/rlib/rutf8.py
+++ b/rpython/rlib/rutf8.py
@@ -471,8 +471,8 @@
 """
 for i in range(len(value) - 2):
 if value[i] == '\xed' and value[i + 1] >= '\xa0':
-return True
-return False
+return i
+return -1
 
 
 UTF8_INDEX_STORAGE = lltype.GcArray(lltype.Struct('utf8_loc_elem',
diff --git a/rpython/rlib/test/test_rutf8.py b/rpython/rlib/test/test_rutf8.py
--- a/rpython/rlib/test/test_rutf8.py
+++ b/rpython/rlib/test/test_rutf8.py
@@ -152,7 +152,7 @@
 @example([u'\ud800', u'\udc00'])
 def test_surrogate_in_utf8(unichars):
 uni = ''.join([u.encode('utf8') for u in unichars])
-result = rutf8.surrogate_in_utf8(uni)
+result = rutf8.surrogate_in_utf8(uni) < 0
 expected = any(uch for uch in unichars if u'\ud800' <= uch <= u'\udfff')
 assert result == expected
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy unicode-utf8-py3: revert some of 2621c0f70d91, avoid decoding utf8 -> unicode

2018-07-11 Thread mattip
Author: Matti Picus 
Branch: unicode-utf8-py3
Changeset: r94844:ad7718874721
Date: 2018-07-11 06:44 -0700
http://bitbucket.org/pypy/pypy/changeset/ad7718874721/

Log:revert some of 2621c0f70d91, avoid decoding utf8 -> unicode

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -602,8 +602,11 @@
 
 def getmsg(self):
 if self.num_kwds == 1:
-msg = u"got an unexpected keyword argument '%s'" % (
-self.kwd_name.decode('utf8'))
+if isinstance(self.kwd_name, str):
+uname = self.kwd_name.decode('utf8')
+else:
+uname = self.kwd_name
+msg = u"got an unexpected keyword argument '%s'" % uname
 else:
 msg = "got %d unexpected keyword arguments" % (
 self.num_kwds)
diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -638,7 +638,7 @@
 state = space.fromcache(CodecState)
 utf8len = w_arg._length
 # XXX deal with func() returning length or not
-result = func(w_arg._utf8.decode('utf8'), errors, 
state.encode_error_handler)
+result = func(w_arg._utf8, errors, state.encode_error_handler)
 return space.newtuple([space.newbytes(result.encode('utf8')), 
space.newint(utf8len)])
 wrap_encoder.__name__ = func.__name__
 globals()[name] = wrap_encoder
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py 
b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -1290,7 +1290,7 @@
 
 def text_w(self, u):
 assert isinstance(u, unicode)
-return FakeUnicode(u)
+return FakeUnicode(u).encode('utf8')
 
 def bytes_w(self, string):
 assert isinstance(string, str)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy unicode-utf8-py3: modify never used rpython surrogate_in_utf8 to return index

2018-07-11 Thread mattip
Author: Matti Picus 
Branch: unicode-utf8-py3
Changeset: r94845:4c9e67d171a9
Date: 2018-07-11 06:46 -0700
http://bitbucket.org/pypy/pypy/changeset/4c9e67d171a9/

Log:modify never used rpython surrogate_in_utf8 to return index

diff --git a/rpython/rlib/rutf8.py b/rpython/rlib/rutf8.py
--- a/rpython/rlib/rutf8.py
+++ b/rpython/rlib/rutf8.py
@@ -471,8 +471,8 @@
 """
 for i in range(len(value) - 2):
 if value[i] == '\xed' and value[i + 1] >= '\xa0':
-return True
-return False
+return i
+return -1
 
 
 UTF8_INDEX_STORAGE = lltype.GcArray(lltype.Struct('utf8_loc_elem',
diff --git a/rpython/rlib/test/test_rutf8.py b/rpython/rlib/test/test_rutf8.py
--- a/rpython/rlib/test/test_rutf8.py
+++ b/rpython/rlib/test/test_rutf8.py
@@ -152,7 +152,7 @@
 @example([u'\ud800', u'\udc00'])
 def test_surrogate_in_utf8(unichars):
 uni = ''.join([u.encode('utf8') for u in unichars])
-result = rutf8.surrogate_in_utf8(uni)
+result = rutf8.surrogate_in_utf8(uni) < 0
 expected = any(uch for uch in unichars if u'\ud800' <= uch <= u'\udfff')
 assert result == expected
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy unicode-utf8-py3: surrogate and illegal unicode handling

2018-07-11 Thread mattip
Author: Matti Picus 
Branch: unicode-utf8-py3
Changeset: r94846:9cf4fc74394c
Date: 2018-07-11 06:49 -0700
http://bitbucket.org/pypy/pypy/changeset/9cf4fc74394c/

Log:surrogate and illegal unicode handling

diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -29,11 +29,17 @@
  space.newtext(msg)]))
 return raise_unicode_exception_decode
 
+def decode_never_raise(errors, encoding, msg, s, startingpos, endingpos):
+ux = ['\ux' + hex(ord(x))[2:].upper() for x in s[startingpos:endingpos]]
+return ''.join(ux), endingpos
+
 @specialize.memo()
 def encode_error_handler(space):
 # Fast version of the "strict" errors handler.
 def raise_unicode_exception_encode(errors, encoding, msg, utf8,
startingpos, endingpos):
+if isinstance(utf8, unicode):
+utf8 = utf8.encode('utf8')
 u_len = rutf8.get_utf8_length(utf8)
 raise OperationError(space.w_UnicodeEncodeError,
  space.newtuple([space.newtext(encoding),
@@ -993,7 +999,7 @@
 # Surrogate-preserving utf-8 decoding.  Assuming there is no
 # encoding error, it should always be reversible, and the reverse is
 # encode_utf8sp().
-return str_decode_utf8(string, "string", True, decode_error_handler(space),
+return str_decode_utf8(string, "string", True, decode_never_raise,
allow_surrogates=True)
 
 
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -1187,22 +1187,26 @@
 
 
 def encode_object(space, w_object, encoding, errors):
+utf8 = space.utf8_w(w_object)
+idx = rutf8.surrogate_in_utf8(utf8)
+if idx >= 0:
+eh = unicodehelper.encode_error_handler(space)
+eh(None, "utf8", "surrogates not allowed", utf8,
+idx, idx + 1)
 if errors is None or errors == 'strict':
 if encoding is None or encoding == 'utf-8':
-utf8 = space.utf8_w(w_object)
-if rutf8.has_surrogates(utf8):
-utf8 = rutf8.reencode_utf8_with_surrogates(utf8)
+#if rutf8.has_surrogates(utf8):
+#utf8 = rutf8.reencode_utf8_with_surrogates(utf8)
 return space.newbytes(utf8)
 elif encoding == 'ascii':
-s = space.utf8_w(w_object)
 try:
-rutf8.check_ascii(s)
+rutf8.check_ascii(utf8)
 except rutf8.CheckError as a:
 eh = unicodehelper.encode_error_handler(space)
-eh(None, "ascii", "ordinal not in range(128)", s,
+eh(None, "ascii", "ordinal not in range(128)", utf8,
 a.pos, a.pos + 1)
 assert False, "always raises"
-return space.newbytes(s)
+return space.newbytes(utf8)
 
 from pypy.module._codecs.interp_codecs import encode_text
 if encoding is None:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: merge default into py3.5

2018-07-11 Thread mattip
Author: Matti Picus 
Branch: py3.5
Changeset: r94849:d367d9785b64
Date: 2018-07-11 09:20 -0500
http://bitbucket.org/pypy/pypy/changeset/d367d9785b64/

Log:merge default into py3.5

diff --git a/lib_pypy/cffi.egg-info/PKG-INFO b/lib_pypy/cffi.egg-info/PKG-INFO
--- a/lib_pypy/cffi.egg-info/PKG-INFO
+++ b/lib_pypy/cffi.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: cffi
-Version: 1.11.5
+Version: 1.12.0
 Summary: Foreign Function Interface for Python calling C code.
 Home-page: http://cffi.readthedocs.org
 Author: Armin Rigo, Maciej Fijalkowski
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI
 from .error import CDefError, FFIError, VerificationError, VerificationMissing
 
-__version__ = "1.11.5"
-__version_info__ = (1, 11, 5)
+__version__ = "1.12.0"
+__version_info__ = (1, 12, 0)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h
--- a/lib_pypy/cffi/_embedding.h
+++ b/lib_pypy/cffi/_embedding.h
@@ -221,7 +221,7 @@
 
 if (f != NULL && f != Py_None) {
 PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-   "\ncompiled with cffi version: 1.11.5"
+   "\ncompiled with cffi version: 1.12.0"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
diff --git a/lib_pypy/cffi/api.py b/lib_pypy/cffi/api.py
--- a/lib_pypy/cffi/api.py
+++ b/lib_pypy/cffi/api.py
@@ -96,18 +96,21 @@
 self.CData, self.CType = backend._get_types()
 self.buffer = backend.buffer
 
-def cdef(self, csource, override=False, packed=False):
+def cdef(self, csource, override=False, packed=False, pack=None):
 """Parse the given C source.  This registers all declared functions,
 types, and global variables.  The functions and global variables can
 then be accessed via either 'ffi.dlopen()' or 'ffi.verify()'.
 The types can be used in 'ffi.new()' and other functions.
 If 'packed' is specified as True, all structs declared inside this
 cdef are packed, i.e. laid out without any field alignment at all.
+Alternatively, 'pack' can be a small integer, and requests for
+alignment greater than that are ignored (pack=1 is equivalent to
+packed=True).
 """
-self._cdef(csource, override=override, packed=packed)
+self._cdef(csource, override=override, packed=packed, pack=pack)
 
-def embedding_api(self, csource, packed=False):
-self._cdef(csource, packed=packed, dllexport=True)
+def embedding_api(self, csource, packed=False, pack=None):
+self._cdef(csource, packed=packed, pack=pack, dllexport=True)
 if self._embedding is None:
 self._embedding = ''
 
diff --git a/lib_pypy/cffi/backend_ctypes.py b/lib_pypy/cffi/backend_ctypes.py
--- a/lib_pypy/cffi/backend_ctypes.py
+++ b/lib_pypy/cffi/backend_ctypes.py
@@ -730,7 +730,8 @@
 return self._new_struct_or_union('union', name, ctypes.Union)
 
 def complete_struct_or_union(self, CTypesStructOrUnion, fields, tp,
- totalsize=-1, totalalignment=-1, sflags=0):
+ totalsize=-1, totalalignment=-1, sflags=0,
+ pack=0):
 if totalsize >= 0 or totalalignment >= 0:
 raise NotImplementedError("the ctypes backend of CFFI does not 
support "
   "structures completed by verify(); 
please "
@@ -751,6 +752,8 @@
 bfield_types[fname] = Ellipsis
 if sflags & 8:
 struct_or_union._pack_ = 1
+elif pack:
+struct_or_union._pack_ = pack
 struct_or_union._fields_ = cfields
 CTypesStructOrUnion._bfield_types = bfield_types
 #
diff --git a/lib_pypy/cffi/cparser.py b/lib_pypy/cffi/cparser.py
--- a/lib_pypy/cffi/cparser.py
+++ b/lib_pypy/cffi/cparser.py
@@ -306,11 +306,25 @@
 msg = 'parse error\n%s' % (msg,)
 raise CDefError(msg)
 
-def parse(self, csource, override=False, packed=False, dllexport=False):
+def parse(self, csource, override=False, packed=False, pack=None,
+dllexport=False):
+if packed:
+if packed != True:
+raise ValueError("'packed' should be False or True; use "
+ "'pack' to give another value")
+if pack:
+raise ValueError("cannot give both 'pack' and 'packed'")
+pack = 1
+elif pack:
+if pack & (pack - 1):
+raise ValueError("'pack' must be a powe

[pypy-commit] pypy cppyy-packaging: do not allow instantiation of namespaces

2018-07-11 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94850:5b42ae224e5e
Date: 2018-07-11 22:28 -0700
http://bitbucket.org/pypy/pypy/changeset/5b42ae224e5e/

Log:do not allow instantiation of 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
@@ -73,7 +73,8 @@
 
 # C++ namespace base class (the C++ class base class defined in 
_post_import_startup)
 class CPPNamespace(with_metaclass(CPPNamespaceMeta, object)):
- pass
+def __init__(self):
+raise TypeError("cannot instantiate namespace '%s'", self.__cppname__)
 
 
 # TODO: this can be moved to the interp level (and share template argument
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
@@ -148,6 +148,8 @@
 assert gbl.a_ns.d_ns.e_class.f_class.s_f  == 66
 assert gbl.a_ns.d_ns.e_class.f_class().m_f== -6
 
+raises(TypeError, gbl.a_ns)
+
 def test03a_namespace_lookup_on_update(self):
 """Test whether namespaces can be shared across dictionaries."""
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cppyy-packaging: bring in a load of tests from cppyy/test

2018-07-11 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94852:8fe8681b8102
Date: 2018-07-11 22:41 -0700
http://bitbucket.org/pypy/pypy/changeset/8fe8681b8102/

Log:bring in a load of tests from cppyy/test

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
@@ -4,20 +4,32 @@
 
 
 // for testing of default arguments
-#define IMPLEMENT_DEFAULTER_CLASS(type, tname)   \
+#define IMPLEMENT_DEFAULTERS(type, tname)\
 tname##_defaulter::tname##_defaulter(type a, type b, type c) {   \
-   m_a = a; m_b = b; m_c = c;\
+m_a = a; m_b = b; m_c = c;   \
+}\
+type tname##_defaulter_func(int idx, type a, type b, type c) {   \
+if (idx == 0) return a;  \
+if (idx == 1) return b;  \
+if (idx == 2) return c;  \
+return (type)idx;\
 }
-IMPLEMENT_DEFAULTER_CLASS(short, short)
-IMPLEMENT_DEFAULTER_CLASS(unsigned short, ushort)
-IMPLEMENT_DEFAULTER_CLASS(int, int)
-IMPLEMENT_DEFAULTER_CLASS(unsigned, uint)
-IMPLEMENT_DEFAULTER_CLASS(long, long)
-IMPLEMENT_DEFAULTER_CLASS(unsigned long, ulong)
-IMPLEMENT_DEFAULTER_CLASS(long long, llong)
-IMPLEMENT_DEFAULTER_CLASS(unsigned long long, ullong)
-IMPLEMENT_DEFAULTER_CLASS(float, float)
-IMPLEMENT_DEFAULTER_CLASS(double, double)
+IMPLEMENT_DEFAULTERS(short, short)
+IMPLEMENT_DEFAULTERS(unsigned short, ushort)
+IMPLEMENT_DEFAULTERS(int, int)
+IMPLEMENT_DEFAULTERS(unsigned, uint)
+IMPLEMENT_DEFAULTERS(long, long)
+IMPLEMENT_DEFAULTERS(unsigned long, ulong)
+IMPLEMENT_DEFAULTERS(long long, llong)
+IMPLEMENT_DEFAULTERS(unsigned long long, ullong)
+IMPLEMENT_DEFAULTERS(float, float)
+IMPLEMENT_DEFAULTERS(double, double)
+
+std::string string_defaulter_func(int idx, const std::string& name1, 
std::string name2) {
+if (idx == 0) return name1;
+if (idx == 1) return name2;
+return "mies";
+}
 
 
 // for esoteric inheritance testing
@@ -77,11 +89,11 @@
 double my_global_array[500];
 static double sd = 1234.;
 double* my_global_ptr = &sd;
+const char my_global_string2[] = "zus jet teun";
 some_int_holder my_global_int_holders[5] = {
 some_int_holder(13), some_int_holder(42), some_int_holder(88),
 some_int_holder(-1), some_int_holder(17) };
 
-
 // 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
@@ -4,24 +4,27 @@
 
 
 //===
-#define DECLARE_DEFAULTER_CLASS(type, tname)\
+#define DECLARE_DEFAULTERS(type, tname) \
 class tname##_defaulter {   \
 public: \
 tname##_defaulter(type a = 11, type b = 22, type c = 33);   \
 \
 public: \
 type m_a, m_b, m_c; \
-};
-DECLARE_DEFAULTER_CLASS(short, short)   // for testing of default arguments
-DECLARE_DEFAULTER_CLASS(unsigned short, ushort)
-DECLARE_DEFAULTER_CLASS(int, int)
-DECLARE_DEFAULTER_CLASS(unsigned, uint)
-DECLARE_DEFAULTER_CLASS(long, long)
-DECLARE_DEFAULTER_CLASS(unsigned long, ulong)
-DECLARE_DEFAULTER_CLASS(long long, llong)
-DECLARE_DEFAULTER_CLASS(unsigned long long, ullong)
-DECLARE_DEFAULTER_CLASS(float, float)
-DECLARE_DEFAULTER_CLASS(double, double)
+};  \
+type tname##_defaulter_func(int idx = 0, type a = 11, type b = 22, type c = 
33);
+DECLARE_DEFAULTERS(short, short)   // for testing of default arguments
+DECLARE_DEFAULTERS(unsigned short, ushort)
+DECLARE_DEFAULTERS(int, int)
+DECLARE_DEFAULTERS(unsigned, uint)
+DECLARE_DEFAULTERS(long, long)
+DECLARE_DEFAULTERS(unsigned long, ulong)
+DECLARE_DEFAULTERS(long long, llong)
+DECLARE_DEFAULTERS(unsigned long long, ullong)
+DECLARE_DEFAULTERS(float, float)
+DECLARE_DEFAULTERS(double, double)
+
+std::string string_defaulter_func(int idx, const std::string& name1 = "aap", 
std::string name2 = "noot");
 
 
 //===
@@ -274,7 +277,8 @@
 extern d

[pypy-commit] pypy cppyy-packaging: factor out abstract class constructors

2018-07-11 Thread wlav
Author: Wim Lavrijsen 
Branch: cppyy-packaging
Changeset: r94851:534891668842
Date: 2018-07-11 22:29 -0700
http://bitbucket.org/pypy/pypy/changeset/534891668842/

Log:factor out abstract class constructors

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
@@ -657,11 +657,6 @@
 @unwrap_spec(args_w='args_w')
 def call_args(self, args_w):
 jit.promote(self)
-# TODO: factor out the following:
-if capi.c_is_abstract(self.space, self.scope.handle):
-raise oefmt(self.space.w_TypeError,
-"cannot instantiate abstract class '%s'",
-self.scope.name)
 cppinstance = self.space.interp_w(W_CPPInstance, args_w[0])
 w_result = self.call_impl(rffi.cast(capi.C_OBJECT, self.scope.handle), 
args_w[1:])
 newthis = rffi.cast(capi.C_OBJECT, self.space.uint_w(w_result))
@@ -679,6 +674,23 @@
 __doc__= GetSetProperty(W_CPPConstructorOverload.fget_doc)
 )
 
+class W_CPPAbstractConstructorOverload(W_CPPOverload):
+_attrs_ = []
+
+@unwrap_spec(args_w='args_w')
+def call_args(self, args_w):
+raise oefmt(self.space.w_TypeError,
+"cannot instantiate abstract class '%s'", self.scope.name)
+
+def __repr__(self):
+return "W_CPPAbstractConstructorOverload"
+
+W_CPPAbstractConstructorOverload.typedef = TypeDef(
+'CPPAbstractConstructorOverload',
+__get__= interp2app(W_CPPConstructorOverload.descr_get),
+__call__   = interp2app(W_CPPConstructorOverload.call_args),
+)
+
 
 class TemplateOverloadMixin(object):
 """Mixin to instantiate templated methods/functions."""
@@ -1210,7 +1222,10 @@
 ftype = ftype_tmp[pyname]
 CPPMethodSort(methods).sort()
 if ftype & FUNCTION_IS_CONSTRUCTOR:
-overload = W_CPPConstructorOverload(self.space, self, 
methods[:])
+if capi.c_is_abstract(self.space, self.handle):
+overload = W_CPPAbstractConstructorOverload(self.space, 
self, methods[:])
+else:
+overload = W_CPPConstructorOverload(self.space, self, 
methods[:])
 elif ftype & FUNCTION_IS_STATIC:
 if ftype & FUNCTION_IS_TEMPLATE:
 cppname = capi.c_method_name(self.space, 
methods[0].cppmethod)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit