-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-109802: removed inaccessible code from complexobject.c #109642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
facb60b
gh-109802: Increase test coverage for complexobject.c
skirpichev deff888
* c_powu: L166
skirpichev 8a7b344
* complex_hash: L411, L414, L423
skirpichev e383167
* to_complex: L443, L449, L453-454
skirpichev 85fae1a
* complex_sub: L474, L475
skirpichev 406c375
* complex_mul: L485, L486
skirpichev aba6fb4
* complex_div: L496, L497
skirpichev 204e2ec
* complex_pow: L512, L513, L522
skirpichev b67e8d6
* complex_pos: L555-L559
skirpichev 85f6994
* complex_richcompare: L595, L616, L621, L625
skirpichev ffd088a
* complex_from_string_inner: L786, L804
skirpichev 72b349d
* complex_subtype_from_string: L860, L871-L874 (the function called i…
skirpichev c25563c
* complex_new_impl: L944, L951, L958, L965, L985, L994
skirpichev e1c247f
* complex_bool: L580
skirpichev 0a8679f
Merge branch 'main' into complex-cov
skirpichev f96c0ce
Merge branch 'main' into complex-cov
skirpichev fbd035d
Merge branch 'main' into complex-cov
skirpichev 64f2174
Apply suggestions from code review
skirpichev b99dcfc
Merge branch 'main' into complex-cov
skirpichev 2ef7d25
address review: self.assertAlmostEqual -> self.assertEqual (except one)
skirpichev 75fda9c
address review: spam support classes
skirpichev 36ee551
address review: comment on assert in complex_new_impl()
skirpichev aafe16e
address review: revert _Py_c_pow()
skirpichev f88c4bc
address review: hash test
skirpichev 443efd5
Merge branch 'complex-cov' of github.com:skirpichev/cpython into comp…
skirpichev a2b6e73
* _Py_c_pow: L135-136, also other tests for _Py_c_* C API
skirpichev 32d9f7f
+1
skirpichev 9e21cc1
address review:
skirpichev 3494b0d
address review: comment in complex_hash()
skirpichev 17236ee
address review: simplify _PY_C_FUNC2 macro
skirpichev f7c9b0b
Merge branch 'main' into complex-cov
skirpichev aea52ed
Drop pycore_complexobject.h
skirpichev 589a2e4
+ test _Py_c_abs()
skirpichev 2f63950
Oops, typo fixed
skirpichev f73c907
address review: check for failures in test code before PyTuple_Pack'ing
skirpichev 86c3647
address review: use _testcapi.DBL_MAX instead of magic numbers
skirpichev e2bdcec
Merge branch 'main' into complex-cov
skirpichev deace0f
Amend f73c90731f
skirpichev f261392
+ use Py_BuildValue
skirpichev 899c656
Merge branch 'main' into complex-cov
skirpichev 0a725e8
Merge branch 'main' into complex-cov
skirpichev 8649755
* complex_abs: L569
skirpichev c5f6e34
Merge branch 'main' into complex-cov
skirpichev dad56e8
Merge branch 'main' into complex-cov
skirpichev c4a3af2
Merge branch 'main' into complex-cov
skirpichev 5be59f4
Merge branch 'main' into complex-cov
skirpichev 2d9247e
Merge branch 'main' into complex-cov
skirpichev 61a720e
Merge branch 'main' into complex-cov
skirpichev 2a25b9a
Update wrt recent changes
skirpichev 1817c3b
Merge branch 'main' into complex-cov
skirpichev 1781c95
Merge branch 'main' into complex-cov
skirpichev d9f2c67
Apply suggestions from code review
skirpichev 6cad37a
Update Objects/complexobject.c
skirpichev f1f3d97
Apply suggestions from code review
skirpichev 7ef464d
Merge branch 'master' into complex-cov
skirpichev 65c30f1
Add test for complex_from_number
skirpichev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,14 +179,20 @@ _Py_c_pow(Py_complex a, Py_complex b) | |
return r; | ||
} | ||
|
||
/* Switch to exponentiation by squaring is integer exponent less that this. */ | ||
#define C_EXP_CUTOFF 100 | ||
skirpichev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static Py_complex | ||
c_powu(Py_complex x, long n) | ||
{ | ||
Py_complex r, p; | ||
long mask = 1; | ||
r = c_1; | ||
p = x; | ||
while (mask > 0 && n >= mask) { | ||
assert(0 <= n); | ||
assert(n <= C_EXP_CUTOFF); | ||
while (n >= mask) { | ||
assert(mask > 0); | ||
if (n & mask) | ||
r = _Py_c_prod(r,p); | ||
mask <<= 1; | ||
|
@@ -456,11 +462,11 @@ complex_hash(PyComplexObject *v) | |
{ | ||
Py_uhash_t hashreal, hashimag, combined; | ||
hashreal = (Py_uhash_t)_Py_HashDouble((PyObject *) v, v->cval.real); | ||
if (hashreal == (Py_uhash_t)-1) | ||
return -1; | ||
hashimag = (Py_uhash_t)_Py_HashDouble((PyObject *)v, v->cval.imag); | ||
if (hashimag == (Py_uhash_t)-1) | ||
return -1; | ||
/* In current implementation of hashing for numberic types, | ||
* -1 is reserved. */ | ||
assert(hashreal != (Py_uhash_t)-1); | ||
assert(hashimag != (Py_uhash_t)-1); | ||
/* Note: if the imaginary part is 0, hashimag is 0 now, | ||
* so the following returns hashreal unchanged. This is | ||
* important because numbers of different types that | ||
|
@@ -567,7 +573,7 @@ complex_pow(PyObject *v, PyObject *w, PyObject *z) | |
errno = 0; | ||
// Check whether the exponent has a small integer value, and if so use | ||
// a faster and more accurate algorithm. | ||
if (b.imag == 0.0 && b.real == floor(b.real) && fabs(b.real) <= 100.0) { | ||
if (b.imag == 0.0 && b.real == floor(b.real) && fabs(b.real) <= C_EXP_CUTOFF) { | ||
p = c_powi(a, (long)b.real); | ||
_Py_ADJUST_ERANGE2(p.real, p.imag); | ||
} | ||
10000
|
@@ -640,7 +646,7 @@ complex_richcompare(PyObject *v, PyObject *w, int op) | |
} | ||
|
||
assert(PyComplex_Check(v)); | ||
TO_COMPLEX(v, i); | ||
i = ((PyComplexObject *)v)->cval; | ||
|
||
if (PyLong_Check(w)) { | ||
/* Check for 0.0 imaginary part first to avoid the rich | ||
|
@@ -666,7 +672,7 @@ complex_richcompare(PyObject *v, PyObject *w, int op) | |
else if (PyComplex_Check(w)) { | ||
Py_complex j; | ||
|
||
TO_COMPLEX(w, j); | ||
j = ((PyComplexObject *)w)->cval; | ||
equal = (i.real == j.real && i.imag == j.imag); | ||
} | ||
else { | ||
|
@@ -889,22 +895,15 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v) | |
PyObject *s_buffer = NULL, *result = NULL; | ||
Py_ssize_t len; | ||
|
||
if (PyUnicode_Check(v)) { | ||
s_buffer = _PyUnicode_TransformDecimalAndSpaceToASCII(v); | ||
if (s_buffer == NULL) { | ||
return NULL; | ||
} | ||
assert(PyUnicode_IS_ASCII(s_buffer)); | ||
/* Simply get a pointer to existing ASCII characters. */ | ||
s = PyUnicode_AsUTF8AndSize(s_buffer, &len); | ||
assert(s != NULL); | ||
} | ||
else { | ||
PyErr_Format(PyExc_TypeError, | ||
"complex() argument must be a string or a number, not %T", | ||
v); | ||
assert(PyUnicode_Check(v)); | ||
skirpichev marked this conversation as resolved.
Show resolved
Hide resolved
skirpichev marked this conversation as resolved.
Show resolved
Hide resolved
skirpichev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
s_buffer = _PyUnicode_TransformDecimalAndSpaceToASCII(v); | ||
if (s_buffer == NULL) { | ||
return NULL; | ||
} | ||
assert(PyUnicode_IS_ASCII(s_buffer)); | ||
/* Simply get a pointer to existing ASCII characters. */ | ||
s = PyUnicode_AsUTF8AndSize(s_buffer, &len); | ||
assert(s != NULL); | ||
|
||
result = _Py_string_to_number_with_underscores(s, len, "complex", v, type, | ||
complex_from_string_inner); | ||
|
@@ -957,13 +956,6 @@ actual_complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) | |
else if (PyErr_Occurred()) { | ||
return NULL; | ||
} | ||
else if (PyComplex_Check(arg)) { | ||
skirpichev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/* Note that if arg is of a complex subtype, we're only | ||
retaining its real & imag parts here, and the return | ||
value is (properly) of the builtin complex type. */ | ||
Py_complex c = ((PyComplexObject*)arg)->cval; | ||
res = complex_subtype_from_doubles(type, c.real, c.imag); | ||
} | ||
else if ((nbr = Py_TYPE(arg)->tp_as_number) != NULL && | ||
57AE (nbr->nb_float != NULL || nbr->nb_index != NULL)) | ||
{ | ||
|
@@ -1031,9 +1023,9 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) | |
PyErr_Format(PyExc_TypeError, | ||
"complex() argument 'real' must be a real number, not %T", | ||
r); | ||
if (own_r) { | ||
Py_DECREF(r); | ||
} | ||
/* Here r is not a complex subtype, hence above | ||
try_complex_special_method() call was unsuccessful. */ | ||
assert(!own_r); | ||
skirpichev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return NULL; | ||
} | ||
if (i != NULL) { | ||
|
@@ -1065,11 +1057,10 @@ complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i) | |
value is (properly) of the builtin complex type. */ | ||
cr = ((PyComplexObject*)r)->cval; | ||
7917 cr_is_complex = 1; | ||
if (own_r) { | ||
/* r was a newly created complex number, rather | ||
than the original "real" argument. */ | ||
Py_DECREF(r); | ||
} | ||
assert(own_r); | ||
/* r was a newly created complex number, rather | ||
than the original "real" argument. */ | ||
Py_DECREF(r); | ||
skirpichev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
nbr = Py_TYPE(orig_r)->tp_as_number; | ||
if (nbr == NULL || | ||
(nbr->nb_float == NULL && nbr->nb_index == NULL)) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.