Skip to content

Commit 4cecaba

Browse files
committed
Merge remote-tracking branch 'upstream/main' into fix-sizeof-for-int-subtypes
2 parents 9cd5d01 + c1b1f51 commit 4cecaba

27 files changed

+463
-385
lines changed

Doc/library/cmath.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Power and logarithmic functions
8989
logarithms.
9090

9191

92-
.. function:: log(x[, base])
92+
.. function:: log(x, base=None)
9393

9494
Returns the logarithm of *x* to the given *base*. If the *base* is not
9595
specified, returns the natural logarithm of *x*. There is one branch cut, from 0

Doc/library/math.rst

+4-5
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,12 @@ Power and logarithmic functions
393393
.. versionadded:: 3.2
394394

395395

396-
.. function:: log(x[, base])
396+
.. function:: log(x, base=None)
397397

398-
With one argument, return the natural logarithm of *x* (to base *e*).
399-
400-
With two arguments, return the logarithm of *x* to the given *base*,
401-
calculated as ``log(x)/log(base)``.
398+
Return the logarithm of *x* to the given *base*.
402399

400+
If the *base* is not specified, returns the natural
401+
logarithm (base *e*) of *x*.
403402

404403
.. function:: log1p(x)
405404

Doc/using/windows.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ is printed. Now try changing the first line to be:
797797
Re-executing the command should now print the latest Python 3.x information.
798798
As with the above command-line examples, you can specify a more explicit
799799
version qualifier. Assuming you have Python 3.7 installed, try changing
800-
the first line to ``#! python3.7`` and you should find the |version|
800+
the first line to ``#! python3.7`` and you should find the 3.7
801801
version information printed.
802802

803803
Note that unlike interactive use, a bare "python" will use the latest

Include/cpython/longintrepr.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,14 @@ typedef long stwodigits; /* signed variant of twodigits */
7979
aware that ints abuse ob_size's sign bit.
8080
*/
8181

82-
struct _longobject {
83-
PyObject_VAR_HEAD
82+
typedef struct _PyLongValue {
83+
Py_ssize_t ob_size; /* Number of items in variable part */
8484
digit ob_digit[1];
85+
} _PyLongValue;
86+
87+
struct _longobject {
88+
PyObject_HEAD
89+
_PyLongValue long_value;
8590
};
8691

8792
PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);

