]> granicus.if.org Git - python/commitdiff
Issue #24731: Fixed crash on converting objects with special methods
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 25 Nov 2015 13:53:19 +0000 (15:53 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 25 Nov 2015 13:53:19 +0000 (15:53 +0200)
__bytes__, __trunc__, and __float__ returning instances of subclasses of
bytes, int, and float to subclasses of bytes, int, and float correspondingly.

1  2 
Lib/test/test_bytes.py
Misc/NEWS
Objects/bytesobject.c
Objects/longobject.c

Simple merge
diff --cc Misc/NEWS
index 56a4d2d84138a6b7168f2610c6eb07cf4f006ec7,99e962be28a88626c09741a6b3ead80031b34b0d..3f22a20c41b8d2881be5cbd21f70dba395bc8fff
+++ b/Misc/NEWS
@@@ -10,6 -10,49 +10,10 @@@ Release date: XXXX-XX-X
  Core and Builtins
  -----------------
  
 -Library
 --------
 -
 -- Issue #25725: Fixed a reference leak in pickle.loads() when unpickling
 -  invalid data including tuple instructions.
 -
 -- Issue #25663: In the Readline completer, avoid listing duplicate global
 -  names, and search the global namespace before searching builtins.
 -
 -- Issue #25688: Fixed file leak in ElementTree.iterparse() raising an error.
 -
 -- Issue #23914: Fixed SystemError raised by unpickler on broken pickle data.
 -
 -- Issue #25691: Fixed crash on deleting ElementTree.Element attributes.
 -
 -- Issue #25624: ZipFile now always writes a ZIP_STORED header for directory
 -  entries.  Patch by Dingyuan Wang.
 -
 -
 -What's New in Python 3.5.1 final?
 -=================================
 -
 -Release date: 2015-12-06
 -
 -Core and Builtins
 ------------------
 -
 -Library
 --------
 -
 -
 -What's New in Python 3.5.1 release candidate 1?
 -===============================================
 -
 -Release date: 2015-11-22
 -
 -Core and Builtins
 ------------------
 -
+ - Issue #24731: Fixed crash on converting objects with special methods
+   __bytes__, __trunc__, and __float__ returning instances of subclasses of
+   bytes, int, and float to subclasses of bytes, int, and float correspondingly.
  - Issue #25630: Fix a possible segfault during argument parsing in functions
    that accept filesystem paths.
  
index 6a9e06231c713dfbe660172786179745886f09a4,8e098494de6d71cf8bf18fb8bb780597685e075b..cbdac86aecbf6525daf0b820867bd9297efa0a71
@@@ -3523,40 -3386,9 +3523,40 @@@ _PyBytes_FromIterator(PyObject *x
      return NULL;
  }
  
 +PyObject *
 +PyBytes_FromObject(PyObject *x)
 +{
 +    if (x == NULL) {
 +        PyErr_BadInternalCall();
 +        return NULL;
 +    }
 +
 +    if (PyBytes_CheckExact(x)) {
 +        Py_INCREF(x);
 +        return x;
 +    }
 +
 +    /* Use the modern buffer interface */
 +    if (PyObject_CheckBuffer(x))
 +        return _PyBytes_FromBuffer(x);
 +
 +    if (PyList_CheckExact(x))
 +        return _PyBytes_FromList(x);
 +
 +    if (PyTuple_CheckExact(x))
 +        return _PyBytes_FromTuple(x);
 +
 +    if (PyUnicode_Check(x)) {
 +        PyErr_SetString(PyExc_TypeError,
 +                        "cannot convert unicode object to bytes");
 +        return NULL;
 +    }
 +
 +    return _PyBytes_FromIterator(x);
 +}
 +
  static PyObject *
str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
bytes_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
  {
      PyObject *tmp, *pnew;
      Py_ssize_t n;
Simple merge