Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
43ca377e
Kaydet (Commit)
43ca377e
authored
May 09, 2010
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Wrap multiline macros in a 'do {} while(0)', for safety.
üst
fda8d114
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
37 deletions
+43
-37
longobject.c
Objects/longobject.c
+43
-37
No files found.
Objects/longobject.c
Dosyayı görüntüle @
43ca377e
...
@@ -31,11 +31,13 @@
...
@@ -31,11 +31,13 @@
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define SIGCHECK(PyTryBlock) \
#define SIGCHECK(PyTryBlock) \
if (--_Py_Ticker < 0) { \
do { \
_Py_Ticker = _Py_CheckInterval; \
if (--_Py_Ticker < 0) { \
if (PyErr_CheckSignals()) PyTryBlock \
_Py_Ticker = _Py_CheckInterval; \
}
if (PyErr_CheckSignals()) PyTryBlock \
} \
} while(0)
/* Normalize (remove leading zeros from) a long int object.
/* Normalize (remove leading zeros from) a long int object.
Doesn't attempt to free the storage--in most cases, due to the nature
Doesn't attempt to free the storage--in most cases, due to the nature
...
@@ -1151,11 +1153,13 @@ convert_binop(PyObject *v, PyObject *w, PyLongObject **a, PyLongObject **b) {
...
@@ -1151,11 +1153,13 @@ convert_binop(PyObject *v, PyObject *w, PyLongObject **a, PyLongObject **b) {
return
1
;
return
1
;
}
}
#define CONVERT_BINOP(v, w, a, b) \
#define CONVERT_BINOP(v, w, a, b) \
if (!convert_binop(v, w, a, b)) { \
do { \
Py_INCREF(Py_NotImplemented); \
if (!convert_binop(v, w, a, b)) { \
return Py_NotImplemented; \
Py_INCREF(Py_NotImplemented); \
}
return Py_NotImplemented; \
} \
} while(0) \
/* bits_in_digit(d) returns the unique integer k such that 2**(k-1) <= d <
/* bits_in_digit(d) returns the unique integer k such that 2**(k-1) <= d <
2**k if d is nonzero, else 0. */
2**k if d is nonzero, else 0. */
...
@@ -1371,7 +1375,7 @@ long_to_decimal_string(PyObject *aa, int addL)
...
@@ -1371,7 +1375,7 @@ long_to_decimal_string(PyObject *aa, int addL)
SIGCHECK
({
SIGCHECK
({
Py_DECREF
(
scratch
);
Py_DECREF
(
scratch
);
return
NULL
;
return
NULL
;
})
})
;
}
}
/* pout should have at least one digit, so that the case when a = 0
/* pout should have at least one digit, so that the case when a = 0
works correctly */
works correctly */
...
@@ -1540,7 +1544,7 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
...
@@ -1540,7 +1544,7 @@ _PyLong_Format(PyObject *aa, int base, int addL, int newstyle)
Py_DECREF
(
scratch
);
Py_DECREF
(
scratch
);
Py_DECREF
(
str
);
Py_DECREF
(
str
);
return
NULL
;
return
NULL
;
})
})
;
/* Break rem into digits. */
/* Break rem into digits. */
assert
(
ntostore
>
0
);
assert
(
ntostore
>
0
);
...
@@ -2121,7 +2125,7 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
...
@@ -2121,7 +2125,7 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
Py_DECREF
(
v
);
Py_DECREF
(
v
);
*
prem
=
NULL
;
*
prem
=
NULL
;
return
NULL
;
return
NULL
;
})
})
;
/* estimate quotient digit q; may overestimate by 1 (rare) */
/* estimate quotient digit q; may overestimate by 1 (rare) */
vtop
=
vk
[
size_w
];
vtop
=
vk
[
size_w
];
...
@@ -2578,7 +2582,7 @@ x_mul(PyLongObject *a, PyLongObject *b)
...
@@ -2578,7 +2582,7 @@ x_mul(PyLongObject *a, PyLongObject *b)
SIGCHECK
({
SIGCHECK
({
Py_DECREF
(
z
);
Py_DECREF
(
z
);
return
NULL
;
return
NULL
;
})
})
;
carry
=
*
pz
+
f
*
f
;
carry
=
*
pz
+
f
*
f
;
*
pz
++
=
(
digit
)(
carry
&
PyLong_MASK
);
*
pz
++
=
(
digit
)(
carry
&
PyLong_MASK
);
...
@@ -2616,7 +2620,7 @@ x_mul(PyLongObject *a, PyLongObject *b)
...
@@ -2616,7 +2620,7 @@ x_mul(PyLongObject *a, PyLongObject *b)
SIGCHECK
({
SIGCHECK
({
Py_DECREF
(
z
);
Py_DECREF
(
z
);
return
NULL
;
return
NULL
;
})
})
;
while
(
pb
<
pbend
)
{
while
(
pb
<
pbend
)
{
carry
+=
*
pz
+
*
pb
++
*
f
;
carry
+=
*
pz
+
*
pb
++
*
f
;
...
@@ -3475,26 +3479,28 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
...
@@ -3475,26 +3479,28 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
* is NULL.
* is NULL.
*/
*/
#define REDUCE(X) \
#define REDUCE(X) \
if (c != NULL) { \
do { \
if (l_divmod(X, c, NULL, &temp) < 0) \
if (c != NULL) { \
goto Error; \
if (l_divmod(X, c, NULL, &temp) < 0) \
Py_XDECREF(X); \
goto Error; \
X = temp; \
Py_XDECREF(X); \
temp = NULL; \
X = temp; \
}
temp = NULL; \
} \
} while(0)
/* Multiply two values, then reduce the result:
/* Multiply two values, then reduce the result:
result = X*Y % c. If c is NULL, skip the mod. */
result = X*Y % c. If c is NULL, skip the mod. */
#define MULT(X, Y, result)
\
#define MULT(X, Y, result) \
{
\
do {
\
temp = (PyLongObject *)long_mul(X, Y);
\
temp = (PyLongObject *)long_mul(X, Y);
\
if (temp == NULL)
\
if (temp == NULL)
\
goto Error;
\
goto Error;
\
Py_XDECREF(result);
\
Py_XDECREF(result);
\
result = temp;
\
result = temp;
\
temp = NULL;
\
temp = NULL;
\
REDUCE(result)
\
REDUCE(result);
\
}
} while(0)
if
(
Py_SIZE
(
b
)
<=
FIVEARY_CUTOFF
)
{
if
(
Py_SIZE
(
b
)
<=
FIVEARY_CUTOFF
)
{
/* Left-to-right binary exponentiation (HAC Algorithm 14.79) */
/* Left-to-right binary exponentiation (HAC Algorithm 14.79) */
...
@@ -3503,9 +3509,9 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
...
@@ -3503,9 +3509,9 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
digit
bi
=
b
->
ob_digit
[
i
];
digit
bi
=
b
->
ob_digit
[
i
];
for
(
j
=
(
digit
)
1
<<
(
PyLong_SHIFT
-
1
);
j
!=
0
;
j
>>=
1
)
{
for
(
j
=
(
digit
)
1
<<
(
PyLong_SHIFT
-
1
);
j
!=
0
;
j
>>=
1
)
{
MULT
(
z
,
z
,
z
)
MULT
(
z
,
z
,
z
)
;
if
(
bi
&
j
)
if
(
bi
&
j
)
MULT
(
z
,
a
,
z
)
MULT
(
z
,
a
,
z
)
;
}
}
}
}
}
}
...
@@ -3514,7 +3520,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
...
@@ -3514,7 +3520,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
Py_INCREF
(
z
);
/* still holds 1L */
Py_INCREF
(
z
);
/* still holds 1L */
table
[
0
]
=
z
;
table
[
0
]
=
z
;
for
(
i
=
1
;
i
<
32
;
++
i
)
for
(
i
=
1
;
i
<
32
;
++
i
)
MULT
(
table
[
i
-
1
],
a
,
table
[
i
])
MULT
(
table
[
i
-
1
],
a
,
table
[
i
])
;
for
(
i
=
Py_SIZE
(
b
)
-
1
;
i
>=
0
;
--
i
)
{
for
(
i
=
Py_SIZE
(
b
)
-
1
;
i
>=
0
;
--
i
)
{
const
digit
bi
=
b
->
ob_digit
[
i
];
const
digit
bi
=
b
->
ob_digit
[
i
];
...
@@ -3522,9 +3528,9 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
...
@@ -3522,9 +3528,9 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
for
(
j
=
PyLong_SHIFT
-
5
;
j
>=
0
;
j
-=
5
)
{
for
(
j
=
PyLong_SHIFT
-
5
;
j
>=
0
;
j
-=
5
)
{
const
int
index
=
(
bi
>>
j
)
&
0x1f
;
const
int
index
=
(
bi
>>
j
)
&
0x1f
;
for
(
k
=
0
;
k
<
5
;
++
k
)
for
(
k
=
0
;
k
<
5
;
++
k
)
MULT
(
z
,
z
,
z
)
MULT
(
z
,
z
,
z
)
;
if
(
index
)
if
(
index
)
MULT
(
z
,
table
[
index
],
z
)
MULT
(
z
,
table
[
index
],
z
)
;
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment