Author: Armin Rigo <[email protected]>
Branch: cpyext-gc-support-2
Changeset: r82407:f174145a8b9b
Date: 2016-02-22 18:03 +0000
http://bitbucket.org/pypy/pypy/changeset/f174145a8b9b/
Log: hg merge default
diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -22,6 +22,7 @@
^pypy/module/cpyext/test/.+\.obj$
^pypy/module/cpyext/test/.+\.manifest$
^pypy/module/test_lib_pypy/ctypes_tests/.+\.o$
+^pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test\.o$
^pypy/module/cppyy/src/.+\.o$
^pypy/module/cppyy/bench/.+\.so$
^pypy/module/cppyy/bench/.+\.root$
@@ -35,7 +36,6 @@
^pypy/module/test_lib_pypy/cffi_tests/__pycache__.+$
^pypy/doc/.+\.html$
^pypy/doc/config/.+\.rst$
-^pypy/doc/basicblock\.asc$
^pypy/doc/.+\.svninfo$
^rpython/translator/c/src/libffi_msvc/.+\.obj$
^rpython/translator/c/src/libffi_msvc/.+\.dll$
@@ -45,53 +45,33 @@
^rpython/translator/c/src/cjkcodecs/.+\.obj$
^rpython/translator/c/src/stacklet/.+\.o$
^rpython/translator/c/src/.+\.o$
-^rpython/translator/jvm/\.project$
-^rpython/translator/jvm/\.classpath$
-^rpython/translator/jvm/eclipse-bin$
-^rpython/translator/jvm/src/pypy/.+\.class$
-^rpython/translator/benchmark/docutils$
-^rpython/translator/benchmark/templess$
-^rpython/translator/benchmark/gadfly$
-^rpython/translator/benchmark/mako$
-^rpython/translator/benchmark/bench-custom\.benchmark_result$
-^rpython/translator/benchmark/shootout_benchmarks$
+^rpython/translator/llvm/.+\.so$
^rpython/translator/goal/target.+-c$
^rpython/translator/goal/.+\.exe$
^rpython/translator/goal/.+\.dll$
^pypy/goal/pypy-translation-snapshot$
^pypy/goal/pypy-c
-^pypy/goal/pypy-jvm
-^pypy/goal/pypy-jvm.jar
^pypy/goal/.+\.exe$
^pypy/goal/.+\.dll$
^pypy/goal/.+\.lib$
^pypy/_cache$
-^pypy/doc/statistic/.+\.html$
-^pypy/doc/statistic/.+\.eps$
-^pypy/doc/statistic/.+\.pdf$
-^rpython/translator/cli/src/pypylib\.dll$
-^rpython/translator/cli/src/query\.exe$
-^rpython/translator/cli/src/main\.exe$
+^lib-python/2.7/lib2to3/.+\.pickle$
^lib_pypy/__pycache__$
^lib_pypy/ctypes_config_cache/_.+_cache\.py$
^lib_pypy/ctypes_config_cache/_.+_.+_\.py$
^lib_pypy/_libmpdec/.+.o$
-^rpython/translator/cli/query-descriptions$
^pypy/doc/discussion/.+\.html$
^include/.+\.h$
^include/.+\.inl$
^pypy/doc/_build/.*$
^pypy/doc/config/.+\.html$
^pypy/doc/config/style\.css$
-^pypy/doc/jit/.+\.html$
-^pypy/doc/jit/style\.css$
^pypy/doc/image/lattice1\.png$
^pypy/doc/image/lattice2\.png$
^pypy/doc/image/lattice3\.png$
^pypy/doc/image/stackless_informal\.png$
^pypy/doc/image/parsing_example.+\.png$
^rpython/doc/_build/.*$
-^pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test\.o$
^compiled
^.git/
^release/
diff --git a/pypy/interpreter/pyparser/pytokenizer.py
b/pypy/interpreter/pyparser/pytokenizer.py
--- a/pypy/interpreter/pyparser/pytokenizer.py
+++ b/pypy/interpreter/pyparser/pytokenizer.py
@@ -91,6 +91,7 @@
strstart = (0, 0, "")
for line in lines:
lnum = lnum + 1
+ line = universal_newline(line)
pos, max = 0, len(line)
if contstr:
@@ -259,3 +260,14 @@
token_list.append((tokens.ENDMARKER, '', lnum, pos, line))
return token_list
+
+
+def universal_newline(line):
+ # show annotator that indexes below are non-negative
+ line_len_m2 = len(line) - 2
+ if line_len_m2 >= 0 and line[-2] == '\r' and line[-1] == '\n':
+ return line[:line_len_m2] + '\n'
+ line_len_m1 = len(line) - 1
+ if line_len_m1 >= 0 and line[-1] == '\r':
+ return line[:line_len_m1] + '\n'
+ return line
diff --git a/pypy/interpreter/pyparser/test/test_pyparse.py
b/pypy/interpreter/pyparser/test/test_pyparse.py
--- a/pypy/interpreter/pyparser/test/test_pyparse.py
+++ b/pypy/interpreter/pyparser/test/test_pyparse.py
@@ -158,3 +158,10 @@
def test_print_function(self):
self.parse("from __future__ import print_function\nx = print\n")
+
+ def test_universal_newlines(self):
+ fmt = 'stuff = """hello%sworld"""'
+ expected_tree = self.parse(fmt % '\n')
+ for linefeed in ["\r\n","\r"]:
+ tree = self.parse(fmt % linefeed)
+ assert expected_tree == tree
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -156,20 +156,6 @@
get_unique_interplevel_subclass._annspecialcase_ = "specialize:memo"
_subclass_cache = {}
-def enum_interplevel_subclasses(config, cls):
- """Return a list of all the extra interp-level subclasses of 'cls' that
- can be built by get_unique_interplevel_subclass()."""
- result = []
- for flag1 in (False, True):
- for flag2 in (False, True):
- for flag3 in (False, True):
- for flag4 in (False, True):
- result.append(get_unique_interplevel_subclass(
- config, cls, flag1, flag2, flag3, flag4))
- result = dict.fromkeys(result)
- assert len(result) <= 6
- return result.keys()
-
def _getusercls(config, cls, wants_dict, wants_slots, wants_del, weakrefable):
typedef = cls.typedef
if wants_dict and typedef.hasdict:
diff --git a/pypy/module/micronumpy/compile.py
b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -196,6 +196,10 @@
def newfloat(self, f):
return self.float(f)
+ def newslice(self, start, stop, step):
+ return SliceObject(self.int_w(start), self.int_w(stop),
+ self.int_w(step))
+
def le(self, w_obj1, w_obj2):
assert isinstance(w_obj1, boxes.W_GenericBox)
assert isinstance(w_obj2, boxes.W_GenericBox)
diff --git a/pypy/module/micronumpy/strides.py
b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -94,11 +94,13 @@
dim = i
break
if dim >= 0:
- # filter by axis r
- filtr = chunks.pop(dim)
+ # filter by axis dim
+ filtr = chunks[dim]
assert isinstance(filtr, BooleanChunk)
w_arr = w_arr.getitem_filter(space, filtr.w_idx, axis=dim)
arr = w_arr.implementation
+ chunks[dim] = SliceChunk(space.newslice(space.wrap(0),
+ space.wrap(-1), space.w_None))
r = calculate_slice_strides(space, arr.shape, arr.start,
arr.get_strides(), arr.get_backstrides(), chunks)
else:
diff --git a/pypy/module/micronumpy/test/test_ndarray.py
b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -2550,6 +2550,8 @@
assert b.base is None
b = a[:, np.array([True, False, True])]
assert b.base is not None
+ b = a[np.array([True, False]), 0]
+ assert (b ==[0]).all()
def test_scalar_indexing(self):
import numpy as np
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -7,7 +7,7 @@
from pypy.interpreter.astcompiler.misc import mangle
from rpython.rlib.jit import (promote, elidable_promote, we_are_jitted,
- promote_string, elidable, dont_look_inside, unroll_safe)
+ elidable, dont_look_inside, unroll_safe)
from rpython.rlib.objectmodel import current_object_addr_as_int, compute_hash
from rpython.rlib.rarithmetic import intmask, r_uint
@@ -427,7 +427,6 @@
if version_tag is None:
tup = w_self._lookup_where(name)
return tup
- name = promote_string(name)
tup_w = w_self._pure_lookup_where_with_method_cache(name, version_tag)
w_class, w_value = tup_w
if (space.config.objspace.std.withtypeversion and
diff --git a/rpython/jit/codewriter/support.py
b/rpython/jit/codewriter/support.py
--- a/rpython/jit/codewriter/support.py
+++ b/rpython/jit/codewriter/support.py
@@ -246,12 +246,12 @@
def _ll_2_int_floordiv_ovf_zer(x, y):
if y == 0:
raise ZeroDivisionError
- if x == -sys.maxint - 1 and y == -1:
- raise OverflowError
- return llop.int_floordiv(lltype.Signed, x, y)
+ return _ll_2_int_floordiv_ovf(x, y)
def _ll_2_int_floordiv_ovf(x, y):
- if x == -sys.maxint - 1 and y == -1:
+ # intentionally not short-circuited to produce only one guard
+ # and to remove the check fully if one of the arguments is known
+ if (x == -sys.maxint - 1) & (y == -1):
raise OverflowError
return llop.int_floordiv(lltype.Signed, x, y)
@@ -263,12 +263,11 @@
def _ll_2_int_mod_ovf_zer(x, y):
if y == 0:
raise ZeroDivisionError
- if x == -sys.maxint - 1 and y == -1:
- raise OverflowError
- return llop.int_mod(lltype.Signed, x, y)
+ return _ll_2_int_mod_ovf(x, y)
def _ll_2_int_mod_ovf(x, y):
- if x == -sys.maxint - 1 and y == -1:
+ #see comment in _ll_2_int_floordiv_ovf
+ if (x == -sys.maxint - 1) & (y == -1):
raise OverflowError
return llop.int_mod(lltype.Signed, x, y)
diff --git a/rpython/jit/metainterp/test/test_ajit.py
b/rpython/jit/metainterp/test/test_ajit.py
--- a/rpython/jit/metainterp/test/test_ajit.py
+++ b/rpython/jit/metainterp/test/test_ajit.py
@@ -1199,6 +1199,31 @@
(-sys.maxint-1) // (-6) +
100 * 8)
+ def test_overflow_fold_if_divisor_constant(self):
+ import sys
+ from rpython.rtyper.lltypesystem.lloperation import llop
+ myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res'])
+ def f(x, y):
+ res = 0
+ while y > 0:
+ myjitdriver.can_enter_jit(x=x, y=y, res=res)
+ myjitdriver.jit_merge_point(x=x, y=y, res=res)
+ try:
+ res += llop.int_floordiv_ovf(lltype.Signed,
+ x, 2)
+ res += llop.int_mod_ovf(lltype.Signed,
+ x, 2)
+ x += 5
+ except OverflowError:
+ res += 100
+ y -= 1
+ return res
+ res = self.meta_interp(f, [-41, 8])
+ # the guard_true are for the loop condition
+ # the guard_false needed to check whether an overflow can occur have
+ # been folded away
+ self.check_resops(guard_true=2, guard_false=0)
+
def test_isinstance(self):
class A:
pass
diff --git a/rpython/jit/metainterp/test/test_tlc.py
b/rpython/jit/metainterp/test/test_tlc.py
--- a/rpython/jit/metainterp/test/test_tlc.py
+++ b/rpython/jit/metainterp/test/test_tlc.py
@@ -1,5 +1,4 @@
import py
-from rpython.rtyper.module.support import LLSupport
from rpython.jit.tl import tlc
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -3,7 +3,6 @@
import errno
from rpython.rtyper.lltypesystem.rffi import CConstant, CExternVariable, INT
from rpython.rtyper.lltypesystem import lltype, ll2ctypes, rffi
-from rpython.rtyper.module.support import StringTraits, UnicodeTraits
from rpython.rtyper.tool import rffi_platform
from rpython.tool.sourcetools import func_renamer
from rpython.translator.tool.cbuild import ExternalCompilationInfo
@@ -12,7 +11,7 @@
specialize, enforceargs, register_replacement_for, NOT_CONSTANT)
from rpython.rlib.signature import signature
from rpython.rlib import types
-from rpython.annotator.model import s_Str0
+from rpython.annotator.model import s_Str0, s_Unicode0
from rpython.rlib import jit
from rpython.translator.platform import platform
from rpython.rlib import rstring
@@ -342,6 +341,87 @@
rstring.check_str0(res)
return res
+
+class StringTraits:
+ str = str
+ str0 = s_Str0
+ CHAR = rffi.CHAR
+ CCHARP = rffi.CCHARP
+ charp2str = staticmethod(rffi.charp2str)
+ charpsize2str = staticmethod(rffi.charpsize2str)
+ scoped_str2charp = staticmethod(rffi.scoped_str2charp)
+ str2charp = staticmethod(rffi.str2charp)
+ free_charp = staticmethod(rffi.free_charp)
+ scoped_alloc_buffer = staticmethod(rffi.scoped_alloc_buffer)
+
+ @staticmethod
+ def posix_function_name(name):
+ return UNDERSCORE_ON_WIN32 + name
+
+ @staticmethod
+ def ll_os_name(name):
+ return 'll_os.ll_os_' + name
+
+ @staticmethod
+ @specialize.argtype(0)
+ def as_str(path):
+ assert path is not None
+ if isinstance(path, str):
+ return path
+ elif isinstance(path, unicode):
+ # This never happens in PyPy's Python interpreter!
+ # Only in raw RPython code that uses unicode strings.
+ # We implement python2 behavior: silently convert to ascii.
+ return path.encode('ascii')
+ else:
+ return path.as_bytes()
+
+ @staticmethod
+ @specialize.argtype(0)
+ def as_str0(path):
+ res = StringTraits.as_str(path)
+ rstring.check_str0(res)
+ return res
+
+
+class UnicodeTraits:
+ str = unicode
+ str0 = s_Unicode0
+ CHAR = rffi.WCHAR_T
+ CCHARP = rffi.CWCHARP
+ charp2str = staticmethod(rffi.wcharp2unicode)
+ charpsize2str = staticmethod(rffi.wcharpsize2unicode)
+ str2charp = staticmethod(rffi.unicode2wcharp)
+ scoped_str2charp = staticmethod(rffi.scoped_unicode2wcharp)
+ free_charp = staticmethod(rffi.free_wcharp)
+ scoped_alloc_buffer = staticmethod(rffi.scoped_alloc_unicodebuffer)
+
+ @staticmethod
+ def posix_function_name(name):
+ return UNDERSCORE_ON_WIN32 + 'w' + name
+
+ @staticmethod
+ @specialize.argtype(0)
+ def ll_os_name(name):
+ return 'll_os.ll_os_w' + name
+
+ @staticmethod
+ @specialize.argtype(0)
+ def as_str(path):
+ assert path is not None
+ if isinstance(path, unicode):
+ return path
+ else:
+ return path.as_unicode()
+
+ @staticmethod
+ @specialize.argtype(0)
+ def as_str0(path):
+ res = UnicodeTraits.as_str(path)
+ rstring.check_str0(res)
+ return res
+
+
# Returns True when the unicode function should be called:
# - on Windows
# - if the path is Unicode.
diff --git a/rpython/rlib/rposix_environ.py b/rpython/rlib/rposix_environ.py
--- a/rpython/rlib/rposix_environ.py
+++ b/rpython/rlib/rposix_environ.py
@@ -2,10 +2,10 @@
import sys
from rpython.annotator import model as annmodel
from rpython.rlib.objectmodel import enforceargs
+from rpython.rlib.rposix import _WIN32, StringTraits, UnicodeTraits
from rpython.rtyper.controllerentry import Controller
from rpython.rtyper.extfunc import register_external
from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rtyper.module.support import _WIN32, StringTraits, UnicodeTraits
from rpython.translator.tool.cbuild import ExternalCompilationInfo
str0 = annmodel.s_Str0
diff --git a/rpython/rtyper/module/test/test_posix.py
b/rpython/rlib/test/test_posix.py
rename from rpython/rtyper/module/test/test_posix.py
rename to rpython/rlib/test/test_posix.py
diff --git a/rpython/rlib/test/test_rerased.py
b/rpython/rlib/test/test_rerased.py
--- a/rpython/rlib/test/test_rerased.py
+++ b/rpython/rlib/test/test_rerased.py
@@ -192,7 +192,7 @@
def interpret(self, *args, **kwargs):
kwargs["taggedpointers"] = True
- return BaseRtypingTest.interpret(self, *args, **kwargs)
+ return BaseRtypingTest.interpret(*args, **kwargs)
def test_rtype_1(self):
def f():
return eraseX(X())
diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py
b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -463,6 +463,9 @@
def remove_regular_struct_content(container):
STRUCT = container._TYPE
+ if isinstance(STRUCT, lltype.FixedSizeArray):
+ del container._items
+ return
for field_name in STRUCT._names:
FIELDTYPE = getattr(STRUCT, field_name)
if not isinstance(FIELDTYPE, lltype.ContainerType):
@@ -652,6 +655,12 @@
cobj = lltype2ctypes(value)
setattr(self._storage.contents, field_name, cobj)
+ def getitem(self, index, uninitialized_ok=False):
+ return getattr(self, "item%s" % index)
+
+ def setitem(self, index, value):
+ setattr(self, "item%s" % index, value)
+
class _array_mixin(_parentable_mixin):
"""Mixin added to _array containers when they become ctypes-based."""
__slots__ = ()
diff --git a/rpython/rtyper/lltypesystem/lltype.py
b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -1761,7 +1761,10 @@
def __new__(self, TYPE, n=None, initialization=None, parent=None,
parentindex=None):
- my_variety = _struct_variety(TYPE._names)
+ if isinstance(TYPE, FixedSizeArray):
+ my_variety = _fixedsizearray
+ else:
+ my_variety = _struct_variety(TYPE._names)
return object.__new__(my_variety)
def __init__(self, TYPE, n=None, initialization=None, parent=None,
@@ -1771,7 +1774,6 @@
raise TypeError("%r is not variable-sized" % (TYPE,))
if n is None and TYPE._arrayfld is not None:
raise TypeError("%r is variable-sized" % (TYPE,))
- first, FIRSTTYPE = TYPE._first_struct()
for fld, typ in TYPE._flds.items():
if fld == TYPE._arrayfld:
value = _array(typ, n, initialization=initialization,
@@ -1814,23 +1816,48 @@
raise UninitializedMemoryAccess("%r.%s"%(self, field_name))
return r
- # for FixedSizeArray kind of structs:
+
+class _fixedsizearray(_struct):
+ def __init__(self, TYPE, n=None, initialization=None, parent=None,
+ parentindex=None):
+ _parentable.__init__(self, TYPE)
+ if n is not None:
+ raise TypeError("%r is not variable-sized" % (TYPE,))
+ typ = TYPE.OF
+ storage = []
+ for i, fld in enumerate(TYPE._names):
+ value = typ._allocate(initialization=initialization,
+ parent=self, parentindex=fld)
+ storage.append(value)
+ self._items = storage
+ if parent is not None:
+ self._setparentstructure(parent, parentindex)
def getlength(self):
- assert isinstance(self._TYPE, FixedSizeArray)
return self._TYPE.length
def getbounds(self):
return 0, self.getlength()
def getitem(self, index, uninitialized_ok=False):
- assert isinstance(self._TYPE, FixedSizeArray)
- return self._getattr('item%d' % index, uninitialized_ok)
+ assert 0 <= index < self.getlength()
+ return self._items[index]
def setitem(self, index, value):
- assert isinstance(self._TYPE, FixedSizeArray)
- setattr(self, 'item%d' % index, value)
+ assert 0 <= index < self.getlength()
+ self._items[index] = value
+ def __getattr__(self, name):
+ # obscure
+ if name.startswith("item"):
+ return self.getitem(int(name[len('item'):]))
+ return _struct.__getattr__(self, name)
+
+ def __setattr__(self, name, value):
+ if name.startswith("item"):
+ self.setitem(int(name[len('item'):]), value)
+ return
+ _struct.__setattr__(self, name, value)
class _array(_parentable):
_kind = "array"
diff --git a/rpython/rtyper/lltypesystem/module/ll_math.py
b/rpython/rtyper/lltypesystem/module/ll_math.py
--- a/rpython/rtyper/lltypesystem/module/ll_math.py
+++ b/rpython/rtyper/lltypesystem/module/ll_math.py
@@ -6,8 +6,8 @@
from rpython.translator import cdir
from rpython.rlib import jit, rposix
from rpython.rlib.rfloat import INFINITY, NAN, isfinite, isinf, isnan
+from rpython.rlib.rposix import UNDERSCORE_ON_WIN32
from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rtyper.module.support import UNDERSCORE_ON_WIN32
from rpython.tool.sourcetools import func_with_new_name
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.translator.platform import platform
diff --git a/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py
b/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/test/test_ll2ctypes.py
@@ -11,12 +11,12 @@
from rpython.rtyper.lltypesystem.ll2ctypes import _llgcopaque
from rpython.rtyper.annlowlevel import llhelper
from rpython.rlib import rposix
+from rpython.rlib.rposix import UNDERSCORE_ON_WIN32
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.translator import cdir
from rpython.tool.udir import udir
from rpython.rtyper.test.test_llinterp import interpret
from rpython.annotator.annrpython import RPythonAnnotator
-from rpython.rtyper.module.support import UNDERSCORE_ON_WIN32
from rpython.rtyper.rtyper import RPythonTyper
from rpython.rlib.rarithmetic import r_uint, get_long_pattern, is_emulated_long
from rpython.rlib.rarithmetic import is_valid_int
diff --git a/rpython/rtyper/module/__init__.py
b/rpython/rtyper/module/__init__.py
deleted file mode 100644
--- a/rpython/rtyper/module/__init__.py
+++ /dev/null
@@ -1,1 +0,0 @@
-#
diff --git a/rpython/rtyper/module/support.py b/rpython/rtyper/module/support.py
deleted file mode 100644
--- a/rpython/rtyper/module/support.py
+++ /dev/null
@@ -1,139 +0,0 @@
-import sys
-
-from rpython.annotator import model as annmodel
-from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rlib.objectmodel import specialize
-from rpython.rlib import rstring
-
-_WIN32 = sys.platform.startswith('win')
-UNDERSCORE_ON_WIN32 = '_' if _WIN32 else ''
-
-# utility conversion functions
-class LLSupport:
- _mixin_ = True
-
- def to_rstr(s):
- from rpython.rtyper.lltypesystem.rstr import STR, mallocstr
- if s is None:
- return lltype.nullptr(STR)
- p = mallocstr(len(s))
- for i in range(len(s)):
- p.chars[i] = s[i]
- return p
- to_rstr = staticmethod(to_rstr)
-
- def to_runicode(s):
- from rpython.rtyper.lltypesystem.rstr import UNICODE, mallocunicode
- if s is None:
- return lltype.nullptr(UNICODE)
- p = mallocunicode(len(s))
- for i in range(len(s)):
- p.chars[i] = s[i]
- return p
- to_runicode = staticmethod(to_runicode)
-
- def from_rstr(rs):
- if not rs: # null pointer
- return None
- else:
- return ''.join([rs.chars[i] for i in range(len(rs.chars))])
- from_rstr = staticmethod(from_rstr)
-
- def from_rstr_nonnull(rs):
- assert rs
- return ''.join([rs.chars[i] for i in range(len(rs.chars))])
- from_rstr_nonnull = staticmethod(from_rstr_nonnull)
-
-
-class StringTraits:
- str = str
- str0 = annmodel.s_Str0
- CHAR = rffi.CHAR
- CCHARP = rffi.CCHARP
- charp2str = staticmethod(rffi.charp2str)
- charpsize2str = staticmethod(rffi.charpsize2str)
- scoped_str2charp = staticmethod(rffi.scoped_str2charp)
- str2charp = staticmethod(rffi.str2charp)
- free_charp = staticmethod(rffi.free_charp)
- scoped_alloc_buffer = staticmethod(rffi.scoped_alloc_buffer)
-
- @staticmethod
- def posix_function_name(name):
- return UNDERSCORE_ON_WIN32 + name
-
- @staticmethod
- def ll_os_name(name):
- return 'll_os.ll_os_' + name
-
- @staticmethod
- @specialize.argtype(0)
- def as_str(path):
- assert path is not None
- if isinstance(path, str):
- return path
- elif isinstance(path, unicode):
- # This never happens in PyPy's Python interpreter!
- # Only in raw RPython code that uses unicode strings.
- # We implement python2 behavior: silently convert to ascii.
- return path.encode('ascii')
- else:
- return path.as_bytes()
-
- @staticmethod
- @specialize.argtype(0)
- def as_str0(path):
- res = StringTraits.as_str(path)
- rstring.check_str0(res)
- return res
-
-class UnicodeTraits:
- str = unicode
- str0 = annmodel.s_Unicode0
- CHAR = rffi.WCHAR_T
- CCHARP = rffi.CWCHARP
- charp2str = staticmethod(rffi.wcharp2unicode)
- charpsize2str = staticmethod(rffi.wcharpsize2unicode)
- str2charp = staticmethod(rffi.unicode2wcharp)
- scoped_str2charp = staticmethod(rffi.scoped_unicode2wcharp)
- free_charp = staticmethod(rffi.free_wcharp)
- scoped_alloc_buffer = staticmethod(rffi.scoped_alloc_unicodebuffer)
-
- @staticmethod
- def posix_function_name(name):
- return UNDERSCORE_ON_WIN32 + 'w' + name
-
- @staticmethod
- @specialize.argtype(0)
- def ll_os_name(name):
- return 'll_os.ll_os_w' + name
-
- @staticmethod
- @specialize.argtype(0)
- def as_str(path):
- assert path is not None
- if isinstance(path, unicode):
- return path
- else:
- return path.as_unicode()
-
- @staticmethod
- @specialize.argtype(0)
- def as_str0(path):
- res = UnicodeTraits.as_str(path)
- rstring.check_str0(res)
- return res
-
-def ll_strcpy(dst_s, src_s, n):
- dstchars = dst_s.chars
- srcchars = src_s.chars
- i = 0
- while i < n:
- dstchars[i] = srcchars[i]
- i += 1
-
-def _ll_strfill(dst_s, srcchars, n):
- dstchars = dst_s.chars
- i = 0
- while i < n:
- dstchars[i] = srcchars[i]
- i += 1
diff --git a/rpython/rtyper/module/test/__init__.py
b/rpython/rtyper/module/test/__init__.py
deleted file mode 100644
--- a/rpython/rtyper/module/test/__init__.py
+++ /dev/null
@@ -1,1 +0,0 @@
-#
diff --git a/rpython/rtyper/module/test/test_ll_strtod.py
b/rpython/rtyper/module/test/test_ll_strtod.py
deleted file mode 100644
--- a/rpython/rtyper/module/test/test_ll_strtod.py
+++ /dev/null
@@ -1,13 +0,0 @@
-import py
-
-from rpython.rtyper.test.tool import BaseRtypingTest
-from rpython.rlib import rfloat
-
-class TestStrtod(BaseRtypingTest):
- def test_formatd(self):
- for flags in [0,
- rfloat.DTSF_ADD_DOT_0]:
- def f(y):
- return rfloat.formatd(y, 'g', 2, flags)
-
- assert self.ll_to_string(self.interpret(f, [3.0])) == f(3.0)
diff --git a/rpython/rtyper/test/test_rfloat.py
b/rpython/rtyper/test/test_rfloat.py
--- a/rpython/rtyper/test/test_rfloat.py
+++ b/rpython/rtyper/test/test_rfloat.py
@@ -204,6 +204,14 @@
res = self.ll_to_string(self.interpret(f, [10/3.0]))
assert res == '3.33'
+ def test_formatd_g(self):
+ from rpython.rlib import rfloat
+ for flags in [0, rfloat.DTSF_ADD_DOT_0]:
+ def f(y):
+ return rfloat.formatd(y, 'g', 2, flags)
+
+ assert self.ll_to_string(self.interpret(f, [3.0])) == f(3.0)
+
def test_formatd_repr(self):
from rpython.rlib.rfloat import formatd
def f(x):
diff --git a/rpython/rtyper/test/test_rpbc.py b/rpython/rtyper/test/test_rpbc.py
--- a/rpython/rtyper/test/test_rpbc.py
+++ b/rpython/rtyper/test/test_rpbc.py
@@ -1945,7 +1945,7 @@
def interpret(self, fn, args, **kwds):
kwds['config'] = self.config
- return TestRPBC.interpret(self, fn, args, **kwds)
+ return TestRPBC.interpret(fn, args, **kwds)
def test_smallfuncsets_basic():
from rpython.translator.translator import TranslationContext, graphof
diff --git a/rpython/rtyper/test/tool.py b/rpython/rtyper/test/tool.py
--- a/rpython/rtyper/test/tool.py
+++ b/rpython/rtyper/test/tool.py
@@ -5,22 +5,27 @@
class BaseRtypingTest(object):
FLOAT_PRECISION = 8
- def gengraph(self, func, argtypes=[], viewbefore='auto', policy=None,
+ @staticmethod
+ def gengraph(func, argtypes=[], viewbefore='auto', policy=None,
backendopt=False, config=None):
return gengraph(func, argtypes, viewbefore, policy,
backendopt=backendopt, config=config)
- def interpret(self, fn, args, **kwds):
+ @staticmethod
+ def interpret(fn, args, **kwds):
return interpret(fn, args, **kwds)
- def interpret_raises(self, exc, fn, args, **kwds):
+ @staticmethod
+ def interpret_raises(exc, fn, args, **kwds):
return interpret_raises(exc, fn, args, **kwds)
- def float_eq(self, x, y):
+ @staticmethod
+ def float_eq(x, y):
return x == y
- def float_eq_approx(self, x, y):
- maxError = 10**-self.FLOAT_PRECISION
+ @classmethod
+ def float_eq_approx(cls, x, y):
+ maxError = 10**-cls.FLOAT_PRECISION
if abs(x-y) < maxError:
return True
@@ -31,45 +36,66 @@
return relativeError < maxError
- def is_of_type(self, x, type_):
+ @staticmethod
+ def is_of_type(x, type_):
return type(x) is type_
- def _skip_llinterpreter(self, reason):
+ @staticmethod
+ def _skip_llinterpreter(reason):
py.test.skip("lltypesystem doesn't support %s, yet" % reason)
- def ll_to_string(self, s):
+ @staticmethod
+ def ll_to_string(s):
if not s:
return None
return ''.join(s.chars)
- def ll_to_unicode(self, s):
+ @staticmethod
+ def ll_to_unicode(s):
return u''.join(s.chars)
- def string_to_ll(self, s):
- from rpython.rtyper.module.support import LLSupport
- return LLSupport.to_rstr(s)
+ @staticmethod
+ def string_to_ll(s):
+ from rpython.rtyper.lltypesystem.rstr import STR, mallocstr
+ if s is None:
+ return lltype.nullptr(STR)
+ p = mallocstr(len(s))
+ for i in range(len(s)):
+ p.chars[i] = s[i]
+ return p
- def unicode_to_ll(self, s):
- from rpython.rtyper.module.support import LLSupport
- return LLSupport.to_runicode(s)
+ @staticmethod
+ def unicode_to_ll(s):
+ from rpython.rtyper.lltypesystem.rstr import UNICODE, mallocunicode
+ if s is None:
+ return lltype.nullptr(UNICODE)
+ p = mallocunicode(len(s))
+ for i in range(len(s)):
+ p.chars[i] = s[i]
+ return p
- def ll_to_list(self, l):
+ @staticmethod
+ def ll_to_list(l):
r = []
items = l.ll_items()
for i in range(l.ll_length()):
r.append(items[i])
return r
- def ll_unpack_tuple(self, t, length):
+ @staticmethod
+ def ll_unpack_tuple(t, length):
return tuple([getattr(t, 'item%d' % i) for i in range(length)])
- def get_callable(self, fnptr):
+ @staticmethod
+ def get_callable(fnptr):
return fnptr._obj._callable
- def class_name(self, value):
+ @staticmethod
+ def class_name(value):
return ''.join(value.super.typeptr.name.chars)
- def read_attr(self, value, attr_name):
+ @staticmethod
+ def read_attr(value, attr_name):
value = value._obj
while value is not None:
attr = getattr(value, "inst_" + attr_name, None)
@@ -79,6 +105,7 @@
return attr
raise AttributeError()
- def is_of_instance_type(self, val):
+ @staticmethod
+ def is_of_instance_type(val):
T = lltype.typeOf(val)
return isinstance(T, lltype.Ptr) and isinstance(T.TO, lltype.GcStruct)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit