Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
facb60bdeff8888a7b344e38316785fae1a406c375aba6fb4204e2ecb67e8d685f6994ffd088a72b349dc25563ce1c247f0a8679ff96c0cefbd035d64f2174b99dcfc2ef7d2575fda9c36ee551aafe16ef88c4bc443efd5a2b6e7332d9f7f9e21cc13494b0d17236eef7c9b0baea52ed589a2e42f63950f73c90786c3647e2bdcecdeace0ff261392899c6560a725e88649755c5f6e34dad56e8c4a3af25be59f42d9247e61a720e2a25b9a1817c3b1781c95d9f2c676cad37af1f3d977ef464d65c30f1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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 resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| 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); | ||
| } | ||
| @@ -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 resolvedHide resolvedUh oh!There was an error while loading. Please reload this page.
skirpichev marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page.
skirpichev marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| 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 resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| /* 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 && | ||
| (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 resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| 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; | ||
| 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 resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| nbr = Py_TYPE(orig_r)->tp_as_number; | ||
| if (nbr == NULL || | ||
| (nbr->nb_float == NULL && nbr->nb_index == NULL)) | ||
Uh oh!
There was an error while loading. Please reload this page.