aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2022-02-08 22:45:37 +0200
committerMatti Picus <matti.picus@gmail.com>2022-02-08 22:45:37 +0200
commitdc3c2ed078dfce0499413d1a9472826a29f7230d (patch)
treeb8252eb23aa54016d5fa8b3d903da6f1349611ec
parentupdate bundled setuptools to 58.1.0 to get fix for new PyPy layout (diff)
parentmerge default (diff)
downloadpypy-dc3c2ed078dfce0499413d1a9472826a29f7230d.tar.gz
pypy-dc3c2ed078dfce0499413d1a9472826a29f7230d.tar.bz2
pypy-dc3c2ed078dfce0499413d1a9472826a29f7230d.zip
merge py3.7
-rw-r--r--extra_tests/ctypes_tests/test_structures.py16
-rw-r--r--lib_pypy/_hashlib/__init__.py5
-rw-r--r--pypy/doc/release-v7.3.8.rst51
-rw-r--r--pypy/module/_locale/moduledef.py2
-rw-r--r--pypy/module/cpyext/api.py4
-rw-r--r--pypy/module/pyexpat/interp_pyexpat.py55
-rw-r--r--pypy/module/pyexpat/test/test_build.py2
-rw-r--r--pypy/module/select/interp_epoll.py102
-rw-r--r--pypy/objspace/std/intobject.py22
-rw-r--r--rpython/rlib/_rsocket_rffi.py6
-rw-r--r--rpython/rlib/rvmprof/src/shared/vmprof_getpc.h2
-rw-r--r--rpython/translator/c/src/dtoa.c6
-rw-r--r--rpython/translator/c/src/support.c2
-rw-r--r--rpython/translator/tool/cbuild.py4
14 files changed, 198 insertions, 81 deletions
diff --git a/extra_tests/ctypes_tests/test_structures.py b/extra_tests/ctypes_tests/test_structures.py
index 96531ddf3c..6ec11e69b8 100644
--- a/extra_tests/ctypes_tests/test_structures.py
+++ b/extra_tests/ctypes_tests/test_structures.py
@@ -31,7 +31,6 @@ def test___init__():
class Person(Structure):
_fields_ = (("name", c_char*10),
("age", c_int))
-
def __init__(self, name, surname, age):
self.name = name + b' ' + surname
self.age = age
@@ -221,3 +220,18 @@ def test_memoryview_endian():
mv = memoryview(c_les)
assert mv.format == 'B'
+def test_deepcopy_struct():
+ # issue 3022: missing __new__ on StructureInstanceAutoFree
+ import copy
+
+ class struct_a(Structure):
+ pass
+
+ class struct_b(Structure):
+ pass
+
+ struct_a._fields_ = [('first',struct_b)]
+
+ a = struct_a()
+ b = copy.deepcopy(a)
+ assert isinstance(b.first, struct_b)
diff --git a/lib_pypy/_hashlib/__init__.py b/lib_pypy/_hashlib/__init__.py
index 070bcdba5c..50e3a04ab3 100644
--- a/lib_pypy/_hashlib/__init__.py
+++ b/lib_pypy/_hashlib/__init__.py
@@ -56,6 +56,11 @@ class HASH(object):
return "<%s HASH object at 0x%s>" % (self.name, id(self))
def update(self, string):
+ if isinstance(string, str):
+ raise TypeError("Unicode-objects must be encoded before hashing")
+ elif isinstance(string, memoryview):
+ # issue 2756: ffi.from_buffer() cannot handle memoryviews
+ string = string.tobytes()
buf = ffi.from_buffer(string)
with self.lock:
# XXX try to not release the GIL for small requests
diff --git a/pypy/doc/release-v7.3.8.rst b/pypy/doc/release-v7.3.8.rst
index 94d2004458..332eb8e99b 100644
--- a/pypy/doc/release-v7.3.8.rst
+++ b/pypy/doc/release-v7.3.8.rst
@@ -3,7 +3,7 @@ PyPy v7.3.8: release of python 2.7, 3.7, 3.8, and 3.9-beta
==========================================================
..
- Changelog up to commit c859fcd9d243
+ Changelog up to commit 0360402c9455
.. note::
This is a pre-release announcement. When the release actually happens, it
@@ -30,25 +30,28 @@ wish to share. The release includes four different interpreters:
- PyPy3.9, which is an interpreter supporting the syntax and the features of
Python 3.9, including the stdlib for CPython 3.9.10. As this is our first
release of this interpreter, we relate to this as "beta" quality. We
- welcome testing of this version, if you discover incompatibilites, please
- report them so we can gain confidence in the version.
+ welcome testing of this version, if you discover incompatibilities, please
+ report them so we can gain confidence in the version. There is still a known
+ `speed regression`_ around ``**kwargs`` handling in 3.9.
The interpreters are based on much the same codebase, thus the multiple
release. This is a micro release, all APIs are compatible with the other 7.3
releases. Highlights of the release, since the release of 7.3.7 in late October 2021,
include:
- - Improvement in ssl's use of CFFI buffers to speed up ``recv`` and ``recvinto``
- PyPy3.9 uses an RPython version of the PEG parser which brought with it a
cleanup of the lexer and parser in general
- Fixed a regression in PyPy3.8 when JITting empty list comprehenshions
- Tweaked some issues around changing the file layout after packaging to make
- PyPy more compatible with CPython
+ the on-disk layout of PyPy3.8 more compatible with CPython. This requires
+ ``setuptools>=58.1.0``
- RPython now allows the target executable to have a ``.`` in its name, so
PyPy3.9 will produce a ``pypy3.9-c`` and ``libpypy3.9-c.so``. Changing the
name of the shared object to be version-specific (it used to be
``libpypy3-c.so``) will allow it to live alongside other versions.
- Building PyPy3.9+ accepts a ``--platlibdir`` argument like CPython.
+ - Improvement in ssl's use of CFFI buffers to speed up ``recv`` and ``recvinto``
+ - Update the packaged OpenSSL to 1.1.1m
We recommend updating. You can find links to download the v7.3.8 releases here:
@@ -122,6 +125,10 @@ Bugfixes shared across versions
- Copy ``dtoa`` changes from CPython (bpo40780_)
- Use ``symtable`` to improve the position of "duplicate argument" errors
- Add ``__builtins__`` to globals ``dict`` when calling ``eval`` (issue 3584_)
+- Update embedded OpenSSL to 1.1.1m (bpo43522_)
+- Avoid using ``epoll_event`` directly from RPython since it is a ``packed struct``
+- Clean up some compilation warnings around `const char *`` conversions to
+ ``char *``
Speedups and enhancements shared across versions
------------------------------------------------
@@ -138,6 +145,8 @@ Speedups and enhancements shared across versions
to make the meaning more clear. These are functions only useful for internal
testing (issue 3617_).
- Prepare ``_ssl`` for OpenSSL3
+- Improve ``x << y`` where ``x`` and ``y`` are ints but the results doesn't fit
+ into a machine word: don't convert ``y`` to ``rbigint`` and back to int
C-API (cpyext) and C-extensions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -170,7 +179,22 @@ Python 3.7+ bugfixes
segfault
- Detail about ``PYTHONIOENCODING``: if the encoding or the error is ommitted,
always use ``utf-8/strict`` (instead of asking the locale)
-- Fix for bpo43522_, use embedded OpenSSL to 1.1.1m
+- Disallow overriding the ``__context__`` descriptor from ``BaseException``
+ when chaining exceptions (issue 3644_)
+- Replace ``raise ImportError`` with ``raise ModuleNotFoundError`` where
+ appropriate in pure-python equivalents of CPython builtin modules
+- Add missing ``rewinddir()`` at the end of ``os.scandir``
+- ``os.dup2`` now returns ``fd2``
+- Make ``__fspath__`` errors compatible with CPython
+- Fix handling of backslash in raw unicode escape decoders that don't
+ start valid escape sequences (issue 3652_)
+- Add missing equivalent of ``_Py_RestoreSignals()`` call in ``fork_exec``
+- Catch exceptions in ``atexit`` functions to avoid crashing the interpreter at
+ shutdown
+- Update ``fast2locals`` to deal with the fact that it's now possible to
+ delete cell vars (was forbidden in python2) (issue 3656_)
+delete cell vars (was forbidden in python2).
+- Allow hashing memoryviews (issue 2756_)
Python 3.7+ speedups and enhancements
-------------------------------------
@@ -186,13 +210,14 @@ Python 3.7+ speedups and enhancements
- Fix the ctypes errcheck_ protocol
- Various fixes in the windows-only ``_overlapped`` module (issue 3625_)
- Implement ``-X utf8``
+- Add ``WITH_DYLD`` to ``sysconfig`` for darwin
Python 3.7 C-API
~~~~~~~~~~~~~~~~
- Added ``PyDescr_NewGetSet``, ``PyModule_NewObject``, ``PyModule_ExecDef``,
``PyCodec_Decode``, ``PyCodec_Encode``, ``PyErr_WarnExplicit``,
- ``PyDateTime_TimeZone_UTC``
+ ``PyDateTime_TimeZone_UTC``, ``PyUnicode_DecodeLocaleAndSize``
- Fix segfault when using format strings in ``PyUnicode_FromFormat`` and
``PyErr_Format`` (issue 3593_)
- ``_PyObject_LookupAttrId`` does not raise ``AttributeError``
@@ -203,6 +228,7 @@ Python 3.7 C-API
- Alias ``PyDateTime_DATE_GET_FOLD``, which CPython uses instead of the
documented ``PyDateTime_GET_FOLD`` (issue 3627_)
- Add some ``_PyHASH*`` macros (issue 3590_)
+- Fix signature of ``PyUnicode_DecodeLocale`` (issue 3661_)
Python 3.8+ bugfixes
--------------------
@@ -217,6 +243,8 @@ Python 3.8+ bugfixes
stdlib tests to allow PyPy's repr. bpo35545_ touches on this. (issue 3628_)
- Fix small bugs when raising errors in various stdlib modules that caused
stdlib test failures
+- Update bundled ``setuptools`` to ``58.1.0`` to get the fix for the new PyPy
+ layout
Python 3.8+ speedups and enhancements
-------------------------------------
@@ -238,7 +266,10 @@ Python 3.8 C-API
``tp_pypy_flags`` slot. Users should upgrade Cython to 0.2.26 to avoid a
compiler warning.
- Add ``PyCompilerFlags.cf_feature_version`` (bpo35766_)
+- Distinguish between a c-api ``CMethod`` and an app-level ``Method``, which
+ is important for obscure reasons
+.. _2756: https://foss.heptapod.net/pypy/pypy/-/issues/2756
.. _3589: https://foss.heptapod.net/pypy/pypy/-/issues/3589
.. _3584: https://foss.heptapod.net/pypy/pypy/-/issues/3584
.. _3598: https://foss.heptapod.net/pypy/pypy/-/issues/3598
@@ -257,6 +288,11 @@ Python 3.8 C-API
.. _3628: https://foss.heptapod.net/pypy/pypy/-/issues/3628
.. _3627: https://foss.heptapod.net/pypy/pypy/-/issues/3627
.. _3630: https://foss.heptapod.net/pypy/pypy/-/issues/3630
+.. _3644: https://foss.heptapod.net/pypy/pypy/-/issues/3644
+.. _3642: https://foss.heptapod.net/pypy/pypy/-/issues/3642
+.. _3652: https://foss.heptapod.net/pypy/pypy/-/issues/3652
+.. _3656: https://foss.heptapod.net/pypy/pypy/-/issues/3656
+.. _3661: https://foss.heptapod.net/pypy/pypy/-/issues/3661
.. _bpo35883: https://bugs.python.org/issue35883
.. _bpo44954: https://bugs.python.org/issue44954
.. _bpo40780: https://bugs.python.org/issue40780
@@ -264,3 +300,4 @@ Python 3.8 C-API
.. _bpo43522: https://bugs.python.org/issue43522
.. _bpo35545: https://bugs.python.org/issue35545
.. _errcheck: https://docs.python.org/3/library/ctypes.html#ctypes._FuncPtr.errcheck
+.. _`speed regression`_: https://foss.heptapod.net/pypy/pypy/-/issues/3649
diff --git a/pypy/module/_locale/moduledef.py b/pypy/module/_locale/moduledef.py
index 6d91bf3718..550f8e8b4d 100644
--- a/pypy/module/_locale/moduledef.py
+++ b/pypy/module/_locale/moduledef.py
@@ -22,7 +22,7 @@ class Module(MixedModule):
interpleveldefs.update({
'nl_langinfo': 'interp_locale.nl_langinfo',
})
- if rlocale.HAVE_LIBINTL:
+ if rlocale.HAVE_LIBINTL and not sys.platform == 'darwin':
interpleveldefs.update({
'gettext': 'interp_locale.gettext',
'dgettext': 'interp_locale.dgettext',
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
index dc91e2932a..6951020c00 100644
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1252,7 +1252,7 @@ def attach_c_functions(space, eci, prefix):
)
state.C.flag_setters = {}
for c_name, attr in _flags:
- _, setter = rffi.CExternVariable(rffi.SIGNED, c_name, eci_flags,
+ _, setter = rffi.CExternVariable(rffi.INT_real, c_name, eci_flags,
_nowrapper=True, c_type='int')
state.C.flag_setters[attr] = setter
@@ -1274,7 +1274,7 @@ def init_flags(space):
state = space.fromcache(State)
for _, attr in _flags:
f = state.C.flag_setters[attr]
- f(space.sys.get_flag(attr))
+ f(rffi.cast(rffi.INT_real, space.sys.get_flag(attr)))
#_____________________________________________________
# Build the bridge DLL, Allow extension DLLs to call
diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py
index 83c5d84feb..371e5bfd13 100644
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -135,9 +135,10 @@ def expat_external(*a, **kw):
return rffi.llexternal(*a, **kw)
INTERNED_CCHARP = "INTERNED"
+CONST_CCHARPP = lltype.Ptr(lltype.Array(rffi.CONST_CCHARP, hints={'nolength': True}))
HANDLERS = dict(
- StartElementHandler = [INTERNED_CCHARP, rffi.CCHARPP],
+ StartElementHandler = [INTERNED_CCHARP, CONST_CCHARPP],
EndElementHandler = [INTERNED_CCHARP],
ProcessingInstructionHandler = [INTERNED_CCHARP, INTERNED_CCHARP],
CharacterDataHandler = [rffi.CCHARP, rffi.INT],
@@ -145,23 +146,23 @@ HANDLERS = dict(
NotationDeclHandler = [INTERNED_CCHARP] * 4,
StartNamespaceDeclHandler = [INTERNED_CCHARP, INTERNED_CCHARP],
EndNamespaceDeclHandler = [INTERNED_CCHARP],
- CommentHandler = [rffi.CCHARP],
+ CommentHandler = [INTERNED_CCHARP],
StartCdataSectionHandler = [],
EndCdataSectionHandler = [],
- DefaultHandler = [rffi.CCHARP, rffi.INT],
- DefaultHandlerExpand = [rffi.CCHARP, rffi.INT],
+ DefaultHandler = [INTERNED_CCHARP, rffi.INT],
+ DefaultHandlerExpand = [INTERNED_CCHARP, rffi.INT],
NotStandaloneHandler = [],
- ExternalEntityRefHandler = [rffi.CCHARP] + [INTERNED_CCHARP] * 3,
+ ExternalEntityRefHandler = [INTERNED_CCHARP] * 4,
StartDoctypeDeclHandler = [INTERNED_CCHARP, INTERNED_CCHARP,
INTERNED_CCHARP, rffi.INT],
EndDoctypeDeclHandler = [],
- EntityDeclHandler = [INTERNED_CCHARP, rffi.INT, rffi.CCHARP, rffi.INT,
+ EntityDeclHandler = [INTERNED_CCHARP, rffi.INT, INTERNED_CCHARP, rffi.INT,
INTERNED_CCHARP, INTERNED_CCHARP, INTERNED_CCHARP,
INTERNED_CCHARP],
- XmlDeclHandler = [rffi.CCHARP, rffi.CCHARP, rffi.INT],
+ XmlDeclHandler = [INTERNED_CCHARP, INTERNED_CCHARP, rffi.INT],
ElementDeclHandler = [INTERNED_CCHARP, lltype.Ptr(XML_Content)],
AttlistDeclHandler = [INTERNED_CCHARP, INTERNED_CCHARP,
- rffi.CCHARP, rffi.CCHARP, rffi.INT],
+ INTERNED_CCHARP, INTERNED_CCHARP, rffi.INT],
)
if XML_COMBINED_VERSION >= 19504:
HANDLERS['SkippedEntityHandler'] = [INTERNED_CCHARP, rffi.INT]
@@ -224,13 +225,14 @@ for index, (name, params) in enumerate(HANDLERS.items()):
'w_arg%d = parser.w_convert_attributes(space, arg%d)' % (i, i))
elif name in ["CharacterDataHandler", "DefaultHandlerExpand", "DefaultHandler"] and i == 0:
converters.append(
- 'w_arg%d = parser.w_convert_charp_n(space, arg%d, arg%d)' % (i, i, i+1))
+ 'w_arg%d = parser.w_convert_interned_n(space, arg%d, arg%d)' % (i, i, i+1))
del warg_names[i+1]
+ ARG = rffi.CONST_CCHARP
elif name in ["EntityDeclHandler"] and i == 2:
converters.append(
- 'w_arg%d = parser.w_convert_charp_n(space, arg%d, arg%d)' % (i, i, i+1))
+ 'w_arg%d = parser.w_convert_interned_n(space, arg%d, arg%d)' % (i, i, i+1))
del warg_names[i+1]
-
+ ARG = rffi.CONST_CCHARP
# the standard conversions
elif ARG == rffi.CCHARP:
converters.append(
@@ -238,7 +240,7 @@ for index, (name, params) in enumerate(HANDLERS.items()):
elif ARG == INTERNED_CCHARP:
converters.append(
'w_arg%d = parser.w_convert_interned(space, arg%d)' % (i, i))
- ARG = rffi.CCHARP
+ ARG = rffi.CONST_CCHARP
elif ARG == lltype.Ptr(XML_Content):
converters.append(
'w_arg%d = parser.w_convert_model(space, arg%d)' % (i, i))
@@ -324,7 +326,7 @@ def UnknownEncodingHandlerData_callback(ll_userdata, name, info):
space = userdata.space
parser = userdata.parser()
- name = rffi.charp2str(name)
+ name = rffi.constcharp2str(name)
try:
parser.UnknownEncodingHandler(space, name, info)
@@ -337,7 +339,7 @@ def UnknownEncodingHandlerData_callback(ll_userdata, name, info):
result = 1
return rffi.cast(rffi.INT, result)
callback_type = lltype.Ptr(lltype.FuncType(
- [rffi.VOIDP, rffi.CCHARP, XML_Encoding_Ptr], rffi.INT))
+ [rffi.VOIDP, rffi.CONST_CCHARP, XML_Encoding_Ptr], rffi.INT))
XML_SetUnknownEncodingHandler = expat_external(
'XML_SetUnknownEncodingHandler',
[XML_Parser, callback_type, rffi.VOIDP], lltype.Void)
@@ -378,7 +380,7 @@ XML_GetErrorCode = expat_external(
'XML_GetErrorCode', [XML_Parser], rffi.INT)
XML_ErrorString = expat_external(
'XML_ErrorString', [rffi.INT],
- rffi.CCHARP)
+ rffi.CONST_CCHARP)
XML_GetCurrentLineNumber = expat_external(
'XML_GetCurrentLineNumber', [XML_Parser], rffi.INT)
XML_GetErrorLineNumber = XML_GetCurrentLineNumber
@@ -396,10 +398,10 @@ XML_ExternalEntityParserCreate = expat_external(
XML_Parser)
XML_ExpatVersion = expat_external(
- 'XML_ExpatVersion', [], rffi.CCHARP)
+ 'XML_ExpatVersion', [], rffi.CONST_CCHARP)
def get_expat_version(space):
- return space.newtext(rffi.charp2str(XML_ExpatVersion()))
+ return space.newtext(rffi.constcharp2str(XML_ExpatVersion()))
def get_expat_version_info(space):
return space.newtuple([
@@ -497,7 +499,7 @@ getting the advantage of providing document type information to the parser.
def w_convert_interned(self, space, data):
if not data:
return space.w_None
- w_data = self.w_convert_charp(space, data)
+ w_data = self.w_convert(space, rffi.constcharp2str(data))
if not self.w_intern:
return w_data
@@ -516,6 +518,13 @@ getting the advantage of providing document type information to the parser.
else:
return space.w_None
+ def w_convert_interned_n(self, space, data, length):
+ ll_length = rffi.cast(lltype.Signed, length)
+ if data:
+ return self.w_convert(space, rffi.constcharpsize2str(data, ll_length))
+ else:
+ return space.w_None
+
def w_convert_attributes(self, space, attrs):
if self.specified_attributes:
maxindex = XML_GetSpecifiedAttributeCount(self.itself)
@@ -526,15 +535,15 @@ getting the advantage of providing document type information to the parser.
if self.ordered_attributes:
w_attrs = space.newlist([
- self.w_convert_charp(space, attrs[i])
+ self.w_convert_interned(space, attrs[i])
for i in range(maxindex)])
else:
w_attrs = space.newdict()
for i in range(0, maxindex, 2):
space.setitem(
w_attrs,
- self.w_convert_charp(space, attrs[i]),
- self.w_convert_charp(space, attrs[i + 1]))
+ self.w_convert_interned(space, attrs[i]),
+ self.w_convert_interned(space, attrs[i + 1]))
return w_attrs
@@ -711,7 +720,7 @@ information passed to the ExternalEntityRefHandler."""
# Error management
def set_error(self, space, code):
- err = rffi.charp2strn(XML_ErrorString(code), 200)
+ err = rffi.constcharp2str(XML_ErrorString(code))
lineno = XML_GetCurrentLineNumber(self.itself)
colno = XML_GetCurrentColumnNumber(self.itself)
msg = "%s: line %d, column %d" % (err, lineno, colno)
@@ -867,5 +876,5 @@ Return a new XML parser object."""
def ErrorString(space, code):
"""ErrorString(errno) -> string
Returns string error for given number."""
- return space.newtext(rffi.charp2str(XML_ErrorString(code)))
+ return space.newtext(rffi.constcharp2str(XML_ErrorString(code)))
diff --git a/pypy/module/pyexpat/test/test_build.py b/pypy/module/pyexpat/test/test_build.py
index 1a916835c5..67895f02e7 100644
--- a/pypy/module/pyexpat/test/test_build.py
+++ b/pypy/module/pyexpat/test/test_build.py
@@ -21,7 +21,7 @@ def test_build():
parser = interp_pyexpat.XML_ParserCreate("test")
interp_pyexpat.XML_ParserFree(parser)
res = interp_pyexpat.XML_ErrorString(3)
- os.write(1, rffi.charp2str(res))
+ os.write(1, rffi.constcharp2str(res))
return 0
t = TranslationContext()
diff --git a/pypy/module/select/interp_epoll.py b/pypy/module/select/interp_epoll.py
index 809098badc..91b780101b 100644
--- a/pypy/module/select/interp_epoll.py
+++ b/pypy/module/select/interp_epoll.py
@@ -17,7 +17,36 @@ from rpython.translator.tool.cbuild import ExternalCompilationInfo
eci = ExternalCompilationInfo(
- includes = ['sys/epoll.h']
+ includes = ['sys/epoll.h', 'stddef.h', 'stdlib.h', 'stdio.h'],
+ post_include_bits = [
+ "RPY_EXTERN\n"
+ "int pypy_epoll_ctl(int, int, int, uint32_t);"
+ "RPY_EXTERN\n"
+ "int pypy_epoll_wait(int, uint32_t*, int*, int, int);"
+ ],
+ separate_module_sources = ['''
+ int pypy_epoll_ctl(int epfd, int op, int fd, uint32_t events){
+ struct epoll_event evt = {events, (epoll_data_t)fd};
+ return epoll_ctl(epfd, op, fd, &evt);
+ };
+ int pypy_epoll_wait(int epfd, uint32_t *fds, int *evnts, int maxevents, int timeout){
+ struct epoll_event *events = malloc(sizeof(struct epoll_event) * maxevents);
+ if (events == NULL) {
+ return -1;
+ }
+ int ret = epoll_wait(epfd, events, maxevents, timeout);
+ if (ret < 0) {
+ free(events);
+ return ret;
+ }
+ for (int i=0; i<ret; i++) {
+ fds[i] = events[i].data.fd;
+ evnts[i] = events[i].events;
+ }
+ free(events);
+ return ret;
+ };
+ '''],
)
class CConfig:
@@ -50,7 +79,6 @@ for symbol in public_symbols:
public_symbols[symbol] = intmask(cconfig[symbol])
-epoll_event = cconfig["epoll_event"]
EPOLL_CTL_ADD = cconfig["EPOLL_CTL_ADD"]
EPOLL_CTL_MOD = cconfig["EPOLL_CTL_MOD"]
EPOLL_CTL_DEL = cconfig["EPOLL_CTL_DEL"]
@@ -64,22 +92,22 @@ epoll_create1 = rffi.llexternal(
"epoll_create1", [rffi.INT], rffi.INT, compilation_info=eci,
save_err=rffi.RFFI_SAVE_ERRNO
)
-epoll_ctl = rffi.llexternal(
- "epoll_ctl",
- [rffi.INT, rffi.INT, rffi.INT, lltype.Ptr(epoll_event)],
+pypy_epoll_ctl = rffi.llexternal(
+ "pypy_epoll_ctl",
+ [rffi.INT, rffi.INT, rffi.INT, rffi.UINT],
rffi.INT,
compilation_info=eci,
save_err=rffi.RFFI_SAVE_ERRNO
)
-epoll_wait = rffi.llexternal(
- "epoll_wait",
- [rffi.INT, rffi.CArrayPtr(epoll_event), rffi.INT, rffi.INT],
+pypy_epoll_wait = rffi.llexternal(
+ "pypy_epoll_wait",
+ [rffi.INT, rffi.CArrayPtr(rffi.UINT), rffi.CArrayPtr(rffi.INT),
+ rffi.INT, rffi.INT],
rffi.INT,
compilation_info=eci,
save_err=rffi.RFFI_SAVE_ERRNO
)
-
class W_Epoll(W_Root):
def __init__(self, space, epfd):
self.space = space
@@ -121,15 +149,11 @@ class W_Epoll(W_Root):
def epoll_ctl(self, space, ctl, w_fd, eventmask, ignore_ebadf=False):
fd = space.c_filedescriptor_w(w_fd)
- with lltype.scoped_alloc(epoll_event) as ev:
- ev.c_events = rffi.cast(rffi.UINT, eventmask)
- rffi.setintfield(ev.c_data, 'c_fd', fd)
-
- result = epoll_ctl(self.epfd, ctl, fd, ev)
- if ignore_ebadf and get_saved_errno() == errno.EBADF:
- result = 0
- if result < 0:
- raise exception_from_saved_errno(space, space.w_IOError)
+ result = pypy_epoll_ctl(self.epfd, ctl, fd, rffi.cast(rffi.UINT, eventmask))
+ if ignore_ebadf and get_saved_errno() == errno.EBADF:
+ result = 0
+ if result < 0:
+ raise exception_from_saved_errno(space, space.w_IOError)
def descr_get_closed(self, space):
return space.newbool(self.get_closed())
@@ -171,27 +195,27 @@ class W_Epoll(W_Root):
raise oefmt(space.w_ValueError,
"maxevents must be greater than 0, not %d", maxevents)
- with lltype.scoped_alloc(rffi.CArray(epoll_event), maxevents) as evs:
- while True:
- nfds = epoll_wait(self.epfd, evs, maxevents, itimeout)
- if nfds < 0:
- if get_saved_errno() == errno.EINTR:
- space.getexecutioncontext().checksignals()
- if itimeout >= 0:
- timeout = end_time - timeutils.monotonic(space)
- timeout = max(timeout, 0.0)
- itimeout = int(timeout * 1000.0 + 0.999)
- continue
- raise exception_from_saved_errno(space, space.w_IOError)
- break
-
- elist_w = [None] * nfds
- for i in xrange(nfds):
- event = evs[i]
- elist_w[i] = space.newtuple(
- [space.newint(event.c_data.c_fd), space.newint(event.c_events)]
- )
- return space.newlist(elist_w)
+ with lltype.scoped_alloc(rffi.CArray(rffi.UINT), maxevents) as fids:
+ with lltype.scoped_alloc(rffi.CArray(rffi.INT), maxevents) as events:
+ while True:
+ nfds = pypy_epoll_wait(self.epfd, fids, events, maxevents, itimeout)
+ if nfds < 0:
+ if get_saved_errno() == errno.EINTR:
+ space.getexecutioncontext().checksignals()
+ if itimeout >= 0:
+ timeout = end_time - timeutils.monotonic(space)
+ timeout = max(timeout, 0.0)
+ itimeout = int(timeout * 1000.0 + 0.999)
+ continue
+ raise exception_from_saved_errno(space, space.w_IOError)
+ break
+
+ elist_w = [None] * nfds
+ for i in xrange(nfds):
+ elist_w[i] = space.newtuple(
+ [space.newint(fids[i]), space.newint(events[i])]
+ )
+ return space.newlist(elist_w)
def descr_enter(self, space):
self.check_closed(space)
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
index 21008c89bb..668c916d60 100644
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -760,11 +760,15 @@ class W_IntObject(W_AbstractIntObject):
descr_or, descr_ror = _make_generic_descr_binop('or', ovf=False)
descr_xor, descr_rxor = _make_generic_descr_binop('xor', ovf=False)
- def _make_descr_binop(func, ovf=True, ovf2small=None):
+ def _make_descr_binop(func, ovf=True, ovf2small=None, ovf_func=None):
opname = func.__name__[1:]
descr_name, descr_rname = 'descr_' + opname, 'descr_r' + opname
if ovf:
- ovf2long = _make_ovf2long(opname, ovf2small)
+ if ovf_func:
+ ovf2long = ovf_func
+ assert not ovf2small # must be part of ovf_func
+ else:
+ ovf2long = _make_ovf2long(opname, ovf2small)
@func_renamer(descr_name)
def descr_binop(self, space, w_other):
@@ -802,8 +806,20 @@ class W_IntObject(W_AbstractIntObject):
return descr_binop, descr_rbinop
+ def _ovf2long_lshift(space, x, w_x, y, w_y):
+ if _recover_with_smalllong(space):
+ return _lshift_ovf2small(space, x, y)
+
+ from pypy.objspace.std.longobject import W_LongObject, W_AbstractLongObject
+ if w_x is None or not isinstance(w_x, W_AbstractLongObject):
+ w_x = W_LongObject.fromint(space, x)
+
+ # crucially, *don't* convert w_y to W_LongObject, it will just be
+ # converted back (huge lshifts always overflow)
+ return w_x._int_lshift(space, y)
+
descr_lshift, descr_rlshift = _make_descr_binop(
- _lshift, ovf2small=_lshift_ovf2small)
+ _lshift, ovf_func=_ovf2long_lshift)
descr_rshift, descr_rrshift = _make_descr_binop(_rshift, ovf=False)
descr_floordiv, descr_rfloordiv = _make_descr_binop(_floordiv)
diff --git a/rpython/rlib/_rsocket_rffi.py b/rpython/rlib/_rsocket_rffi.py
index bcd031a050..3fb4ca72b1 100644
--- a/rpython/rlib/_rsocket_rffi.py
+++ b/rpython/rlib/_rsocket_rffi.py
@@ -1,7 +1,7 @@
from rpython.rtyper.lltypesystem import rffi
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.tool import rffi_platform as platform
-from rpython.rtyper.lltypesystem.rffi import CCHARP
+from rpython.rtyper.lltypesystem.rffi import CCHARP, CONST_CCHARP
from rpython.rlib import jit
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.translator.platform import platform as target_platform
@@ -1164,7 +1164,7 @@ def external_c(name, args, result, **kwargs):
if _POSIX:
dup = external('dup', [socketfd_type], socketfd_type, save_err=SAVE_ERR)
- gai_strerror = external('gai_strerror', [rffi.INT], CCHARP)
+ gai_strerror = external('gai_strerror', [rffi.INT], CONST_CCHARP)
#h_errno = c_int.in_dll(socketdll, 'h_errno')
#
@@ -1432,7 +1432,7 @@ else:
socket_strerror_str = os.strerror
def gai_strerror_str(errno):
- return rffi.charp2str(gai_strerror(errno))
+ return rffi.constcharp2str(gai_strerror(errno))
def socket_strerror_unicode(errno):
return socket_strerror_str(errno).decode('latin-1')
diff --git a/rpython/rlib/rvmprof/src/shared/vmprof_getpc.h b/rpython/rlib/rvmprof/src/shared/vmprof_getpc.h
index 5a633715cb..da643ad04b 100644
--- a/rpython/rlib/rvmprof/src/shared/vmprof_getpc.h
+++ b/rpython/rlib/rvmprof/src/shared/vmprof_getpc.h
@@ -52,7 +52,7 @@
// the needed __BSD_VISIBLE.
#ifdef __APPLE__
#include <limits.h>
-#define _XOPEN_SOURCE 500
+#define _XOPEN_SOURCE 700
#endif
#include "vmprof_config.h"
diff --git a/rpython/translator/c/src/dtoa.c b/rpython/translator/c/src/dtoa.c
index 225ba42316..35204ae5c0 100644
--- a/rpython/translator/c/src/dtoa.c
+++ b/rpython/translator/c/src/dtoa.c
@@ -122,9 +122,15 @@
#define HAVE_UINT32_T
#define HAVE_INT32_T
#define HAVE_UINT64_T
+#ifndef PY_UINT32_T
#define PY_UINT32_T unsigned int
+#endif
+#ifndef PY_INT32_T
#define PY_INT32_T int
+#endif
+#ifndef PY_UINT64_T
#define PY_UINT64_T unsigned long long
+#endif
#include <limits.h>
#include <stdlib.h>
#include <errno.h>
diff --git a/rpython/translator/c/src/support.c b/rpython/translator/c/src/support.c
index 3b05c5aa4f..b4b1837058 100644
--- a/rpython/translator/c/src/support.c
+++ b/rpython/translator/c/src/support.c
@@ -12,7 +12,9 @@
#define Sign_bit 0x80000000
#define NAN_WORD0 0x7ff80000
#define NAN_WORD1 0
+#ifndef PY_UINT32_T
#define PY_UINT32_T unsigned int
+#endif
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define IEEE_8087
diff --git a/rpython/translator/tool/cbuild.py b/rpython/translator/tool/cbuild.py
index 0225f2f948..a9cdf21996 100644
--- a/rpython/translator/tool/cbuild.py
+++ b/rpython/translator/tool/cbuild.py
@@ -119,6 +119,10 @@ class ExternalCompilationInfo(object):
macro, value = macro.split('=')
else:
value = '1'
+ if macro == '_XOPEN_SOURCE':
+ # use default _XOPEN_SOURCE since we always define
+ # _GNU_SOURCE, which then defines a _XOPEN_SOURCE itself
+ continue
pre_include_bits.append('#define %s %s' % (macro, value))
elif arg.startswith('-L') or arg.startswith('-l'):
raise ValueError('linker flag found in compiler options: %r'