Include/internal/pycore_runtime_init.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ extern "C" {
149149

150150
#define _PyLong_DIGIT_INIT(val) \
151151
{ \
152-
_PyVarObject_IMMORTAL_INIT(&PyLong_Type, \
153-
((val) == 0 ? 0 : ((val) > 0 ? 1 : -1))), \
154-
.ob_digit = { ((val) >= 0 ? (val) : -(val)) }, \
152+
.ob_base = _PyObject_IMMORTAL_INIT(&PyLong_Type), \
153+
.long_value = { \
154+
((val) == 0 ? 0 : ((val) > 0 ? 1 : -1)), \
155+
{ ((val) >= 0 ? (val) : -(val)) }, \
156+
} \
155157
}
156158

157159
#define _PyBytes_SIMPLE_INIT(CH, LEN) \

Lib/test/test_math.py

+1
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ def testLog(self):
11461146
self.ftest('log(1/e)', math.log(1/math.e), -1)
11471147
self.ftest('log(1)', math.log(1), 0)
11481148
self.ftest('log(e)', math.log(math.e), 1)
1149+
self.ftest('log(e, None)', math.log(math.e, None), 1)
11491150
self.ftest('log(32,2)', math.log(32,2), 5)
11501151
self.ftest('log(10**40, 10)', math.log(10**40, 10), 40)
11511152
self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Refactor the ``PyLongObject`` struct into a normal Python object header and
2+
a ``PyLongValue`` struct.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:func:`~math.log` and :func:`~cmath.log` support default base=None values.

Modules/_decimal/_decimal.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2171,16 +2171,16 @@ dec_from_long(PyTypeObject *type, PyObject *v,
21712171
}
21722172

21732173
if (len == 1) {
2174-
_dec_settriple(dec, sign, *l->ob_digit, 0);
2174+
_dec_settriple(dec, sign, *l->long_value.ob_digit, 0);
21752175
mpd_qfinalize(MPD(dec), ctx, status);
21762176
return dec;
21772177
}
21782178

21792179
#if PYLONG_BITS_IN_DIGIT == 30
2180-
mpd_qimport_u32(MPD(dec), l->ob_digit, len, sign, PyLong_BASE,
2180+
mpd_qimport_u32(MPD(dec), l->long_value.ob_digit, len, sign, PyLong_BASE,
21812181
ctx, status);
21822182
#elif PYLONG_BITS_IN_DIGIT == 15
2183-
mpd_qimport_u16(MPD(dec), l->ob_digit, len, sign, PyLong_BASE,
2183+
mpd_qimport_u16(MPD(dec), l->long_value.ob_digit, len, sign, PyLong_BASE,
21842184
ctx, status);
21852185
#else
21862186
#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"
@@ -3543,11 +3543,11 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
35433543
return NULL;
35443544
}
35453545

3546-
memcpy(pylong->ob_digit, ob_digit, n * sizeof(digit));
3546+
memcpy(pylong->long_value.ob_digit, ob_digit, n * sizeof(digit));
35473547
mpd_free(ob_digit);
35483548

35493549
i = n;
3550-
while ((i > 0) && (pylong->ob_digit[i-1] == 0)) {
3550+
while ((i > 0) && (pylong->long_value.ob_digit[i-1] == 0)) {
35513551
i--;
35523552
}
35533553

Modules/clinic/cmathmodule.c.h

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/mathmodule.c.h

+19-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/cmathmodule.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -952,23 +952,24 @@ cmath_tanh_impl(PyObject *module, Py_complex z)
952952
cmath.log
953953
954954
z as x: Py_complex
955-
base as y_obj: object = NULL
955+
base as y_obj: object = None
956956
/
957957
958958
log(z[, base]) -> the logarithm of z to the given base.
959959
960-
If the base not specified, returns the natural logarithm (base e) of z.
960+
If the base is not specified or is None, returns the
961+
natural logarithm (base e) of z.
961962
[clinic start generated code]*/
962963

963964
static PyObject *
964965
cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj)
965-
/*[clinic end generated code: output=4effdb7d258e0d94 input=230ed3a71ecd000a]*/
966+
/*[clinic end generated code: output=4effdb7d258e0d94 input=e7db51859ebf70bf]*/
966967
{
967968
Py_complex y;
968969

969970
errno = 0;
970971
x = c_log(x);
971-
if (y_obj != NULL) {
972+
if (y_obj != Py_None) {
972973
y = PyComplex_AsCComplex(y_obj);
973974
if (PyErr_Occurred()) {
974975
return NULL;

Modules/mathmodule.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -2366,26 +2366,24 @@ loghelper(PyObject* arg, double (*func)(double))
23662366
math.log
23672367
23682368
x: object
2369-
[
2370-
base: object(c_default="NULL") = math.e
2371-
]
2369+
base: object = None
23722370
/
23732371
23742372
Return the logarithm of x to the given base.
23752373
2376-
If the base not specified, returns the natural logarithm (base e) of x.
2374+
If the base is not specified or is None, returns the natural
2375+
logarithm (base e) of x.
23772376
[clinic start generated code]*/
23782377

23792378
static PyObject *
2380-
math_log_impl(PyObject *module, PyObject *x, int group_right_1,
2381-
PyObject *base)
2382-
/*[clinic end generated code: output=7b5a39e526b73fc9 input=0f62d5726cbfebbd]*/
2379+
math_log_impl(PyObject *module, PyObject *x, PyObject *base)
2380+
/*[clinic end generated code: output=1dead263cbb1e854 input=ef032cc9837943e1]*/
23832381
{
23842382
PyObject *num, *den;
23852383
PyObject *ans;
23862384

23872385
num = loghelper(x, m_log);
2388-
if (num == NULL || base == NULL)
2386+
if (num == NULL || base == Py_None)
23892387
return num;
23902388

23912389
den = loghelper(base, m_log);

Objects/boolobject.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ PyTypeObject PyBool_Type = {
197197
/* The objects representing bool values False and True */
198198

199199
struct _longobject _Py_FalseStruct = {
200-
PyVarObject_HEAD_INIT(&PyBool_Type, 0)
201-
{ 0 }
200+
PyObject_HEAD_INIT(&PyBool_Type)
201+
{ 0, { 0 } }
202202
};
203203

204204
struct _longobject _Py_TrueStruct = {
205-
PyVarObject_HEAD_INIT(&PyBool_Type, 1)
206-
{ 1 }
205+
PyObject_HEAD_INIT(&PyBool_Type)
206+
{ 1, { 1 } }
207207
};

Objects/listobject.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2155,8 +2155,8 @@ unsafe_long_compare(PyObject *v, PyObject *w, MergeState *ms)
21552155
vl = (PyLongObject*)v;
21562156
wl = (PyLongObject*)w;
21572157

2158-
v0 = Py_SIZE(vl) == 0 ? 0 : (sdigit)vl->ob_digit[0];
2159-
w0 = Py_SIZE(wl) == 0 ? 0 : (sdigit)wl->ob_digit[0];
2158+
v0 = Py_SIZE(vl) == 0 ? 0 : (sdigit)vl->long_value.ob_digit[0];
2159+
w0 = Py_SIZE(wl) == 0 ? 0 : (sdigit)wl->long_value.ob_digit[0];
21602160

21612161
if (Py_SIZE(vl) < 0)
21622162
v0 = -v0;

0 commit comments

Comments
 (0)