]> granicus.if.org Git - python/commitdiff
Issue #14889: PyBytes_FromObject(bytes) now just increfs and returns.
authorLarry Hastings <larry@hastings.org>
Fri, 25 May 2012 05:58:30 +0000 (22:58 -0700)
committerLarry Hastings <larry@hastings.org>
Fri, 25 May 2012 05:58:30 +0000 (22:58 -0700)
Previously, if you passed in a bytes object, it would create a whole
new object.

Objects/bytesobject.c

index efe6ef87b35a578b2549e923be7bc8678c2b1d7f..14bd8e68c56a236f0ffbad8287edfb68fef3fca7 100644 (file)
@@ -2577,6 +2577,12 @@ PyBytes_FromObject(PyObject *x)
         PyErr_BadInternalCall();
         return NULL;
     }
+
+    if (PyBytes_CheckExact(x)) {
+        Py_INCREF(x);
+        return x;
+    }
+
     /* Use the modern buffer interface */
     if (PyObject_CheckBuffer(x)) {
         Py_buffer view;