summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-01-22 11:33:12 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-01-22 11:33:12 (GMT)
commit7791165fb36ecca2398ac81e9b6bc0248821262c (patch)
tree609b25184362f073bee1a4a5d3730add36b5c401 /Include
parent5640bbb6c5c0c9232fd761ef4544687f9123e43e (diff)
downloadcpython-7791165fb36ecca2398ac81e9b6bc0248821262c.zip
cpython-7791165fb36ecca2398ac81e9b6bc0248821262c.tar.gz
cpython-7791165fb36ecca2398ac81e9b6bc0248821262c.tar.bz2
code_richcompare() now uses the constants types
Issue #25843: When compiling code, don't merge constants if they are equal but have a different types. For example, "f1, f2 = lambda: 1, lambda: 1.0" is now correctly compiled to two different functions: f1() returns 1 (int) and f2() returns 1.0 (int), even if 1 and 1.0 are equal. Add a new _PyCode_ConstantKey() private function.
Diffstat (limited to 'Include')
-rw-r--r--Include/code.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/Include/code.h b/Include/code.h
index 38b2958..7456fd6 100644
--- a/Include/code.h
+++ b/Include/code.h
@@ -70,7 +70,7 @@ PyAPI_DATA(PyTypeObject) PyCode_Type;
/* Public interface */
PyAPI_FUNC(PyCodeObject *) PyCode_New(
int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *,
- PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *);
+ PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *);
/* same as struct above */
/* Creates a new empty code object with the specified source location. */
@@ -98,6 +98,15 @@ typedef struct _addr_pair {
PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co,
int lasti, PyAddrPair *bounds);
+/* Create a comparable key used to compare constants taking in account the
+ * object type. It is used to make sure types are not coerced (e.g., float and
+ * complex) _and_ to distinguish 0.0 from -0.0 e.g. on IEEE platforms
+ *
+ * Return (type(obj), obj, ...): a tuple with variable size (at least 2 items)
+ * depending on the type and the value. The type is the first item to not
+ * compare bytes and str which can raise a BytesWarning exception. */
+PyAPI_FUNC(PyObject*) _PyCode_ConstantKey(PyObject *obj);
+
PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
PyObject *names, PyObject *lineno_obj);