diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-01-22 11:33:12 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-01-22 11:33:12 (GMT) |
commit | 3cdd5fb970a7d6950b80cc156a9e345f87c179fc (patch) | |
tree | 9056965548ae6c59a250f105ce0b0f0e3a5f0f39 /Include/code.h | |
parent | d52513cb222174df834ea81e61037899248e312c (diff) | |
download | cpython-3cdd5fb970a7d6950b80cc156a9e345f87c179fc.zip cpython-3cdd5fb970a7d6950b80cc156a9e345f87c179fc.tar.gz cpython-3cdd5fb970a7d6950b80cc156a9e345f87c179fc.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/code.h')
-rw-r--r-- | Include/code.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Include/code.h b/Include/code.h index 56e6ec1..8ecf38a 100644 --- a/Include/code.h +++ b/Include/code.h @@ -108,12 +108,21 @@ typedef struct _addr_pair { int ap_upper; } PyAddrPair; +#ifndef Py_LIMITED_API /* Update *bounds to describe the first and one-past-the-last instructions in the same line as lasti. Return the number of that line. */ -#ifndef Py_LIMITED_API 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); #endif PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts, |