diff options
author | Matti Picus <matti.picus@gmail.com> | 2020-10-10 22:04:47 +0300 |
---|---|---|
committer | Matti Picus <matti.picus@gmail.com> | 2020-10-10 22:04:47 +0300 |
commit | e1674d3b4b309b904b2c71850394015b4664a96b (patch) | |
tree | 464f5a2a5843e5285a9ae4afe34a2ce8379f4f0b /lib_pypy | |
parent | merge default into win64 (diff) | |
parent | merge stdlib-2.7.18-3 which updates stdlib (diff) | |
download | pypy-e1674d3b4b309b904b2c71850394015b4664a96b.tar.gz pypy-e1674d3b4b309b904b2c71850394015b4664a96b.tar.bz2 pypy-e1674d3b4b309b904b2c71850394015b4664a96b.zip |
merge default into branch
Diffstat (limited to 'lib_pypy')
-rw-r--r-- | lib_pypy/_cffi_ssl/_stdssl/__init__.py | 4 | ||||
-rw-r--r-- | lib_pypy/_cffi_ssl/_stdssl/certificate.py | 3 | ||||
-rw-r--r-- | lib_pypy/_ctypes/array.py | 29 | ||||
-rw-r--r-- | lib_pypy/_ctypes/basics.py | 7 | ||||
-rw-r--r-- | lib_pypy/_ctypes/pointer.py | 22 | ||||
-rw-r--r-- | lib_pypy/_ctypes/primitive.py | 25 | ||||
-rw-r--r-- | lib_pypy/_ctypes/structure.py | 11 | ||||
-rw-r--r-- | lib_pypy/_ctypes_test.c | 207 | ||||
-rw-r--r-- | lib_pypy/_sqlite3.py | 3 | ||||
-rw-r--r-- | lib_pypy/_testcapimodule.c | 264 | ||||
-rw-r--r-- | lib_pypy/_tkinter/tclobj.py | 2 | ||||
-rw-r--r-- | lib_pypy/datetime.py | 7 |
12 files changed, 530 insertions, 54 deletions
diff --git a/lib_pypy/_cffi_ssl/_stdssl/__init__.py b/lib_pypy/_cffi_ssl/_stdssl/__init__.py index 54cad963c0..c444fc3b66 100644 --- a/lib_pypy/_cffi_ssl/_stdssl/__init__.py +++ b/lib_pypy/_cffi_ssl/_stdssl/__init__.py @@ -744,7 +744,7 @@ def _fs_decode(name): return name.decode(sys.getfilesystemencoding()) def _fs_converter(name): """ name must not be None """ - if isinstance(name, str): + if isinstance(name, unicode): return name.encode(sys.getfilesystemencoding()) return bytes(name) @@ -908,7 +908,7 @@ class _SSLContext(object): # Minimal security flags for server and client side context. # Client sockets ignore server-side parameters. options |= lib.SSL_OP_NO_COMPRESSION - # options |= lib.SSL_OP_CIPHER_SERVER_PREFERENCE + options |= lib.SSL_OP_CIPHER_SERVER_PREFERENCE options |= lib.SSL_OP_SINGLE_DH_USE options |= lib.SSL_OP_SINGLE_ECDH_USE lib.SSL_CTX_set_options(self.ctx, options) diff --git a/lib_pypy/_cffi_ssl/_stdssl/certificate.py b/lib_pypy/_cffi_ssl/_stdssl/certificate.py index 6b49e88b14..fe660bde81 100644 --- a/lib_pypy/_cffi_ssl/_stdssl/certificate.py +++ b/lib_pypy/_cffi_ssl/_stdssl/certificate.py @@ -265,6 +265,9 @@ def _get_crl_dp(certificate): count = lib.sk_DIST_POINT_num(dps) for i in range(count): dp = lib.sk_DIST_POINT_value(dps, i); + if not dp.distpoint: + # Ignore empty DP value, CVE-2019-5010 + continue gns = dp.distpoint.name.fullname; jcount = lib.sk_GENERAL_NAME_num(gns) diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py index e972a83ba0..df64e3509a 100644 --- a/lib_pypy/_ctypes/array.py +++ b/lib_pypy/_ctypes/array.py @@ -109,19 +109,22 @@ class ArrayMeta(_CDataMeta): # array accepts very strange parameters as part of structure # or function argument... from ctypes import c_char, c_wchar - if issubclass(self._type_, (c_char, c_wchar)): - if isinstance(value, basestring): - if len(value) > self._length_: - raise ValueError("Invalid length") - value = self(*value) - elif not isinstance(value, self): - raise TypeError("expected string or Unicode object, %s found" - % (value.__class__.__name__,)) - else: - if isinstance(value, tuple): - if len(value) > self._length_: - raise RuntimeError("Invalid length") - value = self(*value) + if isinstance(value, self): + return value + if hasattr(self, '_type_'): + if issubclass(self._type_, (c_char, c_wchar)): + if isinstance(value, basestring): + if len(value) > self._length_: + raise ValueError("Invalid length") + value = self(*value) + elif not isinstance(value, self): + raise TypeError( + "expected string or Unicode object, %s found" + % (value.__class__.__name__,)) + if isinstance(value, tuple): + if len(value) > self._length_: + raise RuntimeError("Invalid length") + value = self(*value) return _CDataMeta.from_param(self, value) def _build_ffiargtype(self): diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py index d8f91caa29..c0f49b157d 100644 --- a/lib_pypy/_ctypes/basics.py +++ b/lib_pypy/_ctypes/basics.py @@ -46,6 +46,9 @@ class COMError(Exception): self.details = details class _CDataMeta(type): + def _is_abstract(self): + return getattr(self, '_type_', 'abstract') == 'abstract' + def from_param(self, value): if isinstance(value, self): return value @@ -96,6 +99,8 @@ class _CDataMeta(type): return self.from_address(dll.__pypy_dll__.getaddressindll(name)) def from_buffer(self, obj, offset=0): + if self._is_abstract(): + raise TypeError('abstract class') size = self._sizeofinstances() if isinstance(obj, (str, unicode)): # hack, buffer(str) will always return a readonly buffer. @@ -122,6 +127,8 @@ class _CDataMeta(type): return result def from_buffer_copy(self, obj, offset=0): + if self._is_abstract(): + raise TypeError('abstract class') size = self._sizeofinstances() buf = buffer(obj, offset, size) if len(buf) < size: diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py index 0894788d81..f865f8870f 100644 --- a/lib_pypy/_ctypes/pointer.py +++ b/lib_pypy/_ctypes/pointer.py @@ -40,14 +40,17 @@ class PointerType(_CDataMeta): def from_param(self, value): if value is None: return self(None) - # If we expect POINTER(<type>), but receive a <type> instance, accept - # it by calling byref(<type>). - if isinstance(value, self._type_): - return byref(value) - # Array instances are also pointers when the item types are the same. - if isinstance(value, (_Pointer, Array)): - if issubclass(type(value)._type_, self._type_): - return value + if isinstance(value, self): + return value + if hasattr(self, '_type_'): + # If we expect POINTER(<type>), but receive a <type> instance, accept + # it by calling byref(<type>). + if isinstance(value, self._type_): + return byref(value) + # Array instances are also pointers when the item types are the same. + if isinstance(value, (_Pointer, Array)): + if issubclass(type(value)._type_, self._type_): + return value return _CDataMeta.from_param(self, value) def _sizeofinstances(self): @@ -60,6 +63,8 @@ class PointerType(_CDataMeta): return True def set_type(self, TP): + if self._is_abstract(): + raise TypeError('abstract class') ffiarray = _rawffi.Array('P') def __init__(self, value=None): if not hasattr(self, '_buffer'): @@ -179,6 +184,7 @@ def POINTER(cls): klass = type(_Pointer)("LP_%s" % cls, (_Pointer,), {}) + klass._type_ = 'P' _pointer_type_cache[id(klass)] = klass return klass else: diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py index 84e7f4364c..54e3ecd2a7 100644 --- a/lib_pypy/_ctypes/primitive.py +++ b/lib_pypy/_ctypes/primitive.py @@ -146,6 +146,14 @@ FROM_PARAM_BY_TYPE = { 'P': from_param_void_p, } +CTYPES_TO_PEP3118_TABLE = { + 'i': {2: 'h', 4: 'i', 8: 'q'}, + 'I': {2: 'H', 4: 'I', 8: 'Q'}, + 'l': {4: 'l', 8: 'q'}, + 'L': {4: 'L', 8: 'Q'}, + '?': {1: '?', 2: 'h', 4: 'l', 8: 'q'}, +} + class SimpleType(_CDataMeta): def __new__(self, name, bases, dct): try: @@ -157,6 +165,8 @@ class SimpleType(_CDataMeta): break else: raise AttributeError("cannot find _type_ attribute") + if tp == 'abstract': + tp = 'i' if (not isinstance(tp, str) or not len(tp) == 1 or tp not in SIMPLE_TYPE_CHARS): @@ -168,7 +178,11 @@ class SimpleType(_CDataMeta): result._ffishape_ = tp result._fficompositesize_ = None result._ffiarray = ffiarray - result._format = byteorder[sys.byteorder] + tp + if tp in CTYPES_TO_PEP3118_TABLE: + pep_code = CTYPES_TO_PEP3118_TABLE[tp][_rawffi.sizeof(tp)] + else: + pep_code = tp + result._format = byteorder[sys.byteorder] + pep_code if tp == 'z': # c_char_p def _getvalue(self): @@ -328,7 +342,7 @@ class SimpleType(_CDataMeta): result.__ctype_be__ = result swapped.__ctype_be__ = result swapped.__ctype_le__ = swapped - swapped._format = '<' + tp + swapped._format = '<' + pep_code else: name += '_be' swapped = self.__new__(self, name, bases, dct) @@ -336,7 +350,7 @@ class SimpleType(_CDataMeta): result.__ctype_le__ = result swapped.__ctype_le__ = result swapped.__ctype_be__ = swapped - swapped._format = '>' + tp + swapped._format = '>' + pep_code from _ctypes import sizeof def _getval(self): return swap_bytes(self._buffer[0], sizeof(self), name, 'get') @@ -353,7 +367,8 @@ class SimpleType(_CDataMeta): def from_param(self, value): if isinstance(value, self): return value - + if self._type_ == 'abstract': + raise TypeError('abstract class') from_param_f = FROM_PARAM_BY_TYPE.get(self._type_) if from_param_f: res = from_param_f(self, value) @@ -387,7 +402,7 @@ class SimpleType(_CDataMeta): class _SimpleCData(_CData): __metaclass__ = SimpleType - _type_ = 'i' + _type_ = 'abstract' def __init__(self, value=DEFAULT_VALUE): if not hasattr(self, '_buffer'): diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py index 5324717c33..cc0c373221 100644 --- a/lib_pypy/_ctypes/structure.py +++ b/lib_pypy/_ctypes/structure.py @@ -119,6 +119,8 @@ class Field(object): if self.is_bitfield: # bitfield member, use direct access return obj._buffer.__getattr__(self.name) + elif not isinstance(obj, _CData): + raise(TypeError, 'not a ctype instance') else: fieldtype = self.ctype offset = self.num @@ -142,6 +144,8 @@ class Field(object): from ctypes import memmove dest = obj._buffer.fieldaddress(self.name) memmove(dest, arg, fieldtype._fficompositesize_) + elif not isinstance(obj, _CData): + raise(TypeError, 'not a ctype instance') else: obj._buffer.__setattr__(self.name, arg) @@ -209,6 +213,9 @@ class StructOrUnionMeta(_CDataMeta): __setattr__ = struct_setattr + def _is_abstract(self): + return False + def from_address(self, address): instance = StructOrUnion.__new__(self) if isinstance(address, _rawffi.StructureInstance): @@ -317,7 +324,9 @@ class StructOrUnion(_CData): memmove(addr, origin, self._fficompositesize_) def _to_ffi_param(self): - return self._buffer + newparam = StructOrUnion.__new__(type(self)) + self._copy_to(newparam._buffer.buffer) + return newparam._buffer def __buffer__(self, flags): fmt = type(self)._getformat() diff --git a/lib_pypy/_ctypes_test.c b/lib_pypy/_ctypes_test.c index 0815aba391..f38292b460 100644 --- a/lib_pypy/_ctypes_test.c +++ b/lib_pypy/_ctypes_test.c @@ -54,6 +54,19 @@ _testfunc_cbk_large_struct(Test in, void (*func)(Test)) func(in); } +/* + * See issue 29565. Update a structure passed by value; + * the caller should not see any change. + */ + +EXPORT(void) +_testfunc_large_struct_update_value(Test in) +{ + in.first = 0x0badf00d; + in.second = 0x0badf00d; + in.third = 0x0badf00d; +} + EXPORT(void)testfunc_array(int values[4]) { printf("testfunc_array %d %d %d %d\n", @@ -645,6 +658,200 @@ EXPORT(void) TwoOutArgs(int a, int *pi, int b, int *pj) } #ifdef MS_WIN32 + +typedef struct { + char f1; +} Size1; + +typedef struct { + char f1; + char f2; +} Size2; + +typedef struct { + char f1; + char f2; + char f3; +} Size3; + +typedef struct { + char f1; + char f2; + char f3; + char f4; +} Size4; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; +} Size5; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; + char f6; +} Size6; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; + char f6; + char f7; +} Size7; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; + char f6; + char f7; + char f8; +} Size8; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; + char f6; + char f7; + char f8; + char f9; +} Size9; + +typedef struct { + char f1; + char f2; + char f3; + char f4; + char f5; + char f6; + char f7; + char f8; + char f9; + char f10; +} Size10; + +EXPORT(Size1) TestSize1() { + Size1 f; + f.f1 = 'a'; + return f; +} + +EXPORT(Size2) TestSize2() { + Size2 f; + f.f1 = 'a'; + f.f2 = 'b'; + return f; +} + +EXPORT(Size3) TestSize3() { + Size3 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + return f; +} + +EXPORT(Size4) TestSize4() { + Size4 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + return f; +} + +EXPORT(Size5) TestSize5() { + Size5 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + return f; +} + +EXPORT(Size6) TestSize6() { + Size6 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + f.f6 = 'f'; + return f; +} + +EXPORT(Size7) TestSize7() { + Size7 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + f.f6 = 'f'; + f.f7 = 'g'; + return f; +} + +EXPORT(Size8) TestSize8() { + Size8 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + f.f6 = 'f'; + f.f7 = 'g'; + f.f8 = 'h'; + return f; +} + +EXPORT(Size9) TestSize9() { + Size9 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + f.f6 = 'f'; + f.f7 = 'g'; + f.f8 = 'h'; + f.f9 = 'i'; + return f; +} + +EXPORT(Size10) TestSize10() { + Size10 f; + f.f1 = 'a'; + f.f2 = 'b'; + f.f3 = 'c'; + f.f4 = 'd'; + f.f5 = 'e'; + f.f6 = 'f'; + f.f7 = 'g'; + f.f8 = 'h'; + f.f9 = 'i'; + f.f10 = 'j'; + return f; +} + +#endif + +#ifdef MS_WIN32 EXPORT(S2H) __stdcall s_ret_2h_func(S2H inp) { return ret_2h_func(inp); } EXPORT(S8I) __stdcall s_ret_8i_func(S8I inp) { return ret_8i_func(inp); } #endif diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py index 61eba030e6..a0e6d8e1b8 100644 --- a/lib_pypy/_sqlite3.py +++ b/lib_pypy/_sqlite3.py @@ -705,6 +705,8 @@ class Cursor(object): self.__initialized = True def close(self): + if not self.__initialized: + raise ProgrammingError("Base Cursor.__init__ not called.") self.__connection._check_thread() self.__connection._check_closed() if self.__statement: @@ -988,6 +990,7 @@ class Cursor(object): return list(self) def __get_connection(self): + self.__check_cursor() return self.__connection connection = property(__get_connection) diff --git a/lib_pypy/_testcapimodule.c b/lib_pypy/_testcapimodule.c index 40d3b777fa..b33f97878c 100644 --- a/lib_pypy/_testcapimodule.c +++ b/lib_pypy/_testcapimodule.c @@ -1,6 +1,5 @@ -/* Verbatim copy of Modules/_testcapimodule.c from CPython 2.7.12 w/ +/* Verbatim copy of Modules/_testcapimodule.c from CPython 2.7.18 w/ * parts disabled that rely on the not yet supported: - * - PyBuffer_To/FromContiguous * - PyThread_exit_thread * - PyMarshal_* * (via the PYPY_NOT_SUPPORTED define) @@ -21,6 +20,14 @@ #ifndef PYPY_NOT_SUPPORTED #include "marshal.h" #endif +#include <signal.h> +#ifdef MS_WINDOWS +# include <crtdbg.h> +#endif + +#ifdef HAVE_SYS_WAIT_H +#include <sys/wait.h> /* For W_STOPCODE */ +#endif #ifdef WITH_THREAD #include "pythread.h" @@ -190,8 +197,7 @@ test_dict_iteration(PyObject* self) * PyType_Ready if it hasn't already been called */ static PyTypeObject _HashInheritanceTester_Type = { - PyObject_HEAD_INIT(NULL) - 0, /* Number of items for varobject */ + PyVarObject_HEAD_INIT(NULL, 0) "hashinheritancetester", /* Name of this type */ sizeof(PyObject), /* Basic object size */ 0, /* Item size for varobject */ @@ -318,8 +324,7 @@ static PyBufferProcs memoryviewtester_as_buffer = { }; static PyTypeObject _MemoryViewTester_Type = { - PyObject_HEAD_INIT(NULL) - 0, /* Number of items for varobject */ + PyVarObject_HEAD_INIT(NULL, 0) "memoryviewtester", /* Name of this type */ sizeof(PyObject), /* Basic object size */ 0, /* Item size for varobject */ @@ -388,7 +393,6 @@ test_broken_memoryview(PyObject* self) Py_RETURN_NONE; } -#ifndef PYPY_NOT_SUPPORTED static PyObject * test_to_contiguous(PyObject* self, PyObject *noargs) { @@ -487,7 +491,6 @@ test_from_contiguous(PyObject* self, PyObject *noargs) Py_RETURN_NONE; } -#endif /* ifndef PYPY_NOT_SUPPORTED */ /* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG) @@ -895,6 +898,26 @@ test_long_long_and_overflow(PyObject *self) return Py_None; } +static PyObject * +test_long_as_unsigned_long_long_mask(PyObject *self) +{ + unsigned PY_LONG_LONG res = PyLong_AsUnsignedLongLongMask(NULL); + + if (res != (unsigned PY_LONG_LONG)-1 || !PyErr_Occurred()) { + return raiseTestError("test_long_as_unsigned_long_long_mask", + "PyLong_AsUnsignedLongLongMask(NULL) didn't " + "complain"); + } + if (!PyErr_ExceptionMatches(PyExc_SystemError)) { + return raiseTestError("test_long_as_unsigned_long_long_mask", + "PyLong_AsUnsignedLongLongMask(NULL) raised " + "something other than SystemError"); + } + PyErr_Clear(); + Py_INCREF(Py_None); + return Py_None; +} + /* Test the L code for PyArg_ParseTuple. This should deliver a PY_LONG_LONG for both long and int arguments. The test may leak a little memory if it fails. @@ -916,8 +939,9 @@ test_L_code(PyObject *self) PyTuple_SET_ITEM(tuple, 0, num); value = -1; - if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0) + if (!PyArg_ParseTuple(tuple, "L:test_L_code", &value)) { return NULL; + } if (value != 42) return raiseTestError("test_L_code", "L code returned wrong value for long 42"); @@ -930,8 +954,9 @@ test_L_code(PyObject *self) PyTuple_SET_ITEM(tuple, 0, num); value = -1; - if (PyArg_ParseTuple(tuple, "L:test_L_code", &value) < 0) + if (!PyArg_ParseTuple(tuple, "L:test_L_code", &value)) { return NULL; + } if (value != 42) return raiseTestError("test_L_code", "L code returned wrong value for int 42"); @@ -1212,8 +1237,9 @@ test_k_code(PyObject *self) PyTuple_SET_ITEM(tuple, 0, num); value = 0; - if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0) + if (!PyArg_ParseTuple(tuple, "k:test_k_code", &value)) { return NULL; + } if (value != ULONG_MAX) return raiseTestError("test_k_code", "k code returned wrong value for long 0xFFF...FFF"); @@ -1231,8 +1257,9 @@ test_k_code(PyObject *self) PyTuple_SET_ITEM(tuple, 0, num); value = 0; - if (PyArg_ParseTuple(tuple, "k:test_k_code", &value) < 0) + if (!PyArg_ParseTuple(tuple, "k:test_k_code", &value)) { return NULL; + } if (value != (unsigned long)-0x42) return raiseTestError("test_k_code", "k code returned wrong value for long -0xFFF..000042"); @@ -1562,6 +1589,89 @@ getargs_et_hash(PyObject *self, PyObject *args) return result; } +static PyObject * +get_indices(PyObject *self, PyObject *args) +{ + int result; + PySliceObject *slice; + Py_ssize_t length, start, stop, step; + + if (!PyArg_ParseTuple(args, "On", &slice, &length)) + return NULL; + + result = PySlice_GetIndices(slice, length, &start, &stop, &step); + + if (PyErr_Occurred()) { + assert(result == -1); + return NULL; + } + + if (result == -1) { + Py_RETURN_NONE; + } + return Py_BuildValue("innn", result, start, stop, step); +} + +static PyObject * +parse_tuple_and_keywords(PyObject *self, PyObject *args) +{ + PyObject *sub_args; + PyObject *sub_kwargs; + const char *sub_format; + PyObject *sub_keywords; + + Py_ssize_t i, size; + char *keywords[8 + 1]; /* space for NULL at end */ + PyObject *o; + + int result; + PyObject *return_value = NULL; + + double buffers[8][4]; /* double ensures alignment where necessary */ + + if (!PyArg_ParseTuple(args, "OOsO:parse_tuple_and_keywords", + &sub_args, &sub_kwargs, + &sub_format, &sub_keywords)) + return NULL; + + if (!(PyList_CheckExact(sub_keywords) || PyTuple_CheckExact(sub_keywords))) { + PyErr_SetString(PyExc_ValueError, + "parse_tuple_and_keywords: sub_keywords must be either list or tuple"); + return NULL; + } + + memset(buffers, 0, sizeof(buffers)); + memset(keywords, 0, sizeof(keywords)); + + size = PySequence_Fast_GET_SIZE(sub_keywords); + if (size > 8) { + PyErr_SetString(PyExc_ValueError, + "parse_tuple_and_keywords: too many keywords in sub_keywords"); + goto exit; + } + + for (i = 0; i < size; i++) { + o = PySequence_Fast_GET_ITEM(sub_keywords, i); + keywords[i] = PyString_AsString(o); + if (keywords[i] == NULL) { + goto exit; + } + } + + result = PyArg_ParseTupleAndKeywords(sub_args, sub_kwargs, + sub_format, keywords, + buffers + 0, buffers + 1, buffers + 2, buffers + 3, + buffers + 4, buffers + 5, buffers + 6, buffers + 7); + + if (result) { + return_value = Py_None; + Py_INCREF(Py_None); + } + +exit: + return return_value; +} + #ifdef Py_USING_UNICODE static volatile int x; @@ -1592,14 +1702,16 @@ test_u_code(PyObject *self) PyTuple_SET_ITEM(tuple, 0, obj); value = 0; - if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0) + if (!PyArg_ParseTuple(tuple, "u:test_u_code", &value)) { return NULL; + } if (value != PyUnicode_AS_UNICODE(obj)) return raiseTestError("test_u_code", "u code returned wrong value for u'test'"); value = 0; - if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0) + if (!PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len)) { return NULL; + } if (value != PyUnicode_AS_UNICODE(obj) || len != PyUnicode_GET_SIZE(obj)) return raiseTestError("test_u_code", @@ -1697,8 +1809,9 @@ test_empty_argparse(PyObject *self) tuple = PyTuple_New(0); if (!tuple) return NULL; - if ((result = PyArg_ParseTuple(tuple, "|:test_empty_argparse")) < 0) + if (!(result = PyArg_ParseTuple(tuple, "|:test_empty_argparse"))) { goto done; + } dict = PyDict_New(); if (!dict) goto done; @@ -1706,8 +1819,9 @@ test_empty_argparse(PyObject *self) done: Py_DECREF(tuple); Py_XDECREF(dict); - if (result < 0) + if (!result) { return NULL; + } else { Py_RETURN_NONE; } @@ -1837,7 +1951,7 @@ set_errno(PyObject *self, PyObject *args) Py_RETURN_NONE; } -#ifdef Py_USING_UNICODE +#if defined(Py_USING_UNICODE) && !defined(Py_BUILD_CORE) static int test_run_counter = 0; static PyObject * @@ -1962,7 +2076,8 @@ static int _pending_callback(void *arg) /* The following requests n callbacks to _pending_callback. It can be * run from any python thread. */ -PyObject *pending_threadfunc(PyObject *self, PyObject *arg) +static PyObject * +pending_threadfunc(PyObject *self, PyObject *arg) { PyObject *callable; int r; @@ -2498,22 +2613,106 @@ pymarshal_read_object_from_file(PyObject* self, PyObject *args) } #endif /* ifndef PYPY_NOT_SUPPORTED */ +static PyObject* +test_raise_signal(PyObject* self, PyObject *args) +{ + int signum, err; + + if (!PyArg_ParseTuple(args, "i:raise_signal", &signum)) { + return NULL; + } + + err = raise(signum); + if (err) + return PyErr_SetFromErrno(PyExc_OSError); + + if (PyErr_CheckSignals() < 0) + return NULL; + + Py_RETURN_NONE; +} + + +#ifdef MS_WINDOWS +static PyObject* +msvcrt_CrtSetReportMode(PyObject* self, PyObject *args) +{ + int type, mode; + int res; + + if (!PyArg_ParseTuple(args, "ii:CrtSetReportMode", &type, &mode)) { + return NULL; + } + + res = _CrtSetReportMode(type, mode); + if (res == -1) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + return PyInt_FromLong(res); +} + + +static PyObject* +msvcrt_CrtSetReportFile(PyObject* self, PyObject *args) +{ + int type, file; + long res; + + if (!PyArg_ParseTuple(args, "ii:CrtSetReportFile", &type, &file)) { + return NULL; + } + + res = (long)_CrtSetReportFile(type, (_HFILE)file); + + return PyInt_FromLong(res); +} +#endif + + +#ifdef W_STOPCODE +static PyObject* +py_w_stopcode(PyObject *self, PyObject *args) +{ + int sig, status; + if (!PyArg_ParseTuple(args, "i", &sig)) { + return NULL; + } + status = W_STOPCODE(sig); + return PyLong_FromLong(status); +} +#endif + + +/* Read memory from NULL (address 0) to raise a SIGSEGV or SIGBUS signal + depending on the platform. This function is used by + test.support._crash_python() to "crash" Python. */ +static PyObject * +read_null(PyObject *self, PyObject *args) +{ + volatile int *x; + volatile int y; + + x = NULL; + y = *x; + return PyLong_FromLong(y); + +} + static PyMethodDef TestMethods[] = { {"raise_exception", raise_exception, METH_VARARGS}, {"set_errno", set_errno, METH_VARARGS}, {"test_config", (PyCFunction)test_config, METH_NOARGS}, -#ifdef Py_USING_UNICODE +#if defined(Py_USING_UNICODE) && !defined(Py_BUILD_CORE) {"test_datetime_capi", test_datetime_capi, METH_NOARGS}, #endif {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS}, {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS}, {"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS}, {"test_broken_memoryview", (PyCFunction)test_broken_memoryview,METH_NOARGS}, -#ifndef PYPY_NOT_SUPPORTED {"test_to_contiguous", (PyCFunction)test_to_contiguous, METH_NOARGS}, {"test_from_contiguous", (PyCFunction)test_from_contiguous, METH_NOARGS}, -#endif /* ifndef PYPY_NOT_SUPPORTED */ {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS}, {"test_long_and_overflow", (PyCFunction)test_long_and_overflow, METH_NOARGS}, @@ -2522,6 +2721,8 @@ static PyMethodDef TestMethods[] = { #ifdef Py_USING_UNICODE {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS}, #endif + {"get_indices", get_indices, METH_VARARGS}, + {"parse_tuple_and_keywords", parse_tuple_and_keywords, METH_VARARGS}, {"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS}, {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS}, {"test_with_docstring", (PyCFunction)test_with_docstring, METH_NOARGS, @@ -2548,6 +2749,8 @@ static PyMethodDef TestMethods[] = { {"test_longlong_api", test_longlong_api, METH_NOARGS}, {"test_long_long_and_overflow", (PyCFunction)test_long_long_and_overflow, METH_NOARGS}, + {"test_long_as_unsigned_long_long_mask", + (PyCFunction)test_long_as_unsigned_long_long_mask, METH_NOARGS}, {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS}, #endif {"getargs_f", getargs_f, METH_VARARGS}, @@ -2616,6 +2819,15 @@ static PyMethodDef TestMethods[] = { {"pymarshal_read_object_from_file", pymarshal_read_object_from_file, METH_VARARGS}, #endif /* ifndef PYPY_NOT_SUPPORTED */ + {"raise_signal", (PyCFunction)test_raise_signal, METH_VARARGS}, +#ifdef MS_WINDOWS + {"CrtSetReportMode", (PyCFunction)msvcrt_CrtSetReportMode, METH_VARARGS}, + {"CrtSetReportFile", (PyCFunction)msvcrt_CrtSetReportFile, METH_VARARGS}, +#endif +#ifdef W_STOPCODE + {"W_STOPCODE", py_w_stopcode, METH_VARARGS}, +#endif + {"_read_null", (PyCFunction)read_null, METH_NOARGS}, {NULL, NULL} /* sentinel */ }; @@ -2780,7 +2992,7 @@ init_testcapi(void) m = Py_InitModule("_testcapi", TestMethods); if (m == NULL) return; - + if (PyType_Ready(&_MemoryViewTester_Type) < 0) return; @@ -2815,6 +3027,14 @@ init_testcapi(void) PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN)); PyModule_AddObject(m, "SIZEOF_PYGC_HEAD", PyInt_FromSsize_t(sizeof(PyGC_Head))); +#ifdef MS_WINDOWS + PyModule_AddIntConstant(m, "CRT_WARN", _CRT_WARN); + PyModule_AddIntConstant(m, "CRT_ERROR", _CRT_ERROR); + PyModule_AddIntConstant(m, "CRT_ASSERT", _CRT_ASSERT); + PyModule_AddIntConstant(m, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE); + PyModule_AddIntConstant(m, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR); +#endif + TestError = PyErr_NewException("_testcapi.error", NULL, NULL); Py_INCREF(TestError); PyModule_AddObject(m, "error", TestError); diff --git a/lib_pypy/_tkinter/tclobj.py b/lib_pypy/_tkinter/tclobj.py index d5a7b2b301..483d1a1023 100644 --- a/lib_pypy/_tkinter/tclobj.py +++ b/lib_pypy/_tkinter/tclobj.py @@ -51,7 +51,7 @@ def FromWideIntObj(app, value): wide = tkffi.new("Tcl_WideInt*") if tklib.Tcl_GetWideIntFromObj(app.interp, value, wide) != tklib.TCL_OK: app.raiseTclError() - return wide[0] + return int(wide[0]) # Only when tklib.HAVE_LIBTOMMATH! def FromBignumObj(app, value): diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py index 9ca2c4e526..cd2be238f2 100644 --- a/lib_pypy/datetime.py +++ b/lib_pypy/datetime.py @@ -479,8 +479,11 @@ class timedelta(deltainterop): @classmethod def _from_microseconds(cls, us): - s, us = divmod(us, _US_PER_SECOND) - d, s = divmod(s, _SECONDS_PER_DAY) + try: + s, us = divmod(us, _US_PER_SECOND) + d, s = divmod(s, _SECONDS_PER_DAY) + except ValueError: + raise TypeError('__divmod__ must return a tuple of 2 numbers') return cls._create(d, s, us, False) @classmethod |