[pypy-commit] pypy release-5.x: merge default into branch
mattip
pypy.commits at gmail.com
Tue Apr 19 07:58:15 EDT 2016
Author: mattip <matti.picus at gmail.com>
Branch: release-5.x
Changeset: r83770:94369b856427
Date: 2016-04-19 14:57 +0300
http://bitbucket.org/pypy/pypy/changeset/94369b856427/
Log: merge default into branch
diff too long, truncating to 2000 out of 5943 lines
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -111,23 +111,24 @@
Simon Burton
Martin Matusiak
Konstantin Lopuhin
+ Stefano Rivera
Wenzhu Man
John Witulski
Laurence Tratt
Ivan Sichmann Freitas
Greg Price
Dario Bertini
- Stefano Rivera
Mark Pearse
Simon Cross
+ Edd Barrett
Andreas Stührk
- Edd Barrett
Jean-Philippe St. Pierre
Guido van Rossum
Pavel Vinogradov
+ Spenser Bauman
Jeremy Thurgood
Paweł Piotr Przeradowski
- Spenser Bauman
+ Tobias Pape
Paul deGrandis
Ilya Osadchiy
marky1991
@@ -139,7 +140,7 @@
Georg Brandl
Bert Freudenberg
Stian Andreassen
- Tobias Pape
+ Mark Young
Wanja Saatkamp
Gerald Klix
Mike Blume
@@ -170,9 +171,9 @@
Yichao Yu
Rocco Moretti
Gintautas Miliauskas
+ Devin Jeanpierre
Michael Twomey
Lucian Branescu Mihaila
- Devin Jeanpierre
Gabriel Lavoie
Olivier Dormond
Jared Grubb
@@ -183,6 +184,7 @@
Victor Stinner
Andrews Medina
anatoly techtonik
+ Sergey Matyunin
Stuart Williams
Jasper Schulz
Christian Hudon
@@ -217,7 +219,6 @@
Arjun Naik
Valentina Mukhamedzhanova
Stefano Parmesan
- Mark Young
Alexis Daboville
Jens-Uwe Mager
Carl Meyer
@@ -225,7 +226,9 @@
Pieter Zieschang
Gabriel
Lukas Vacek
+ Kunal Grover
Andrew Dalke
+ Florin Papa
Sylvain Thenault
Jakub Stasiak
Nathan Taylor
@@ -240,7 +243,6 @@
Kristjan Valur Jonsson
David Lievens
Neil Blakey-Milner
- Sergey Matyunin
Lutz Paelike
Lucio Torre
Lars Wassermann
@@ -252,9 +254,11 @@
Artur Lisiecki
Sergey Kishchenko
Ignas Mikalajunas
+ Alecsandru Patrascu
Christoph Gerum
Martin Blais
Lene Wagner
+ Catalin Gabriel Manciu
Tomo Cocoa
Kim Jin Su
Toni Mattis
@@ -291,6 +295,7 @@
Akira Li
Gustavo Niemeyer
Stephan Busemann
+ florinpapa
Rafał Gałczyński
Matt Bogosian
Christian Muirhead
@@ -305,6 +310,7 @@
Boglarka Vezer
Chris Pressey
Buck Golemon
+ Diana Popa
Konrad Delong
Dinu Gherman
Chris Lambacher
diff --git a/lib_pypy/_collections.py b/lib_pypy/_collections.py
--- a/lib_pypy/_collections.py
+++ b/lib_pypy/_collections.py
@@ -320,8 +320,7 @@
def __reduce_ex__(self, proto):
return type(self), (list(self), self.maxlen)
- def __hash__(self):
- raise TypeError("deque objects are unhashable")
+ __hash__ = None
def __copy__(self):
return self.__class__(self, self.maxlen)
diff --git a/lib_pypy/_pypy_wait.py b/lib_pypy/_pypy_wait.py
--- a/lib_pypy/_pypy_wait.py
+++ b/lib_pypy/_pypy_wait.py
@@ -1,51 +1,22 @@
-from resource import _struct_rusage, struct_rusage
-from ctypes import CDLL, c_int, POINTER, byref
-from ctypes.util import find_library
+from resource import ffi, lib, _make_struct_rusage
__all__ = ["wait3", "wait4"]
-libc = CDLL(find_library("c"))
-c_wait3 = libc.wait3
-c_wait3.argtypes = [POINTER(c_int), c_int, POINTER(_struct_rusage)]
-c_wait3.restype = c_int
-
-c_wait4 = libc.wait4
-c_wait4.argtypes = [c_int, POINTER(c_int), c_int, POINTER(_struct_rusage)]
-c_wait4.restype = c_int
-
-def create_struct_rusage(c_struct):
- return struct_rusage((
- float(c_struct.ru_utime),
- float(c_struct.ru_stime),
- c_struct.ru_maxrss,
- c_struct.ru_ixrss,
- c_struct.ru_idrss,
- c_struct.ru_isrss,
- c_struct.ru_minflt,
- c_struct.ru_majflt,
- c_struct.ru_nswap,
- c_struct.ru_inblock,
- c_struct.ru_oublock,
- c_struct.ru_msgsnd,
- c_struct.ru_msgrcv,
- c_struct.ru_nsignals,
- c_struct.ru_nvcsw,
- c_struct.ru_nivcsw))
def wait3(options):
- status = c_int()
- _rusage = _struct_rusage()
- pid = c_wait3(byref(status), c_int(options), byref(_rusage))
+ status = ffi.new("int *")
+ ru = ffi.new("struct rusage *")
+ pid = lib.wait3(status, options, ru)
- rusage = create_struct_rusage(_rusage)
+ rusage = _make_struct_rusage(ru)
- return pid, status.value, rusage
+ return pid, status[0], rusage
def wait4(pid, options):
- status = c_int()
- _rusage = _struct_rusage()
- pid = c_wait4(c_int(pid), byref(status), c_int(options), byref(_rusage))
+ status = ffi.new("int *")
+ ru = ffi.new("struct rusage *")
+ pid = lib.wait4(pid, status, options, ru)
- rusage = create_struct_rusage(_rusage)
+ rusage = _make_struct_rusage(ru)
- return pid, status.value, rusage
+ return pid, status[0], rusage
diff --git a/lib_pypy/_resource_build.py b/lib_pypy/_resource_build.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/_resource_build.py
@@ -0,0 +1,118 @@
+from cffi import FFI
+
+ffi = FFI()
+
+# Note: we don't directly expose 'struct timeval' or 'struct rlimit'
+
+
+rlimit_consts = '''
+RLIMIT_CPU
+RLIMIT_FSIZE
+RLIMIT_DATA
+RLIMIT_STACK
+RLIMIT_CORE
+RLIMIT_NOFILE
+RLIMIT_OFILE
+RLIMIT_VMEM
+RLIMIT_AS
+RLIMIT_RSS
+RLIMIT_NPROC
+RLIMIT_MEMLOCK
+RLIMIT_SBSIZE
+RLIM_INFINITY
+RUSAGE_SELF
+RUSAGE_CHILDREN
+RUSAGE_BOTH
+'''.split()
+
+rlimit_consts = ['#ifdef %s\n\t{"%s", %s},\n#endif\n' % (s, s, s)
+ for s in rlimit_consts]
+
+
+ffi.set_source("_resource_cffi", """
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+
+static const struct my_rlimit_def {
+ const char *name;
+ long long value;
+} my_rlimit_consts[] = {
+$RLIMIT_CONSTS
+ { NULL, 0 }
+};
+
+#define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)
+
+static double my_utime(struct rusage *input)
+{
+ return doubletime(input->ru_utime);
+}
+
+static double my_stime(struct rusage *input)
+{
+ return doubletime(input->ru_stime);
+}
+
+static int my_getrlimit(int resource, long long result[2])
+{
+ struct rlimit rl;
+ if (getrlimit(resource, &rl) == -1)
+ return -1;
+ result[0] = rl.rlim_cur;
+ result[1] = rl.rlim_max;
+ return 0;
+}
+
+static int my_setrlimit(int resource, long long cur, long long max)
+{
+ struct rlimit rl;
+ rl.rlim_cur = cur & RLIM_INFINITY;
+ rl.rlim_max = max & RLIM_INFINITY;
+ return setrlimit(resource, &rl);
+}
+
+""".replace('$RLIMIT_CONSTS', ''.join(rlimit_consts)))
+
+
+ffi.cdef("""
+
+#define RLIM_NLIMITS ...
+
+const struct my_rlimit_def {
+ const char *name;
+ long long value;
+} my_rlimit_consts[];
+
+struct rusage {
+ long ru_maxrss;
+ long ru_ixrss;
+ long ru_idrss;
+ long ru_isrss;
+ long ru_minflt;
+ long ru_majflt;
+ long ru_nswap;
+ long ru_inblock;
+ long ru_oublock;
+ long ru_msgsnd;
+ long ru_msgrcv;
+ long ru_nsignals;
+ long ru_nvcsw;
+ long ru_nivcsw;
+ ...;
+};
+
+static double my_utime(struct rusage *);
+static double my_stime(struct rusage *);
+void getrusage(int who, struct rusage *result);
+int my_getrlimit(int resource, long long result[2]);
+int my_setrlimit(int resource, long long cur, long long max);
+
+int wait3(int *status, int options, struct rusage *rusage);
+int wait4(int pid, int *status, int options, struct rusage *rusage);
+""")
+
+
+if __name__ == "__main__":
+ ffi.compile()
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.5.2
+Version: 1.6.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, CDefError, FFIError
from .ffiplatform import VerificationError, VerificationMissing
-__version__ = "1.5.2"
-__version_info__ = (1, 5, 2)
+__version__ = "1.6.0"
+__version_info__ = (1, 6, 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
@@ -233,7 +233,7 @@
f = PySys_GetObject((char *)"stderr");
if (f != NULL && f != Py_None) {
PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
- "\ncompiled with cffi version: 1.5.2"
+ "\ncompiled with cffi version: 1.6.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
@@ -299,6 +299,23 @@
"""
return self._backend.string(cdata, maxlen)
+ def unpack(self, cdata, length):
+ """Unpack an array of C data of the given length,
+ returning a Python string/unicode/list.
+
+ If 'cdata' is a pointer to 'char', returns a byte string.
+ It does not stop at the first null. This is equivalent to:
+ ffi.buffer(cdata, length)[:]
+
+ If 'cdata' is a pointer to 'wchar_t', returns a unicode string.
+ 'length' is measured in wchar_t's; it is not the size in bytes.
+
+ If 'cdata' is a pointer to anything else, returns a list of
+ 'length' items. This is a faster equivalent to:
+ [cdata[i] for i in range(length)]
+ """
+ return self._backend.unpack(cdata, length)
+
def buffer(self, cdata, size=-1):
"""Return a read-write buffer object that references the raw C data
pointed to by the given 'cdata'. The 'cdata' must be a pointer or
@@ -721,6 +738,26 @@
raise ValueError("ffi.def_extern() is only available on API-mode FFI "
"objects")
+ def list_types(self):
+ """Returns the user type names known to this FFI instance.
+ This returns a tuple containing three lists of names:
+ (typedef_names, names_of_structs, names_of_unions)
+ """
+ typedefs = []
+ structs = []
+ unions = []
+ for key in self._parser._declarations:
+ if key.startswith('typedef '):
+ typedefs.append(key[8:])
+ elif key.startswith('struct '):
+ structs.append(key[7:])
+ elif key.startswith('union '):
+ unions.append(key[6:])
+ typedefs.sort()
+ structs.sort()
+ unions.sort()
+ return (typedefs, structs, unions)
+
def _load_backend_lib(backend, name, flags):
if name is None:
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
@@ -29,7 +29,8 @@
_r_stdcall1 = re.compile(r"\b(__stdcall|WINAPI)\b")
_r_stdcall2 = re.compile(r"[(]\s*(__stdcall|WINAPI)\b")
_r_cdecl = re.compile(r"\b__cdecl\b")
-_r_extern_python = re.compile(r'\bextern\s*"Python"\s*.')
+_r_extern_python = re.compile(r'\bextern\s*"'
+ r'(Python|Python\s*\+\s*C|C\s*\+\s*Python)"\s*.')
_r_star_const_space = re.compile( # matches "* const "
r"[*]\s*((const|volatile|restrict)\b\s*)+")
@@ -88,6 +89,12 @@
# void __cffi_extern_python_start;
# int foo(int);
# void __cffi_extern_python_stop;
+ #
+ # input: `extern "Python+C" int foo(int);`
+ # output:
+ # void __cffi_extern_python_plus_c_start;
+ # int foo(int);
+ # void __cffi_extern_python_stop;
parts = []
while True:
match = _r_extern_python.search(csource)
@@ -98,7 +105,10 @@
#print ''.join(parts)+csource
#print '=>'
parts.append(csource[:match.start()])
- parts.append('void __cffi_extern_python_start; ')
+ if 'C' in match.group(1):
+ parts.append('void __cffi_extern_python_plus_c_start; ')
+ else:
+ parts.append('void __cffi_extern_python_start; ')
if csource[endpos] == '{':
# grouping variant
closing = csource.find('}', endpos)
@@ -302,7 +312,7 @@
break
#
try:
- self._inside_extern_python = False
+ self._inside_extern_python = '__cffi_extern_python_stop'
for decl in iterator:
if isinstance(decl, pycparser.c_ast.Decl):
self._parse_decl(decl)
@@ -376,8 +386,10 @@
tp = self._get_type_pointer(tp, quals)
if self._options.get('dllexport'):
tag = 'dllexport_python '
- elif self._inside_extern_python:
+ elif self._inside_extern_python == '__cffi_extern_python_start':
tag = 'extern_python '
+ elif self._inside_extern_python == '__cffi_extern_python_plus_c_start':
+ tag = 'extern_python_plus_c '
else:
tag = 'function '
self._declare(tag + decl.name, tp)
@@ -421,11 +433,9 @@
# hack: `extern "Python"` in the C source is replaced
# with "void __cffi_extern_python_start;" and
# "void __cffi_extern_python_stop;"
- self._inside_extern_python = not self._inside_extern_python
- assert self._inside_extern_python == (
- decl.name == '__cffi_extern_python_start')
+ self._inside_extern_python = decl.name
else:
- if self._inside_extern_python:
+ if self._inside_extern_python !='__cffi_extern_python_stop':
raise api.CDefError(
"cannot declare constants or "
"variables with 'extern \"Python\"'")
diff --git a/lib_pypy/cffi/recompiler.py b/lib_pypy/cffi/recompiler.py
--- a/lib_pypy/cffi/recompiler.py
+++ b/lib_pypy/cffi/recompiler.py
@@ -1145,11 +1145,11 @@
def _generate_cpy_extern_python_collecttype(self, tp, name):
assert isinstance(tp, model.FunctionPtrType)
self._do_collect_type(tp)
+ _generate_cpy_dllexport_python_collecttype = \
+ _generate_cpy_extern_python_plus_c_collecttype = \
+ _generate_cpy_extern_python_collecttype
- def _generate_cpy_dllexport_python_collecttype(self, tp, name):
- self._generate_cpy_extern_python_collecttype(tp, name)
-
- def _generate_cpy_extern_python_decl(self, tp, name, dllexport=False):
+ def _extern_python_decl(self, tp, name, tag_and_space):
prnt = self._prnt
if isinstance(tp.result, model.VoidType):
size_of_result = '0'
@@ -1184,11 +1184,7 @@
size_of_a = 'sizeof(%s) > %d ? sizeof(%s) : %d' % (
tp.result.get_c_name(''), size_of_a,
tp.result.get_c_name(''), size_of_a)
- if dllexport:
- tag = 'CFFI_DLLEXPORT'
- else:
- tag = 'static'
- prnt('%s %s' % (tag, tp.result.get_c_name(name_and_arguments)))
+ prnt('%s%s' % (tag_and_space, tp.result.get_c_name(name_and_arguments)))
prnt('{')
prnt(' char a[%s];' % size_of_a)
prnt(' char *p = a;')
@@ -1206,8 +1202,14 @@
prnt()
self._num_externpy += 1
+ def _generate_cpy_extern_python_decl(self, tp, name):
+ self._extern_python_decl(tp, name, 'static ')
+
def _generate_cpy_dllexport_python_decl(self, tp, name):
- self._generate_cpy_extern_python_decl(tp, name, dllexport=True)
+ self._extern_python_decl(tp, name, 'CFFI_DLLEXPORT ')
+
+ def _generate_cpy_extern_python_plus_c_decl(self, tp, name):
+ self._extern_python_decl(tp, name, '')
def _generate_cpy_extern_python_ctx(self, tp, name):
if self.target_is_python:
@@ -1220,8 +1222,9 @@
self._lsts["global"].append(
GlobalExpr(name, '&_cffi_externpy__%s' % name, type_op, name))
- def _generate_cpy_dllexport_python_ctx(self, tp, name):
- self._generate_cpy_extern_python_ctx(tp, name)
+ _generate_cpy_dllexport_python_ctx = \
+ _generate_cpy_extern_python_plus_c_ctx = \
+ _generate_cpy_extern_python_ctx
def _string_literal(self, s):
def _char_repr(c):
@@ -1231,7 +1234,7 @@
if c == '\n': return '\\n'
return '\\%03o' % ord(c)
lines = []
- for line in s.splitlines(True):
+ for line in s.splitlines(True) or ['']:
lines.append('"%s"' % ''.join([_char_repr(c) for c in line]))
return ' \\\n'.join(lines)
@@ -1319,7 +1322,9 @@
s = s.encode('ascii')
super(NativeIO, self).write(s)
-def _make_c_or_py_source(ffi, module_name, preamble, target_file):
+def _make_c_or_py_source(ffi, module_name, preamble, target_file, verbose):
+ if verbose:
+ print("generating %s" % (target_file,))
recompiler = Recompiler(ffi, module_name,
target_is_python=(preamble is None))
recompiler.collect_type_table()
@@ -1331,6 +1336,8 @@
with open(target_file, 'r') as f1:
if f1.read(len(output) + 1) != output:
raise IOError
+ if verbose:
+ print("(already up-to-date)")
return False # already up-to-date
except IOError:
tmp_file = '%s.~%d' % (target_file, os.getpid())
@@ -1343,12 +1350,14 @@
os.rename(tmp_file, target_file)
return True
-def make_c_source(ffi, module_name, preamble, target_c_file):
+def make_c_source(ffi, module_name, preamble, target_c_file, verbose=False):
assert preamble is not None
- return _make_c_or_py_source(ffi, module_name, preamble, target_c_file)
+ return _make_c_or_py_source(ffi, module_name, preamble, target_c_file,
+ verbose)
-def make_py_source(ffi, module_name, target_py_file):
- return _make_c_or_py_source(ffi, module_name, None, target_py_file)
+def make_py_source(ffi, module_name, target_py_file, verbose=False):
+ return _make_c_or_py_source(ffi, module_name, None, target_py_file,
+ verbose)
def _modname_to_file(outputdir, modname, extension):
parts = modname.split('.')
@@ -1438,7 +1447,8 @@
target = '*'
#
ext = ffiplatform.get_extension(ext_c_file, module_name, **kwds)
- updated = make_c_source(ffi, module_name, preamble, c_file)
+ updated = make_c_source(ffi, module_name, preamble, c_file,
+ verbose=compiler_verbose)
if call_c_compiler:
patchlist = []
cwd = os.getcwd()
@@ -1458,7 +1468,8 @@
else:
if c_file is None:
c_file, _ = _modname_to_file(tmpdir, module_name, '.py')
- updated = make_py_source(ffi, module_name, c_file)
+ updated = make_py_source(ffi, module_name, c_file,
+ verbose=compiler_verbose)
if call_c_compiler:
return c_file
else:
@@ -1484,4 +1495,7 @@
def typeof_disabled(*args, **kwds):
raise NotImplementedError
ffi._typeof = typeof_disabled
+ for name in dir(ffi):
+ if not name.startswith('_') and not hasattr(module.ffi, name):
+ setattr(ffi, name, NotImplemented)
return module.lib
diff --git a/lib_pypy/ctypes_config_cache/.empty b/lib_pypy/ctypes_config_cache/.empty
new file mode 100644
--- /dev/null
+++ b/lib_pypy/ctypes_config_cache/.empty
@@ -0,0 +1,1 @@
+dummy file to allow old buildbot configuration to run
diff --git a/lib_pypy/ctypes_config_cache/__init__.py b/lib_pypy/ctypes_config_cache/__init__.py
deleted file mode 100644
diff --git a/lib_pypy/ctypes_config_cache/dumpcache.py b/lib_pypy/ctypes_config_cache/dumpcache.py
deleted file mode 100644
--- a/lib_pypy/ctypes_config_cache/dumpcache.py
+++ /dev/null
@@ -1,21 +0,0 @@
-import sys, os
-from ctypes_configure import dumpcache
-
-def dumpcache2(basename, config):
- size = 32 if sys.maxint <= 2**32 else 64
- filename = '_%s_%s_.py' % (basename, size)
- dumpcache.dumpcache(__file__, filename, config)
- #
- filename = os.path.join(os.path.dirname(__file__),
- '_%s_cache.py' % (basename,))
- g = open(filename, 'w')
- print >> g, '''\
-import sys
-_size = 32 if sys.maxint <= 2**32 else 64
-# XXX relative import, should be removed together with
-# XXX the relative imports done e.g. by lib_pypy/pypy_test/test_hashlib
-_mod = __import__("_%s_%%s_" %% (_size,),
- globals(), locals(), ["*"])
-globals().update(_mod.__dict__)\
-''' % (basename,)
- g.close()
diff --git a/lib_pypy/ctypes_config_cache/locale.ctc.py b/lib_pypy/ctypes_config_cache/locale.ctc.py
deleted file mode 100644
--- a/lib_pypy/ctypes_config_cache/locale.ctc.py
+++ /dev/null
@@ -1,73 +0,0 @@
-"""
-'ctypes_configure' source for _locale.py.
-Run this to rebuild _locale_cache.py.
-"""
-
-from ctypes_configure.configure import (configure, ExternalCompilationInfo,
- ConstantInteger, DefinedConstantInteger, SimpleType, check_eci)
-import dumpcache
-
-# ____________________________________________________________
-
-_CONSTANTS = [
- 'LC_CTYPE',
- 'LC_TIME',
- 'LC_COLLATE',
- 'LC_MONETARY',
- 'LC_MESSAGES',
- 'LC_NUMERIC',
- 'LC_ALL',
- 'CHAR_MAX',
-]
-
-class LocaleConfigure:
- _compilation_info_ = ExternalCompilationInfo(includes=['limits.h',
- 'locale.h'])
-for key in _CONSTANTS:
- setattr(LocaleConfigure, key, DefinedConstantInteger(key))
-
-config = configure(LocaleConfigure, noerr=True)
-for key, value in config.items():
- if value is None:
- del config[key]
- _CONSTANTS.remove(key)
-
-# ____________________________________________________________
-
-eci = ExternalCompilationInfo(includes=['locale.h', 'langinfo.h'])
-HAS_LANGINFO = check_eci(eci)
-
-if HAS_LANGINFO:
- # list of all possible names
- langinfo_names = [
- "RADIXCHAR", "THOUSEP", "CRNCYSTR",
- "D_T_FMT", "D_FMT", "T_FMT", "AM_STR", "PM_STR",
- "CODESET", "T_FMT_AMPM", "ERA", "ERA_D_FMT", "ERA_D_T_FMT",
- "ERA_T_FMT", "ALT_DIGITS", "YESEXPR", "NOEXPR", "_DATE_FMT",
- ]
- for i in range(1, 8):
- langinfo_names.append("DAY_%d" % i)
- langinfo_names.append("ABDAY_%d" % i)
- for i in range(1, 13):
- langinfo_names.append("MON_%d" % i)
- langinfo_names.append("ABMON_%d" % i)
-
- class LanginfoConfigure:
- _compilation_info_ = eci
- nl_item = SimpleType('nl_item')
- for key in langinfo_names:
- setattr(LanginfoConfigure, key, DefinedConstantInteger(key))
-
- langinfo_config = configure(LanginfoConfigure)
- for key, value in langinfo_config.items():
- if value is None:
- del langinfo_config[key]
- langinfo_names.remove(key)
- config.update(langinfo_config)
- _CONSTANTS += langinfo_names
-
-# ____________________________________________________________
-
-config['ALL_CONSTANTS'] = tuple(_CONSTANTS)
-config['HAS_LANGINFO'] = HAS_LANGINFO
-dumpcache.dumpcache2('locale', config)
diff --git a/lib_pypy/ctypes_config_cache/rebuild.py b/lib_pypy/ctypes_config_cache/rebuild.py
deleted file mode 100755
--- a/lib_pypy/ctypes_config_cache/rebuild.py
+++ /dev/null
@@ -1,56 +0,0 @@
-#! /usr/bin/env python
-# Run this script to rebuild all caches from the *.ctc.py files.
-
-import os, sys
-
-sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..')))
-
-import py
-
-_dirpath = os.path.dirname(__file__) or os.curdir
-
-from rpython.tool.ansi_print import AnsiLogger
-log = AnsiLogger("ctypes_config_cache")
-
-
-def rebuild_one(name):
- filename = os.path.join(_dirpath, name)
- d = {'__file__': filename}
- path = sys.path[:]
- try:
- sys.path.insert(0, _dirpath)
- execfile(filename, d)
- finally:
- sys.path[:] = path
-
-def try_rebuild():
- size = 32 if sys.maxint <= 2**32 else 64
- # remove the files '_*_size_.py'
- left = {}
- for p in os.listdir(_dirpath):
- if p.startswith('_') and (p.endswith('_%s_.py' % size) or
- p.endswith('_%s_.pyc' % size)):
- os.unlink(os.path.join(_dirpath, p))
- elif p.startswith('_') and (p.endswith('_.py') or
- p.endswith('_.pyc')):
- for i in range(2, len(p)-4):
- left[p[:i]] = True
- # remove the files '_*_cache.py' if there is no '_*_*_.py' left around
- for p in os.listdir(_dirpath):
- if p.startswith('_') and (p.endswith('_cache.py') or
- p.endswith('_cache.pyc')):
- if p[:-9] not in left:
- os.unlink(os.path.join(_dirpath, p))
- #
- for p in os.listdir(_dirpath):
- if p.endswith('.ctc.py'):
- try:
- rebuild_one(p)
- except Exception, e:
- log.ERROR("Running %s:\n %s: %s" % (
- os.path.join(_dirpath, p),
- e.__class__.__name__, e))
-
-
-if __name__ == '__main__':
- try_rebuild()
diff --git a/lib_pypy/ctypes_config_cache/resource.ctc.py b/lib_pypy/ctypes_config_cache/resource.ctc.py
deleted file mode 100644
--- a/lib_pypy/ctypes_config_cache/resource.ctc.py
+++ /dev/null
@@ -1,62 +0,0 @@
-"""
-'ctypes_configure' source for resource.py.
-Run this to rebuild _resource_cache.py.
-"""
-
-
-from ctypes import sizeof
-import dumpcache
-from ctypes_configure.configure import (configure,
- ExternalCompilationInfo, ConstantInteger, DefinedConstantInteger,
- SimpleType)
-
-
-_CONSTANTS = (
- 'RLIM_INFINITY',
- 'RLIM_NLIMITS',
-)
-_OPTIONAL_CONSTANTS = (
- 'RLIMIT_CPU',
- 'RLIMIT_FSIZE',
- 'RLIMIT_DATA',
- 'RLIMIT_STACK',
- 'RLIMIT_CORE',
- 'RLIMIT_RSS',
- 'RLIMIT_NPROC',
- 'RLIMIT_NOFILE',
- 'RLIMIT_OFILE',
- 'RLIMIT_MEMLOCK',
- 'RLIMIT_AS',
- 'RLIMIT_LOCKS',
- 'RLIMIT_SIGPENDING',
- 'RLIMIT_MSGQUEUE',
- 'RLIMIT_NICE',
- 'RLIMIT_RTPRIO',
- 'RLIMIT_VMEM',
-
- 'RUSAGE_BOTH',
- 'RUSAGE_SELF',
- 'RUSAGE_CHILDREN',
-)
-
-# Setup our configure
-class ResourceConfigure:
- _compilation_info_ = ExternalCompilationInfo(includes=['sys/resource.h'])
- rlim_t = SimpleType('rlim_t')
-for key in _CONSTANTS:
- setattr(ResourceConfigure, key, ConstantInteger(key))
-for key in _OPTIONAL_CONSTANTS:
- setattr(ResourceConfigure, key, DefinedConstantInteger(key))
-
-# Configure constants and types
-config = configure(ResourceConfigure)
-config['rlim_t_max'] = (1<<(sizeof(config['rlim_t']) * 8)) - 1
-optional_constants = []
-for key in _OPTIONAL_CONSTANTS:
- if config[key] is not None:
- optional_constants.append(key)
- else:
- del config[key]
-
-config['ALL_CONSTANTS'] = _CONSTANTS + tuple(optional_constants)
-dumpcache.dumpcache2('resource', config)
diff --git a/lib_pypy/pwd.py b/lib_pypy/pwd.py
--- a/lib_pypy/pwd.py
+++ b/lib_pypy/pwd.py
@@ -1,4 +1,4 @@
-# ctypes implementation: Victor Stinner, 2008-05-08
+# indirectly based on ctypes implementation: Victor Stinner, 2008-05-08
"""
This module provides access to the Unix password database.
It is available on all Unix versions.
diff --git a/lib_pypy/resource.py b/lib_pypy/resource.py
--- a/lib_pypy/resource.py
+++ b/lib_pypy/resource.py
@@ -1,15 +1,8 @@
-import sys
-if sys.platform == 'win32':
- raise ImportError('resource module not available for win32')
+"""http://docs.python.org/library/resource"""
-# load the platform-specific cache made by running resource.ctc.py
-from ctypes_config_cache._resource_cache import *
-
-from ctypes_support import standard_c_lib as libc
-from ctypes_support import get_errno
-from ctypes import Structure, c_int, c_long, byref, POINTER
+from _resource_cffi import ffi, lib
from errno import EINVAL, EPERM
-import _structseq
+import _structseq, os
try: from __pypy__ import builtinify
except ImportError: builtinify = lambda f: f
@@ -18,106 +11,37 @@
class error(Exception):
pass
+class struct_rusage:
+ """struct_rusage: Result from getrusage.
-# Read required libc functions
-_getrusage = libc.getrusage
-_getrlimit = libc.getrlimit
-_setrlimit = libc.setrlimit
-try:
- _getpagesize = libc.getpagesize
- _getpagesize.argtypes = ()
- _getpagesize.restype = c_int
-except AttributeError:
- from os import sysconf
- _getpagesize = None
+This object may be accessed either as a tuple of
+ (utime,stime,maxrss,ixrss,idrss,isrss,minflt,majflt,
+ nswap,inblock,oublock,msgsnd,msgrcv,nsignals,nvcsw,nivcsw)
+or via the attributes ru_utime, ru_stime, ru_maxrss, and so on."""
-
-class timeval(Structure):
- _fields_ = (
- ("tv_sec", c_long),
- ("tv_usec", c_long),
- )
- def __str__(self):
- return "(%s, %s)" % (self.tv_sec, self.tv_usec)
-
- def __float__(self):
- return self.tv_sec + self.tv_usec/1000000.0
-
-class _struct_rusage(Structure):
- _fields_ = (
- ("ru_utime", timeval),
- ("ru_stime", timeval),
- ("ru_maxrss", c_long),
- ("ru_ixrss", c_long),
- ("ru_idrss", c_long),
- ("ru_isrss", c_long),
- ("ru_minflt", c_long),
- ("ru_majflt", c_long),
- ("ru_nswap", c_long),
- ("ru_inblock", c_long),
- ("ru_oublock", c_long),
- ("ru_msgsnd", c_long),
- ("ru_msgrcv", c_long),
- ("ru_nsignals", c_long),
- ("ru_nvcsw", c_long),
- ("ru_nivcsw", c_long),
- )
-
-_getrusage.argtypes = (c_int, POINTER(_struct_rusage))
-_getrusage.restype = c_int
-
-
-class struct_rusage:
__metaclass__ = _structseq.structseqtype
- ru_utime = _structseq.structseqfield(0)
- ru_stime = _structseq.structseqfield(1)
- ru_maxrss = _structseq.structseqfield(2)
- ru_ixrss = _structseq.structseqfield(3)
- ru_idrss = _structseq.structseqfield(4)
- ru_isrss = _structseq.structseqfield(5)
- ru_minflt = _structseq.structseqfield(6)
- ru_majflt = _structseq.structseqfield(7)
- ru_nswap = _structseq.structseqfield(8)
- ru_inblock = _structseq.structseqfield(9)
- ru_oublock = _structseq.structseqfield(10)
- ru_msgsnd = _structseq.structseqfield(11)
- ru_msgrcv = _structseq.structseqfield(12)
- ru_nsignals = _structseq.structseqfield(13)
- ru_nvcsw = _structseq.structseqfield(14)
- ru_nivcsw = _structseq.structseqfield(15)
+ ru_utime = _structseq.structseqfield(0, "user time used")
+ ru_stime = _structseq.structseqfield(1, "system time used")
+ ru_maxrss = _structseq.structseqfield(2, "max. resident set size")
+ ru_ixrss = _structseq.structseqfield(3, "shared memory size")
+ ru_idrss = _structseq.structseqfield(4, "unshared data size")
+ ru_isrss = _structseq.structseqfield(5, "unshared stack size")
+ ru_minflt = _structseq.structseqfield(6, "page faults not requiring I/O")
+ ru_majflt = _structseq.structseqfield(7, "page faults requiring I/O")
+ ru_nswap = _structseq.structseqfield(8, "number of swap outs")
+ ru_inblock = _structseq.structseqfield(9, "block input operations")
+ ru_oublock = _structseq.structseqfield(10, "block output operations")
+ ru_msgsnd = _structseq.structseqfield(11, "IPC messages sent")
+ ru_msgrcv = _structseq.structseqfield(12, "IPC messages received")
+ ru_nsignals = _structseq.structseqfield(13,"signals received")
+ ru_nvcsw = _structseq.structseqfield(14, "voluntary context switches")
+ ru_nivcsw = _structseq.structseqfield(15, "involuntary context switches")
- at builtinify
-def rlimit_check_bounds(rlim_cur, rlim_max):
- if rlim_cur > rlim_t_max:
- raise ValueError("%d does not fit into rlim_t" % rlim_cur)
- if rlim_max > rlim_t_max:
- raise ValueError("%d does not fit into rlim_t" % rlim_max)
-
-class rlimit(Structure):
- _fields_ = (
- ("rlim_cur", rlim_t),
- ("rlim_max", rlim_t),
- )
-
-_getrlimit.argtypes = (c_int, POINTER(rlimit))
-_getrlimit.restype = c_int
-_setrlimit.argtypes = (c_int, POINTER(rlimit))
-_setrlimit.restype = c_int
-
-
- at builtinify
-def getrusage(who):
- ru = _struct_rusage()
- ret = _getrusage(who, byref(ru))
- if ret == -1:
- errno = get_errno()
- if errno == EINVAL:
- raise ValueError("invalid who parameter")
- raise error(errno)
+def _make_struct_rusage(ru):
return struct_rusage((
- float(ru.ru_utime),
- float(ru.ru_stime),
+ lib.my_utime(ru),
+ lib.my_stime(ru),
ru.ru_maxrss,
ru.ru_ixrss,
ru.ru_idrss,
@@ -135,48 +59,59 @@
))
@builtinify
+def getrusage(who):
+ ru = ffi.new("struct rusage *")
+ if lib.getrusage(who, ru) == -1:
+ if ffi.errno == EINVAL:
+ raise ValueError("invalid who parameter")
+ raise error(ffi.errno)
+ return _make_struct_rusage(ru)
+
+ at builtinify
def getrlimit(resource):
- if not(0 <= resource < RLIM_NLIMITS):
+ if not (0 <= resource < lib.RLIM_NLIMITS):
return ValueError("invalid resource specified")
- rlim = rlimit()
- ret = _getrlimit(resource, byref(rlim))
- if ret == -1:
- errno = get_errno()
- raise error(errno)
- return (rlim.rlim_cur, rlim.rlim_max)
+ result = ffi.new("long long[2]")
+ if lib.my_getrlimit(resource, result) == -1:
+ raise error(ffi.errno)
+ return (result[0], result[1])
@builtinify
-def setrlimit(resource, rlim):
- if not(0 <= resource < RLIM_NLIMITS):
+def setrlimit(resource, limits):
+ if not (0 <= resource < lib.RLIM_NLIMITS):
return ValueError("invalid resource specified")
- rlimit_check_bounds(*rlim)
- rlim = rlimit(rlim[0], rlim[1])
- ret = _setrlimit(resource, byref(rlim))
- if ret == -1:
- errno = get_errno()
- if errno == EINVAL:
- return ValueError("current limit exceeds maximum limit")
- elif errno == EPERM:
- return ValueError("not allowed to raise maximum limit")
+ limits = tuple(limits)
+ if len(limits) != 2:
+ raise ValueError("expected a tuple of 2 integers")
+
+ if lib.my_setrlimit(resource, limits[0], limits[1]) == -1:
+ if ffi.errno == EINVAL:
+ raise ValueError("current limit exceeds maximum limit")
+ elif ffi.errno == EPERM:
+ raise ValueError("not allowed to raise maximum limit")
else:
- raise error(errno)
+ raise error(ffi.errno)
+
@builtinify
def getpagesize():
- if _getpagesize:
- return _getpagesize()
- else:
- try:
- return sysconf("SC_PAGE_SIZE")
- except ValueError:
- # Irix 5.3 has _SC_PAGESIZE, but not _SC_PAGE_SIZE
- return sysconf("SC_PAGESIZE")
+ return os.sysconf("SC_PAGESIZE")
-__all__ = ALL_CONSTANTS + (
- 'error', 'timeval', 'struct_rusage', 'rlimit',
- 'getrusage', 'getrlimit', 'setrlimit', 'getpagesize',
+
+def _setup():
+ all_constants = []
+ p = lib.my_rlimit_consts
+ while p.name:
+ name = ffi.string(p.name)
+ globals()[name] = int(p.value)
+ all_constants.append(name)
+ p += 1
+ return all_constants
+
+__all__ = tuple(_setup()) + (
+ 'error', 'getpagesize', 'struct_rusage',
+ 'getrusage', 'getrlimit', 'setrlimit',
)
-
-del ALL_CONSTANTS
+del _setup
diff --git a/pypy/doc/contributor.rst b/pypy/doc/contributor.rst
--- a/pypy/doc/contributor.rst
+++ b/pypy/doc/contributor.rst
@@ -81,13 +81,13 @@
Simon Burton
Martin Matusiak
Konstantin Lopuhin
+ Stefano Rivera
Wenzhu Man
John Witulski
Laurence Tratt
Ivan Sichmann Freitas
Greg Price
Dario Bertini
- Stefano Rivera
Mark Pearse
Simon Cross
Andreas Stührk
@@ -95,9 +95,10 @@
Jean-Philippe St. Pierre
Guido van Rossum
Pavel Vinogradov
+ Spenser Bauman
Jeremy Thurgood
Paweł Piotr Przeradowski
- Spenser Bauman
+ Tobias Pape
Paul deGrandis
Ilya Osadchiy
marky1991
@@ -109,7 +110,7 @@
Georg Brandl
Bert Freudenberg
Stian Andreassen
- Tobias Pape
+ Mark Young
Wanja Saatkamp
Gerald Klix
Mike Blume
@@ -140,9 +141,9 @@
Yichao Yu
Rocco Moretti
Gintautas Miliauskas
+ Devin Jeanpierre
Michael Twomey
Lucian Branescu Mihaila
- Devin Jeanpierre
Gabriel Lavoie
Olivier Dormond
Jared Grubb
@@ -153,6 +154,7 @@
Victor Stinner
Andrews Medina
anatoly techtonik
+ Sergey Matyunin
Stuart Williams
Jasper Schulz
Christian Hudon
@@ -187,7 +189,6 @@
Arjun Naik
Valentina Mukhamedzhanova
Stefano Parmesan
- Mark Young
Alexis Daboville
Jens-Uwe Mager
Carl Meyer
@@ -195,7 +196,9 @@
Pieter Zieschang
Gabriel
Lukas Vacek
+ Kunal Grover
Andrew Dalke
+ Florin Papa
Sylvain Thenault
Jakub Stasiak
Nathan Taylor
@@ -210,7 +213,6 @@
Kristjan Valur Jonsson
David Lievens
Neil Blakey-Milner
- Sergey Matyunin
Lutz Paelike
Lucio Torre
Lars Wassermann
@@ -222,9 +224,11 @@
Artur Lisiecki
Sergey Kishchenko
Ignas Mikalajunas
+ Alecsandru Patrascu
Christoph Gerum
Martin Blais
Lene Wagner
+ Catalin Gabriel Manciu
Tomo Cocoa
Kim Jin Su
Toni Mattis
@@ -261,6 +265,7 @@
Akira Li
Gustavo Niemeyer
Stephan Busemann
+ florinpapa
Rafał Gałczyński
Matt Bogosian
Christian Muirhead
@@ -275,6 +280,7 @@
Boglarka Vezer
Chris Pressey
Buck Golemon
+ Diana Popa
Konrad Delong
Dinu Gherman
Chris Lambacher
diff --git a/pypy/doc/release-5.1.0.rst b/pypy/doc/release-5.1.0.rst
--- a/pypy/doc/release-5.1.0.rst
+++ b/pypy/doc/release-5.1.0.rst
@@ -2,12 +2,11 @@
PyPy 5.1
========
-We have released PyPy 5.1, about two months after PyPy 5.0.1.
+We have released PyPy 5.1, about a month after PyPy 5.0.
We encourage all users of PyPy to update to this version. Apart from the usual
bug fixes, there is an ongoing effort to improve the warmup time and memory
-usage of JIT-related metadata.
-
-We now fully support the IBM s390x architecture.
+usage of JIT-related metadata, and we now fully support the IBM s390x
+architecture.
You can download the PyPy 5.1 release here:
@@ -52,22 +51,46 @@
.. _`PyPy and CPython 2.7.x`: http://speed.pypy.org
.. _`dynamic languages`: http://pypyjs.org
-Other Highlights (since 5.0.1 released in Febuary 2015)
+Other Highlights (since 5.0 released in March 2015)
=========================================================
* New features:
- *
+ * A new jit backend for the IBM s390x, which was a large effort over the past
+ few months.
- *
+ * Add better support for PyUnicodeObject in the C-API compatibility layer
- *
+ * Support GNU/kFreeBSD Debian ports in vmprof
+
+ * Add __pypy__._promote
+
+ * Make attrgetter a single type for CPython compatibility
* Bug Fixes
- *
+ * Catch exceptions raised in an exit function
- *
+ * Fix a corner case in the JIT
+
+ * Fix edge cases in the cpyext refcounting-compatible semantics
+
+ * Try harder to not emit NEON instructions on ARM processors without NEON
+ support
+
+ * Improve the rpython posix module system interaction function calls
+
+ * Detect a missing class function implementation instead of calling a random
+ function
+
+ * Check that PyTupleObjects do not contain any NULLs at the
+ point of conversion to W_TupleObjects
+
+ * In ctypes, fix _anonymous_ fields of instances
+
+ * Fix JIT issue with unpack() on a Trace which contains half-written operations
+
+ * Fix sandbox startup (a regression in 5.0)
* Issues reported with our previous release were resolved_ after reports from users on
our issue tracker at https://bitbucket.org/pypy/pypy/issues or on IRC at
@@ -75,21 +98,32 @@
* Numpy:
- *
+ * Implemented numpy.where for a single argument
- *
+ * Indexing by a numpy scalar now returns a scalar
+
+ * Fix transpose(arg) when arg is a sequence
+
+ * Refactor include file handling, now all numpy ndarray, ufunc, and umath
+ functions exported from libpypy.so are declared in pypy_numpy.h, which is
+ included only when building our fork of numpy
* Performance improvements:
- *
+ * Improve str.endswith([tuple]) and str.startswith([tuple]) to allow JITting
- *
+ * Merge another round of improvements to the warmup performance
+
+ * Cleanup history rewriting in pyjitpl
+
+ * Remove the forced minor collection that occurs when rewriting the
+ assembler at the start of the JIT backend
* Internal refactorings:
- *
+ * Use a simpler logger to speed up translation
- *
+ * Drop vestiges of Python 2.5 support in testing
.. _resolved: http://doc.pypy.org/en/latest/whatsnew-5.0.0.html
.. _`blog post`: http://morepypy.blogspot.com/2016/02/c-api-support-update.html
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
@@ -5,3 +5,12 @@
.. this is a revision shortly after release-5.1
.. startrev: 2180e1eaf6f6
+.. branch: rposix-for-3
+
+Reuse rposix definition of TIMESPEC in rposix_stat, add wrapper for fstatat().
+This updates the underlying rpython functions with the ones needed for the
+py3k branch
+
+.. branch: numpy_broadcast
+
+Add broadcast to micronumpy
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -340,10 +340,6 @@
return PyPyJitPolicy(pypy_hooks)
def get_entry_point(self, config):
- from pypy.tool.lib_pypy import import_from_lib_pypy
- rebuild = import_from_lib_pypy('ctypes_config_cache/rebuild')
- rebuild.try_rebuild()
-
space = make_objspace(config)
# manually imports app_main.py
diff --git a/pypy/interpreter/astcompiler/astbuilder.py b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -54,24 +54,24 @@
n = self.root_node
if n.type == syms.file_input:
stmts = []
- for i in range(len(n.children) - 1):
- stmt = n.children[i]
+ for i in range(n.num_children() - 1):
+ stmt = n.get_child(i)
if stmt.type == tokens.NEWLINE:
continue
sub_stmts_count = self.number_of_statements(stmt)
if sub_stmts_count == 1:
stmts.append(self.handle_stmt(stmt))
else:
- stmt = stmt.children[0]
+ stmt = stmt.get_child(0)
for j in range(sub_stmts_count):
- small_stmt = stmt.children[j * 2]
+ small_stmt = stmt.get_child(j * 2)
stmts.append(self.handle_stmt(small_stmt))
return ast.Module(stmts)
elif n.type == syms.eval_input:
- body = self.handle_testlist(n.children[0])
+ body = self.handle_testlist(n.get_child(0))
return ast.Expression(body)
elif n.type == syms.single_input:
- first_child = n.children[0]
+ first_child = n.get_child(0)
if first_child.type == tokens.NEWLINE:
# An empty line.
return ast.Interactive([])
@@ -81,8 +81,8 @@
stmts = [self.handle_stmt(first_child)]
else:
stmts = []
- for i in range(0, len(first_child.children), 2):
- stmt = first_child.children[i]
+ for i in range(0, first_child.num_children(), 2):
+ stmt = first_child.get_child(i)
if stmt.type == tokens.NEWLINE:
break
stmts.append(self.handle_stmt(stmt))
@@ -96,16 +96,16 @@
if stmt_type == syms.compound_stmt:
return 1
elif stmt_type == syms.stmt:
- return self.number_of_statements(n.children[0])
+ return self.number_of_statements(n.get_child(0))
elif stmt_type == syms.simple_stmt:
# Divide to remove semi-colons.
- return len(n.children) // 2
+ return n.num_children() // 2
else:
raise AssertionError("non-statement node")
def error(self, msg, n):
"""Raise a SyntaxError with the lineno and column set to n's."""
- raise SyntaxError(msg, n.lineno, n.column,
+ raise SyntaxError(msg, n.get_lineno(), n.get_column(),
filename=self.compile_info.filename)
def error_ast(self, msg, ast_node):
@@ -132,51 +132,51 @@
expressions = None
newline = True
start = 1
- child_count = len(print_node.children)
- if child_count > 2 and print_node.children[1].type == tokens.RIGHTSHIFT:
- dest = self.handle_expr(print_node.children[2])
+ child_count = print_node.num_children()
+ if child_count > 2 and print_node.get_child(1).type == tokens.RIGHTSHIFT:
+ dest = self.handle_expr(print_node.get_child(2))
start = 4
if (child_count + 1 - start) // 2:
- expressions = [self.handle_expr(print_node.children[i])
+ expressions = [self.handle_expr(print_node.get_child(i))
for i in range(start, child_count, 2)]
- if print_node.children[-1].type == tokens.COMMA:
+ if print_node.get_child(-1).type == tokens.COMMA:
newline = False
- return ast.Print(dest, expressions, newline, print_node.lineno,
- print_node.column)
+ return ast.Print(dest, expressions, newline, print_node.get_lineno(),
+ print_node.get_column())
def handle_del_stmt(self, del_node):
- targets = self.handle_exprlist(del_node.children[1], ast.Del)
- return ast.Delete(targets, del_node.lineno, del_node.column)
+ targets = self.handle_exprlist(del_node.get_child(1), ast.Del)
+ return ast.Delete(targets, del_node.get_lineno(), del_node.get_column())
def handle_flow_stmt(self, flow_node):
- first_child = flow_node.children[0]
+ first_child = flow_node.get_child(0)
first_child_type = first_child.type
if first_child_type == syms.break_stmt:
- return ast.Break(flow_node.lineno, flow_node.column)
+ return ast.Break(flow_node.get_lineno(), flow_node.get_column())
elif first_child_type == syms.continue_stmt:
- return ast.Continue(flow_node.lineno, flow_node.column)
+ return ast.Continue(flow_node.get_lineno(), flow_node.get_column())
elif first_child_type == syms.yield_stmt:
- yield_expr = self.handle_expr(first_child.children[0])
- return ast.Expr(yield_expr, flow_node.lineno, flow_node.column)
+ yield_expr = self.handle_expr(first_child.get_child(0))
+ return ast.Expr(yield_expr, flow_node.get_lineno(), flow_node.get_column())
elif first_child_type == syms.return_stmt:
- if len(first_child.children) == 1:
+ if first_child.num_children() == 1:
values = None
else:
- values = self.handle_testlist(first_child.children[1])
- return ast.Return(values, flow_node.lineno, flow_node.column)
+ values = self.handle_testlist(first_child.get_child(1))
+ return ast.Return(values, flow_node.get_lineno(), flow_node.get_column())
elif first_child_type == syms.raise_stmt:
exc = None
value = None
traceback = None
- child_count = len(first_child.children)
+ child_count = first_child.num_children()
if child_count >= 2:
- exc = self.handle_expr(first_child.children[1])
+ exc = self.handle_expr(first_child.get_child(1))
if child_count >= 4:
- value = self.handle_expr(first_child.children[3])
+ value = self.handle_expr(first_child.get_child(3))
if child_count == 6:
- traceback = self.handle_expr(first_child.children[5])
- return ast.Raise(exc, value, traceback, flow_node.lineno,
- flow_node.column)
+ traceback = self.handle_expr(first_child.get_child(5))
+ return ast.Raise(exc, value, traceback, flow_node.get_lineno(),
+ flow_node.get_column())
else:
raise AssertionError("unknown flow statement")
@@ -184,32 +184,32 @@
while True:
import_name_type = import_name.type
if import_name_type == syms.import_as_name:
- name = import_name.children[0].value
- if len(import_name.children) == 3:
- as_name = import_name.children[2].value
- self.check_forbidden_name(as_name, import_name.children[2])
+ name = import_name.get_child(0).get_value()
+ if import_name.num_children() == 3:
+ as_name = import_name.get_child(2).get_value()
+ self.check_forbidden_name(as_name, import_name.get_child(2))
else:
as_name = None
- self.check_forbidden_name(name, import_name.children[0])
+ self.check_forbidden_name(name, import_name.get_child(0))
return ast.alias(name, as_name)
elif import_name_type == syms.dotted_as_name:
- if len(import_name.children) == 1:
- import_name = import_name.children[0]
+ if import_name.num_children() == 1:
+ import_name = import_name.get_child(0)
continue
- alias = self.alias_for_import_name(import_name.children[0],
+ alias = self.alias_for_import_name(import_name.get_child(0),
store=False)
- asname_node = import_name.children[2]
- alias.asname = asname_node.value
+ asname_node = import_name.get_child(2)
+ alias.asname = asname_node.get_value()
self.check_forbidden_name(alias.asname, asname_node)
return alias
elif import_name_type == syms.dotted_name:
- if len(import_name.children) == 1:
- name = import_name.children[0].value
+ if import_name.num_children() == 1:
+ name = import_name.get_child(0).get_value()
if store:
- self.check_forbidden_name(name, import_name.children[0])
+ self.check_forbidden_name(name, import_name.get_child(0))
return ast.alias(name, None)
- name_parts = [import_name.children[i].value
- for i in range(0, len(import_name.children), 2)]
+ name_parts = [import_name.get_child(i).get_value()
+ for i in range(0, import_name.num_children(), 2)]
name = ".".join(name_parts)
return ast.alias(name, None)
elif import_name_type == tokens.STAR:
@@ -218,20 +218,20 @@
raise AssertionError("unknown import name")
def handle_import_stmt(self, import_node):
- import_node = import_node.children[0]
+ import_node = import_node.get_child(0)
if import_node.type == syms.import_name:
- dotted_as_names = import_node.children[1]
- aliases = [self.alias_for_import_name(dotted_as_names.children[i])
- for i in range(0, len(dotted_as_names.children), 2)]
- return ast.Import(aliases, import_node.lineno, import_node.column)
+ dotted_as_names = import_node.get_child(1)
+ aliases = [self.alias_for_import_name(dotted_as_names.get_child(i))
+ for i in range(0, dotted_as_names.num_children(), 2)]
+ return ast.Import(aliases, import_node.get_lineno(), import_node.get_column())
elif import_node.type == syms.import_from:
- child_count = len(import_node.children)
+ child_count = import_node.num_children()
module = None
modname = None
i = 1
dot_count = 0
while i < child_count:
- child = import_node.children[i]
+ child = import_node.get_child(i)
if child.type == syms.dotted_name:
module = self.alias_for_import_name(child, False)
i += 1
@@ -241,16 +241,16 @@
i += 1
dot_count += 1
i += 1
- after_import_type = import_node.children[i].type
+ after_import_type = import_node.get_child(i).type
star_import = False
if after_import_type == tokens.STAR:
- names_node = import_node.children[i]
+ names_node = import_node.get_child(i)
star_import = True
elif after_import_type == tokens.LPAR:
- names_node = import_node.children[i + 1]
+ names_node = import_node.get_child(i + 1)
elif after_import_type == syms.import_as_names:
- names_node = import_node.children[i]
- if len(names_node.children) % 2 == 0:
+ names_node = import_node.get_child(i)
+ if names_node.num_children() % 2 == 0:
self.error("trailing comma is only allowed with "
"surronding parenthesis", names_node)
else:
@@ -258,25 +258,25 @@
if star_import:
aliases = [self.alias_for_import_name(names_node)]
else:
- aliases = [self.alias_for_import_name(names_node.children[i])
- for i in range(0, len(names_node.children), 2)]
+ aliases = [self.alias_for_import_name(names_node.get_child(i))
+ for i in range(0, names_node.num_children(), 2)]
if module is not None:
modname = module.name
return ast.ImportFrom(modname, aliases, dot_count,
- import_node.lineno, import_node.column)
+ import_node.get_lineno(), import_node.get_column())
else:
raise AssertionError("unknown import node")
def handle_global_stmt(self, global_node):
- names = [global_node.children[i].value
- for i in range(1, len(global_node.children), 2)]
- return ast.Global(names, global_node.lineno, global_node.column)
+ names = [global_node.get_child(i).get_value()
+ for i in range(1, global_node.num_children(), 2)]
+ return ast.Global(names, global_node.get_lineno(), global_node.get_column())
def handle_exec_stmt(self, exec_node):
- child_count = len(exec_node.children)
+ child_count = exec_node.num_children()
globs = None
locs = None
- to_execute = self.handle_expr(exec_node.children[1])
+ to_execute = self.handle_expr(exec_node.get_child(1))
if child_count < 4:
if isinstance(to_execute, ast.Tuple) and \
(len(to_execute.elts) == 2 or len(to_execute.elts) == 3):
@@ -285,272 +285,273 @@
locs = to_execute.elts[2]
to_execute = to_execute.elts[0]
elif child_count >= 4:
- globs = self.handle_expr(exec_node.children[3])
+ globs = self.handle_expr(exec_node.get_child(3))
if child_count == 6:
- locs = self.handle_expr(exec_node.children[5])
- return ast.Exec(to_execute, globs, locs, exec_node.lineno,
- exec_node.column)
+ locs = self.handle_expr(exec_node.get_child(5))
+ return ast.Exec(to_execute, globs, locs, exec_node.get_lineno(),
+ exec_node.get_column())
def handle_assert_stmt(self, assert_node):
- expr = self.handle_expr(assert_node.children[1])
+ expr = self.handle_expr(assert_node.get_child(1))
msg = None
- if len(assert_node.children) == 4:
- msg = self.handle_expr(assert_node.children[3])
- return ast.Assert(expr, msg, assert_node.lineno, assert_node.column)
+ if assert_node.num_children() == 4:
+ msg = self.handle_expr(assert_node.get_child(3))
+ return ast.Assert(expr, msg, assert_node.get_lineno(), assert_node.get_column())
def handle_suite(self, suite_node):
- first_child = suite_node.children[0]
+ first_child = suite_node.get_child(0)
if first_child.type == syms.simple_stmt:
- end = len(first_child.children) - 1
- if first_child.children[end - 1].type == tokens.SEMI:
+ end = first_child.num_children() - 1
+ if first_child.get_child(end - 1).type == tokens.SEMI:
end -= 1
- stmts = [self.handle_stmt(first_child.children[i])
+ stmts = [self.handle_stmt(first_child.get_child(i))
for i in range(0, end, 2)]
else:
stmts = []
- for i in range(2, len(suite_node.children) - 1):
- stmt = suite_node.children[i]
+ for i in range(2, suite_node.num_children() - 1):
+ stmt = suite_node.get_child(i)
stmt_count = self.number_of_statements(stmt)
if stmt_count == 1:
stmts.append(self.handle_stmt(stmt))
else:
- simple_stmt = stmt.children[0]
- for j in range(0, len(simple_stmt.children), 2):
- stmt = simple_stmt.children[j]
- if not stmt.children:
+ simple_stmt = stmt.get_child(0)
+ for j in range(0, simple_stmt.num_children(), 2):
+ stmt = simple_stmt.get_child(j)
+ if not stmt.num_children():
break
stmts.append(self.handle_stmt(stmt))
return stmts
def handle_if_stmt(self, if_node):
- child_count = len(if_node.children)
+ child_count = if_node.num_children()
if child_count == 4:
- test = self.handle_expr(if_node.children[1])
- suite = self.handle_suite(if_node.children[3])
- return ast.If(test, suite, None, if_node.lineno, if_node.column)
- otherwise_string = if_node.children[4].value
+ test = self.handle_expr(if_node.get_child(1))
+ suite = self.handle_suite(if_node.get_child(3))
+ return ast.If(test, suite, None, if_node.get_lineno(), if_node.get_column())
+ otherwise_string = if_node.get_child(4).get_value()
if otherwise_string == "else":
- test = self.handle_expr(if_node.children[1])
- suite = self.handle_suite(if_node.children[3])
- else_suite = self.handle_suite(if_node.children[6])
- return ast.If(test, suite, else_suite, if_node.lineno,
- if_node.column)
+ test = self.handle_expr(if_node.get_child(1))
+ suite = self.handle_suite(if_node.get_child(3))
+ else_suite = self.handle_suite(if_node.get_child(6))
+ return ast.If(test, suite, else_suite, if_node.get_lineno(),
+ if_node.get_column())
elif otherwise_string == "elif":
elif_count = child_count - 4
- after_elif = if_node.children[elif_count + 1]
+ after_elif = if_node.get_child(elif_count + 1)
if after_elif.type == tokens.NAME and \
- after_elif.value == "else":
+ after_elif.get_value() == "else":
has_else = True
elif_count -= 3
else:
has_else = False
elif_count /= 4
if has_else:
- last_elif = if_node.children[-6]
+ last_elif = if_node.get_child(-6)
last_elif_test = self.handle_expr(last_elif)
- elif_body = self.handle_suite(if_node.children[-4])
- else_body = self.handle_suite(if_node.children[-1])
+ elif_body = self.handle_suite(if_node.get_child(-4))
+ else_body = self.handle_suite(if_node.get_child(-1))
otherwise = [ast.If(last_elif_test, elif_body, else_body,
- last_elif.lineno, last_elif.column)]
+ last_elif.get_lineno(), last_elif.get_column())]
elif_count -= 1
else:
otherwise = None
for i in range(elif_count):
offset = 5 + (elif_count - i - 1) * 4
- elif_test_node = if_node.children[offset]
+ elif_test_node = if_node.get_child(offset)
elif_test = self.handle_expr(elif_test_node)
- elif_body = self.handle_suite(if_node.children[offset + 2])
+ elif_body = self.handle_suite(if_node.get_child(offset + 2))
new_if = ast.If(elif_test, elif_body, otherwise,
- elif_test_node.lineno, elif_test_node.column)
+ elif_test_node.get_lineno(), elif_test_node.get_column())
otherwise = [new_if]
- expr = self.handle_expr(if_node.children[1])
- body = self.handle_suite(if_node.children[3])
- return ast.If(expr, body, otherwise, if_node.lineno, if_node.column)
+ expr = self.handle_expr(if_node.get_child(1))
+ body = self.handle_suite(if_node.get_child(3))
+ return ast.If(expr, body, otherwise, if_node.get_lineno(), if_node.get_column())
else:
raise AssertionError("unknown if statement configuration")
def handle_while_stmt(self, while_node):
- loop_test = self.handle_expr(while_node.children[1])
- body = self.handle_suite(while_node.children[3])
- if len(while_node.children) == 7:
- otherwise = self.handle_suite(while_node.children[6])
+ loop_test = self.handle_expr(while_node.get_child(1))
+ body = self.handle_suite(while_node.get_child(3))
+ if while_node.num_children() == 7:
+ otherwise = self.handle_suite(while_node.get_child(6))
else:
otherwise = None
- return ast.While(loop_test, body, otherwise, while_node.lineno,
- while_node.column)
+ return ast.While(loop_test, body, otherwise, while_node.get_lineno(),
+ while_node.get_column())
def handle_for_stmt(self, for_node):
- target_node = for_node.children[1]
+ target_node = for_node.get_child(1)
target_as_exprlist = self.handle_exprlist(target_node, ast.Store)
- if len(target_node.children) == 1:
+ if target_node.num_children() == 1:
target = target_as_exprlist[0]
else:
target = ast.Tuple(target_as_exprlist, ast.Store,
- target_node.lineno, target_node.column)
- expr = self.handle_testlist(for_node.children[3])
- body = self.handle_suite(for_node.children[5])
- if len(for_node.children) == 9:
- otherwise = self.handle_suite(for_node.children[8])
+ target_node.get_lineno(), target_node.get_column())
+ expr = self.handle_testlist(for_node.get_child(3))
+ body = self.handle_suite(for_node.get_child(5))
+ if for_node.num_children() == 9:
+ otherwise = self.handle_suite(for_node.get_child(8))
else:
otherwise = None
- return ast.For(target, expr, body, otherwise, for_node.lineno,
- for_node.column)
+ return ast.For(target, expr, body, otherwise, for_node.get_lineno(),
+ for_node.get_column())
def handle_except_clause(self, exc, body):
test = None
target = None
suite = self.handle_suite(body)
- child_count = len(exc.children)
+ child_count = exc.num_children()
if child_count >= 2:
- test = self.handle_expr(exc.children[1])
+ test = self.handle_expr(exc.get_child(1))
if child_count == 4:
- target_child = exc.children[3]
+ target_child = exc.get_child(3)
target = self.handle_expr(target_child)
self.set_context(target, ast.Store)
- return ast.ExceptHandler(test, target, suite, exc.lineno, exc.column)
+ return ast.ExceptHandler(test, target, suite, exc.get_lineno(), exc.get_column())
def handle_try_stmt(self, try_node):
- body = self.handle_suite(try_node.children[2])
- child_count = len(try_node.children)
+ body = self.handle_suite(try_node.get_child(2))
+ child_count = try_node.num_children()
except_count = (child_count - 3 ) // 3
otherwise = None
finally_suite = None
- possible_extra_clause = try_node.children[-3]
+ possible_extra_clause = try_node.get_child(-3)
if possible_extra_clause.type == tokens.NAME:
- if possible_extra_clause.value == "finally":
+ if possible_extra_clause.get_value() == "finally":
if child_count >= 9 and \
- try_node.children[-6].type == tokens.NAME:
- otherwise = self.handle_suite(try_node.children[-4])
+ try_node.get_child(-6).type == tokens.NAME:
+ otherwise = self.handle_suite(try_node.get_child(-4))
except_count -= 1
- finally_suite = self.handle_suite(try_node.children[-1])
+ finally_suite = self.handle_suite(try_node.get_child(-1))
except_count -= 1
else:
- otherwise = self.handle_suite(try_node.children[-1])
+ otherwise = self.handle_suite(try_node.get_child(-1))
except_count -= 1
if except_count:
handlers = []
for i in range(except_count):
base_offset = i * 3
- exc = try_node.children[3 + base_offset]
- except_body = try_node.children[5 + base_offset]
+ exc = try_node.get_child(3 + base_offset)
+ except_body = try_node.get_child(5 + base_offset)
handlers.append(self.handle_except_clause(exc, except_body))
except_ast = ast.TryExcept(body, handlers, otherwise,
- try_node.lineno, try_node.column)
+ try_node.get_lineno(), try_node.get_column())
if finally_suite is None:
return except_ast
body = [except_ast]
- return ast.TryFinally(body, finally_suite, try_node.lineno,
- try_node.column)
+ return ast.TryFinally(body, finally_suite, try_node.get_lineno(),
+ try_node.get_column())
def handle_with_stmt(self, with_node):
- body = self.handle_suite(with_node.children[-1])
- i = len(with_node.children) - 1
+ body = self.handle_suite(with_node.get_child(-1))
+ i = with_node.num_children() - 1
while True:
i -= 2
- item = with_node.children[i]
- test = self.handle_expr(item.children[0])
- if len(item.children) == 3:
- target = self.handle_expr(item.children[2])
+ item = with_node.get_child(i)
+ test = self.handle_expr(item.get_child(0))
+ if item.num_children() == 3:
+ target = self.handle_expr(item.get_child(2))
self.set_context(target, ast.Store)
else:
target = None
- wi = ast.With(test, target, body, with_node.lineno,
- with_node.column)
+ wi = ast.With(test, target, body, with_node.get_lineno(),
+ with_node.get_column())
if i == 1:
break
body = [wi]
return wi
def handle_classdef(self, classdef_node, decorators=None):
- name_node = classdef_node.children[1]
- name = name_node.value
+ name_node = classdef_node.get_child(1)
+ name = name_node.get_value()
self.check_forbidden_name(name, name_node)
- if len(classdef_node.children) == 4:
- body = self.handle_suite(classdef_node.children[3])
+ if classdef_node.num_children() == 4:
+ body = self.handle_suite(classdef_node.get_child(3))
return ast.ClassDef(name, None, body, decorators,
- classdef_node.lineno, classdef_node.column)
- if classdef_node.children[3].type == tokens.RPAR:
- body = self.handle_suite(classdef_node.children[5])
+ classdef_node.get_lineno(), classdef_node.get_column())
+ if classdef_node.get_child(3).type == tokens.RPAR:
+ body = self.handle_suite(classdef_node.get_child(5))
return ast.ClassDef(name, None, body, decorators,
- classdef_node.lineno, classdef_node.column)
- bases = self.handle_class_bases(classdef_node.children[3])
- body = self.handle_suite(classdef_node.children[6])
- return ast.ClassDef(name, bases, body, decorators, classdef_node.lineno,
- classdef_node.column)
+ classdef_node.get_lineno(), classdef_node.get_column())
+ bases = self.handle_class_bases(classdef_node.get_child(3))
+ body = self.handle_suite(classdef_node.get_child(6))
+ return ast.ClassDef(name, bases, body, decorators, classdef_node.get_lineno(),
+ classdef_node.get_column())
def handle_class_bases(self, bases_node):
- if len(bases_node.children) == 1:
- return [self.handle_expr(bases_node.children[0])]
+ if bases_node.num_children() == 1:
+ return [self.handle_expr(bases_node.get_child(0))]
return self.get_expression_list(bases_node)
def handle_funcdef(self, funcdef_node, decorators=None):
- name_node = funcdef_node.children[1]
- name = name_node.value
+ name_node = funcdef_node.get_child(1)
+ name = name_node.get_value()
self.check_forbidden_name(name, name_node)
- args = self.handle_arguments(funcdef_node.children[2])
- body = self.handle_suite(funcdef_node.children[4])
+ args = self.handle_arguments(funcdef_node.get_child(2))
+ body = self.handle_suite(funcdef_node.get_child(4))
return ast.FunctionDef(name, args, body, decorators,
- funcdef_node.lineno, funcdef_node.column)
+ funcdef_node.get_lineno(), funcdef_node.get_column())
def handle_decorated(self, decorated_node):
- decorators = self.handle_decorators(decorated_node.children[0])
- definition = decorated_node.children[1]
+ decorators = self.handle_decorators(decorated_node.get_child(0))
+ definition = decorated_node.get_child(1)
if definition.type == syms.funcdef:
node = self.handle_funcdef(definition, decorators)
elif definition.type == syms.classdef:
node = self.handle_classdef(definition, decorators)
else:
raise AssertionError("unkown decorated")
- node.lineno = decorated_node.lineno
- node.col_offset = decorated_node.column
+ node.lineno = decorated_node.get_lineno()
+ node.col_offset = decorated_node.get_column()
return node
def handle_decorators(self, decorators_node):
- return [self.handle_decorator(dec) for dec in decorators_node.children]
+ return [self.handle_decorator(decorators_node.get_child(i))
+ for i in range(decorators_node.num_children())]
def handle_decorator(self, decorator_node):
- dec_name = self.handle_dotted_name(decorator_node.children[1])
- if len(decorator_node.children) == 3:
+ dec_name = self.handle_dotted_name(decorator_node.get_child(1))
+ if decorator_node.num_children() == 3:
dec = dec_name
- elif len(decorator_node.children) == 5:
+ elif decorator_node.num_children() == 5:
dec = ast.Call(dec_name, None, None, None, None,
- decorator_node.lineno, decorator_node.column)
+ decorator_node.get_lineno(), decorator_node.get_column())
else:
- dec = self.handle_call(decorator_node.children[3], dec_name)
+ dec = self.handle_call(decorator_node.get_child(3), dec_name)
return dec
def handle_dotted_name(self, dotted_name_node):
- base_value = dotted_name_node.children[0].value
- name = ast.Name(base_value, ast.Load, dotted_name_node.lineno,
- dotted_name_node.column)
- for i in range(2, len(dotted_name_node.children), 2):
- attr = dotted_name_node.children[i].value
- name = ast.Attribute(name, attr, ast.Load, dotted_name_node.lineno,
- dotted_name_node.column)
+ base_value = dotted_name_node.get_child(0).get_value()
+ name = ast.Name(base_value, ast.Load, dotted_name_node.get_lineno(),
+ dotted_name_node.get_column())
+ for i in range(2, dotted_name_node.num_children(), 2):
+ attr = dotted_name_node.get_child(i).get_value()
+ name = ast.Attribute(name, attr, ast.Load, dotted_name_node.get_lineno(),
+ dotted_name_node.get_column())
return name
More information about the pypy-commit
mailing list