[pypy-commit] pypy default: merge heads
arigo
noreply at buildbot.pypy.org
Tue Jan 21 16:19:34 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r68817:cda44e90c717
Date: 2014-01-21 16:18 +0100
http://bitbucket.org/pypy/pypy/changeset/cda44e90c717/
Log: merge heads
diff --git a/pypy/doc/_ref.txt b/pypy/doc/_ref.txt
--- a/pypy/doc/_ref.txt
+++ b/pypy/doc/_ref.txt
@@ -109,6 +109,4 @@
.. _`rpython/translator/c/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/
.. _`rpython/translator/c/src/stacklet/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/
.. _`rpython/translator/c/src/stacklet/stacklet.h`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/stacklet.h
-.. _`rpython/translator/cli/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/cli/
-.. _`rpython/translator/jvm/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/jvm/
.. _`rpython/translator/tool/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/tool/
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -167,7 +167,7 @@
def run(self):
"""Start this frame's execution."""
if self.getcode().co_flags & pycode.CO_GENERATOR:
- if self.getcode().co_flags & pycode.CO_YIELD_INSIDE_TRY:
+ if 1:# self.getcode().co_flags & pycode.CO_YIELD_INSIDE_TRY:
from pypy.interpreter.generator import GeneratorIteratorWithDel
return self.space.wrap(GeneratorIteratorWithDel(self))
else:
diff --git a/pypy/module/_cffi_backend/ctypestruct.py b/pypy/module/_cffi_backend/ctypestruct.py
--- a/pypy/module/_cffi_backend/ctypestruct.py
+++ b/pypy/module/_cffi_backend/ctypestruct.py
@@ -33,7 +33,7 @@
if self.fields_dict is None:
space = self.space
raise operationerrfmt(w_errorcls or space.w_TypeError,
- "'%s' is not completed yet", self.name)
+ "'%s' is opaque or not completed yet", self.name)
def _alignof(self):
self.check_complete(w_errorcls=self.space.w_ValueError)
diff --git a/pypy/module/_rawffi/test/test__rawffi.py b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -1,6 +1,5 @@
from rpython.translator.platform import platform
from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.conftest import option
from pypy.module._rawffi.interp_rawffi import TYPEMAP, TYPEMAP_FLOAT_LETTERS
from pypy.module._rawffi.tracker import Tracker
@@ -1133,15 +1132,6 @@
def setup_class(cls):
cls.w_sizes_and_alignments = cls.space.wrap(dict(
[(k, (v.c_size, v.c_alignment)) for k,v in TYPEMAP.iteritems()]))
- #
- # detect if we're running on PyPy with DO_TRACING not compiled in
- if option.runappdirect:
- try:
- import _rawffi
- _rawffi._num_of_allocated_objects()
- except (ImportError, RuntimeError), e:
- py.test.skip(str(e))
- #
Tracker.DO_TRACING = True
def test_structure_autofree(self):
diff --git a/pypy/module/struct/__init__.py b/pypy/module/struct/__init__.py
--- a/pypy/module/struct/__init__.py
+++ b/pypy/module/struct/__init__.py
@@ -49,11 +49,12 @@
'calcsize': 'interp_struct.calcsize',
'pack': 'interp_struct.pack',
'unpack': 'interp_struct.unpack',
- }
+
+ 'Struct': 'interp_struct.W_Struct',
+ }
appleveldefs = {
'error': 'app_struct.error',
'pack_into': 'app_struct.pack_into',
'unpack_from': 'app_struct.unpack_from',
- 'Struct': 'app_struct.Struct',
- }
+ }
diff --git a/pypy/module/struct/app_struct.py b/pypy/module/struct/app_struct.py
--- a/pypy/module/struct/app_struct.py
+++ b/pypy/module/struct/app_struct.py
@@ -4,6 +4,7 @@
"""
import struct
+
class error(Exception):
"""Exception raised on various occasions; argument is a string
describing what is wrong."""
@@ -21,21 +22,3 @@
raise error("unpack_from requires a buffer of at least %d bytes"
% (size,))
return struct.unpack(fmt, data)
-
-# XXX inefficient
-class Struct(object):
- def __init__(self, format):
- self.format = format
- self.size = struct.calcsize(format)
-
- def pack(self, *args):
- return struct.pack(self.format, *args)
-
- def unpack(self, s):
- return struct.unpack(self.format, s)
-
- def pack_into(self, buffer, offset, *args):
- return pack_into(self.format, buffer, offset, *args)
-
- def unpack_from(self, buffer, offset=0):
- return unpack_from(self.format, buffer, offset)
diff --git a/pypy/module/struct/interp_struct.py b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -1,15 +1,22 @@
-from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.error import OperationError
-from pypy.module.struct.formatiterator import PackFormatIterator, UnpackFormatIterator
from rpython.rlib import jit
from rpython.rlib.rstruct.error import StructError, StructOverflowError
from rpython.rlib.rstruct.formatiterator import CalcSizeFormatIterator
+from rpython.tool.sourcetools import func_with_new_name
+
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.typedef import TypeDef, interp_attrproperty
+from pypy.module.struct.formatiterator import (
+ PackFormatIterator, UnpackFormatIterator
+)
@unwrap_spec(format=str)
def calcsize(space, format):
return space.wrap(_calcsize(space, format))
+
def _calcsize(space, format):
fmtiter = CalcSizeFormatIterator()
try:
@@ -52,3 +59,44 @@
w_error = space.getattr(w_module, space.wrap('error'))
raise OperationError(w_error, space.wrap(e.msg))
return space.newtuple(fmtiter.result_w[:])
+
+
+class W_Struct(W_Root):
+ _immutable_fields_ = ["format", "size"]
+
+ def __init__(self, space, format):
+ self.format = format
+ self.size = _calcsize(space, format)
+
+ @unwrap_spec(format=str)
+ def descr__new__(space, w_subtype, format):
+ self = space.allocate_instance(W_Struct, w_subtype)
+ W_Struct.__init__(self, space, format)
+ return self
+
+ def wrap_struct_method(name):
+ def impl(self, space, __args__):
+ w_module = space.getbuiltinmodule('struct')
+ w_method = space.getattr(w_module, space.wrap(name))
+ return space.call_obj_args(
+ w_method, space.wrap(self.format), __args__
+ )
+
+ return func_with_new_name(impl, 'descr_' + name)
+
+ descr_pack = wrap_struct_method("pack")
+ descr_unpack = wrap_struct_method("unpack")
+ descr_pack_into = wrap_struct_method("pack_into")
+ descr_unpack_from = wrap_struct_method("unpack_from")
+
+
+W_Struct.typedef = TypeDef("Struct",
+ __new__=interp2app(W_Struct.descr__new__.im_func),
+ format=interp_attrproperty("format", cls=W_Struct),
+ size=interp_attrproperty("size", cls=W_Struct),
+
+ pack=interp2app(W_Struct.descr_pack),
+ unpack=interp2app(W_Struct.descr_unpack),
+ pack_into=interp2app(W_Struct.descr_pack_into),
+ unpack_from=interp2app(W_Struct.descr_unpack_from),
+)
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
@@ -35,13 +35,7 @@
if (isinstance(self, W_BytearrayObject) and
space.isinstance_w(w_sub, space.w_int)):
char = space.int_w(w_sub)
- if not 0 <= char < 256:
- raise OperationError(space.w_ValueError,
- space.wrap("byte must be in range(0, 256)"))
- for c in self.data:
- if ord(c) == char:
- return space.w_True
- return space.w_False
+ return _descr_contains_bytearray(self.data, space, char)
return space.newbool(self._val(space).find(self._op_val(space, w_sub)) >= 0)
def descr_add(self, space, w_other):
@@ -79,7 +73,7 @@
assert start >= 0 and stop >= 0
return self._sliced(space, selfvalue, start, stop, self)
else:
- ret = [selfvalue[start + i*step] for i in range(sl)]
+ ret = _descr_getslice_slowpath(selfvalue, start, step, sl)
return self._new_from_list(ret)
index = space.getindex_w(w_index, space.w_IndexError, "string index")
@@ -253,17 +247,21 @@
return self._is_generic(space, '_isdigit')
# this is only for bytes and bytesarray: unicodeobject overrides it
+ def _descr_islower_slowpath(self, space, v):
+ cased = False
+ for idx in range(len(v)):
+ if self._isupper(v[idx]):
+ return False
+ elif not cased and self._islower(v[idx]):
+ cased = True
+ return cased
+
def descr_islower(self, space):
v = self._val(space)
if len(v) == 1:
c = v[0]
return space.newbool(self._islower(c))
- cased = False
- for idx in range(len(v)):
- if self._isupper(v[idx]):
- return space.w_False
- elif not cased and self._islower(v[idx]):
- cased = True
+ cased = self._descr_islower_slowpath(space, v)
return space.newbool(cased)
def descr_isspace(self, space):
@@ -291,17 +289,21 @@
return space.newbool(cased)
# this is only for bytes and bytesarray: unicodeobject overrides it
+ def _descr_isupper_slowpath(self, space, v):
+ cased = False
+ for idx in range(len(v)):
+ if self._islower(v[idx]):
+ return False
+ elif not cased and self._isupper(v[idx]):
+ cased = True
+ return cased
+
def descr_isupper(self, space):
v = self._val(space)
if len(v) == 1:
c = v[0]
return space.newbool(self._isupper(c))
- cased = False
- for idx in range(len(v)):
- if self._islower(v[idx]):
- return space.w_False
- elif not cased and self._isupper(v[idx]):
- cased = True
+ cased = self._descr_isupper_slowpath(space, v)
return space.newbool(cased)
def descr_join(self, space, w_list):
@@ -677,3 +679,19 @@
def descr_getnewargs(self, space):
return space.newtuple([self._new(self._val(space))])
+
+# ____________________________________________________________
+# helpers for slow paths, moved out because they contain loops
+
+def _descr_contains_bytearray(data, space, char):
+ if not 0 <= char < 256:
+ raise OperationError(space.w_ValueError,
+ space.wrap("byte must be in range(0, 256)"))
+ for c in data:
+ if ord(c) == char:
+ return space.w_True
+ return space.w_False
+
+ at specialize.argtype(0)
+def _descr_getslice_slowpath(selfvalue, start, step, sl):
+ return [selfvalue[start + i*step] for i in range(sl)]
diff --git a/rpython/jit/backend/llsupport/gc.py b/rpython/jit/backend/llsupport/gc.py
--- a/rpython/jit/backend/llsupport/gc.py
+++ b/rpython/jit/backend/llsupport/gc.py
@@ -454,17 +454,19 @@
unicode_ofs_length = self.unicode_descr.lendescr.offset
def malloc_str(length):
+ type_id = llop.extract_ushort(llgroup.HALFWORD, str_type_id)
return llop1.do_malloc_varsize_clear(
llmemory.GCREF,
- str_type_id, length, str_basesize, str_itemsize,
+ type_id, length, str_basesize, str_itemsize,
str_ofs_length)
self.generate_function('malloc_str', malloc_str,
[lltype.Signed])
def malloc_unicode(length):
+ type_id = llop.extract_ushort(llgroup.HALFWORD, unicode_type_id)
return llop1.do_malloc_varsize_clear(
llmemory.GCREF,
- unicode_type_id, length, unicode_basesize, unicode_itemsize,
+ type_id, length, unicode_basesize, unicode_itemsize,
unicode_ofs_length)
self.generate_function('malloc_unicode', malloc_unicode,
[lltype.Signed])
diff --git a/rpython/rlib/ropenssl.py b/rpython/rlib/ropenssl.py
--- a/rpython/rlib/ropenssl.py
+++ b/rpython/rlib/ropenssl.py
@@ -56,9 +56,17 @@
ASN1_STRING = lltype.Ptr(lltype.ForwardReference())
ASN1_ITEM = rffi.COpaquePtr('ASN1_ITEM')
-ASN1_ITEM_EXP = lltype.Ptr(lltype.FuncType([], ASN1_ITEM))
X509_NAME = rffi.COpaquePtr('X509_NAME')
+class CConfigBootstrap:
+ _compilation_info_ = eci
+ OPENSSL_EXPORT_VAR_AS_FUNCTION = rffi_platform.Defined(
+ "OPENSSL_EXPORT_VAR_AS_FUNCTION")
+if rffi_platform.configure(CConfigBootstrap)["OPENSSL_EXPORT_VAR_AS_FUNCTION"]:
+ ASN1_ITEM_EXP = lltype.Ptr(lltype.FuncType([], ASN1_ITEM))
+else:
+ ASN1_ITEM_EXP = ASN1_ITEM
+
class CConfig:
_compilation_info_ = eci
@@ -128,8 +136,6 @@
('block_size', rffi.INT)])
EVP_MD_SIZE = rffi_platform.SizeOf('EVP_MD')
EVP_MD_CTX_SIZE = rffi_platform.SizeOf('EVP_MD_CTX')
- OPENSSL_EXPORT_VAR_AS_FUNCTION = rffi_platform.Defined(
- "OPENSSL_EXPORT_VAR_AS_FUNCTION")
OBJ_NAME_st = rffi_platform.Struct(
'OBJ_NAME',
@@ -259,10 +265,7 @@
ssl_external('i2a_ASN1_INTEGER', [BIO, ASN1_INTEGER], rffi.INT)
ssl_external('ASN1_item_d2i',
[rffi.VOIDP, rffi.CCHARPP, rffi.LONG, ASN1_ITEM], rffi.VOIDP)
-if OPENSSL_EXPORT_VAR_AS_FUNCTION:
- ssl_external('ASN1_ITEM_ptr', [ASN1_ITEM_EXP], ASN1_ITEM, macro=True)
-else:
- ssl_external('ASN1_ITEM_ptr', [rffi.VOIDP], ASN1_ITEM, macro=True)
+ssl_external('ASN1_ITEM_ptr', [ASN1_ITEM_EXP], ASN1_ITEM, macro=True)
ssl_external('sk_GENERAL_NAME_num', [GENERAL_NAMES], rffi.INT,
macro=True)
diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -167,7 +167,7 @@
#
# This list corresponds to the operations implemented by the LLInterpreter.
# Note that many exception-raising operations can be replaced by calls
-# to helper functions in rpython.rtyper.raisingops.raisingops.
+# to helper functions in rpython.rtyper.raisingops.
# ***** Run test_lloperation after changes. *****
LL_OPERATIONS = {
diff --git a/rpython/rtyper/raisingops/raisingops.py b/rpython/rtyper/raisingops.py
rename from rpython/rtyper/raisingops/raisingops.py
rename to rpython/rtyper/raisingops.py
diff --git a/rpython/rtyper/raisingops/__init__.py b/rpython/rtyper/raisingops/__init__.py
deleted file mode 100644
diff --git a/rpython/translator/backendopt/raisingop2direct_call.py b/rpython/translator/backendopt/raisingop2direct_call.py
--- a/rpython/translator/backendopt/raisingop2direct_call.py
+++ b/rpython/translator/backendopt/raisingop2direct_call.py
@@ -1,5 +1,5 @@
from rpython.translator.backendopt.support import log, all_operations, annotate
-import rpython.rtyper.raisingops.raisingops
+import rpython.rtyper.raisingops
log = log.raisingop2directcall
@@ -15,7 +15,7 @@
def raisingop2direct_call(translator, graphs=None):
"""search for operations that could raise an exception and change that
- operation into a direct_call to a function from the raisingops directory.
+ operation into a direct_call to a function from the raisingops module.
This function also needs to be annotated and specialized.
note: this could be extended to allow for any operation to be changed into
@@ -30,7 +30,7 @@
for op in all_operations(graphs):
if not is_raisingop(op):
continue
- func = getattr(rpython.rtyper.raisingops.raisingops, op.opname, None)
+ func = getattr(rpython.rtyper.raisingops, op.opname, None)
if not func:
log.warning("%s not found" % op.opname)
continue
diff --git a/rpython/translator/driver.py b/rpython/translator/driver.py
--- a/rpython/translator/driver.py
+++ b/rpython/translator/driver.py
@@ -33,13 +33,6 @@
# TODO:
# sanity-checks using states
-_BACKEND_TO_TYPESYSTEM = {
- 'c': 'lltype',
-}
-
-def backend_to_typesystem(backend):
- return _BACKEND_TO_TYPESYSTEM[backend]
-
# set of translation steps to profile
PROFILE = set([])
@@ -132,7 +125,7 @@
if backend == postfix:
expose_task(task, explicit_task)
elif ts:
- if ts == backend_to_typesystem(postfix):
+ if ts == 'lltype':
expose_task(explicit_task)
else:
expose_task(explicit_task)
More information about the pypy-commit
mailing list