Skip to content

Commit

Permalink
more PY_LONG_LONG to long long
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminp committed Sep 8, 2016
1 parent c71ec8a commit 47ff073
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 281 deletions.
23 changes: 8 additions & 15 deletions Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,12 @@ Numbers
Convert a Python integer to a C :c:type:`unsigned long` without
overflow checking.

``L`` (:class:`int`) [PY_LONG_LONG]
Convert a Python integer to a C :c:type:`long long`. This format is only
available on platforms that support :c:type:`long long` (or :c:type:`_int64` on
Windows).
``L`` (:class:`int`) [long long]
Convert a Python integer to a C :c:type:`long long`.

``K`` (:class:`int`) [unsigned PY_LONG_LONG]
``K`` (:class:`int`) [unsigned long long]
Convert a Python integer to a C :c:type:`unsigned long long`
without overflow checking. This format is only available on platforms that
support :c:type:`unsigned long long` (or :c:type:`unsigned _int64` on Windows).
without overflow checking.

``n`` (:class:`int`) [Py_ssize_t]
Convert a Python integer to a C :c:type:`Py_ssize_t`.
Expand Down Expand Up @@ -594,15 +591,11 @@ Building values
``k`` (:class:`int`) [unsigned long]
Convert a C :c:type:`unsigned long` to a Python integer object.
``L`` (:class:`int`) [PY_LONG_LONG]
Convert a C :c:type:`long long` to a Python integer object. Only available
on platforms that support :c:type:`long long` (or :c:type:`_int64` on
Windows).
``L`` (:class:`int`) [long long]
Convert a C :c:type:`long long` to a Python integer object.
``K`` (:class:`int`) [unsigned PY_LONG_LONG]
Convert a C :c:type:`unsigned long long` to a Python integer object. Only
available on platforms that support :c:type:`unsigned long long` (or
:c:type:`unsigned _int64` on Windows).
``K`` (:class:`int`) [unsigned long long]
Convert a C :c:type:`unsigned long long` to a Python integer object.
``n`` (:class:`int`) [Py_ssize_t]
Convert a C :c:type:`Py_ssize_t` to a Python integer.
Expand Down
18 changes: 9 additions & 9 deletions Doc/c-api/long.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ All integers are implemented as "long" integer objects of arbitrary size.
*NULL* on failure.
.. c:function:: PyObject* PyLong_FromLongLong(PY_LONG_LONG v)
.. c:function:: PyObject* PyLong_FromLongLong(long long v)
Return a new :c:type:`PyLongObject` object from a C :c:type:`long long`, or *NULL*
on failure.
.. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG v)
.. c:function:: PyObject* PyLong_FromUnsignedLongLong(unsigned long long v)
Return a new :c:type:`PyLongObject` object from a C :c:type:`unsigned long long`,
or *NULL* on failure.
Expand Down Expand Up @@ -148,7 +148,7 @@ All integers are implemented as "long" integer objects of arbitrary size.
occurs set *\*overflow* to ``0`` and return ``-1`` as usual.
.. c:function:: PY_LONG_LONG PyLong_AsLongLong(PyObject *obj)
.. c:function:: long long PyLong_AsLongLong(PyObject *obj)
.. index::
single: OverflowError (built-in exception)
Expand All @@ -161,7 +161,7 @@ All integers are implemented as "long" integer objects of arbitrary size.
:c:type:`long`.
.. c:function:: PY_LONG_LONG PyLong_AsLongLongAndOverflow(PyObject *obj, int *overflow)
.. c:function:: long long PyLong_AsLongLongAndOverflow(PyObject *obj, int *overflow)
Return a C :c:type:`long long` representation of *obj*. If *obj* is not an
instance of :c:type:`PyLongObject`, first call its :meth:`__int__` method
Expand Down Expand Up @@ -210,16 +210,16 @@ All integers are implemented as "long" integer objects of arbitrary size.
:c:type:`size_t`.
.. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(PyObject *pylong)
.. c:function:: unsigned long long PyLong_AsUnsignedLongLong(PyObject *pylong)
.. index::
single: OverflowError (built-in exception)
Return a C :c:type:`unsigned PY_LONG_LONG` representation of *pylong*.
*pylong* must be an instance of :c:type:`PyLongObject`.
Return a C :c:type:`unsigned long long` representation of *pylong*. *pylong*
must be an instance of :c:type:`PyLongObject`.
Raise :exc:`OverflowError` if the value of *pylong* is out of range for an
:c:type:`unsigned PY_LONG_LONG`.
:c:type:`unsigned long long`.
.. versionchanged:: 3.1
A negative *pylong* now raises :exc:`OverflowError`, not :exc:`TypeError`.
Expand All @@ -235,7 +235,7 @@ All integers are implemented as "long" integer objects of arbitrary size.
return the reduction of that value modulo :const:`ULONG_MAX + 1`.
.. c:function:: unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(PyObject *obj)
.. c:function:: unsigned long long PyLong_AsUnsignedLongLongMask(PyObject *obj)
Return a C :c:type:`unsigned long long` representation of *obj*. If *obj*
is not an instance of :c:type:`PyLongObject`, first call its :meth:`__int__`
Expand Down
1 change: 0 additions & 1 deletion Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ APIs:
.. % because not all compilers support the %z width modifier -- we fake it
.. % when necessary via interpolating PY_FORMAT_SIZE_T.
.. % Similar comments apply to the %ll width modifier and
.. % PY_FORMAT_LONG_LONG.
.. tabularcolumns:: |l|l|L|
Expand Down
30 changes: 0 additions & 30 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,10 @@ Used in: Py_SAFE_DOWNCAST

#ifndef PY_LONG_LONG
#define PY_LONG_LONG long long
#if defined(LLONG_MAX)
/* If LLONG_MAX is defined in limits.h, use that. */
#define PY_LLONG_MIN LLONG_MIN
#define PY_LLONG_MAX LLONG_MAX
#define PY_ULLONG_MAX ULLONG_MAX
#elif defined(__LONG_LONG_MAX__)
/* Otherwise, if GCC has a builtin define, use that. (Definition of
* PY_LLONG_MIN assumes two's complement with no trap representation.) */
#define PY_LLONG_MAX __LONG_LONG_MAX__
#define PY_LLONG_MIN (-PY_LLONG_MAX - 1)
#define PY_ULLONG_MAX (PY_LLONG_MAX * Py_ULL(2) + 1)
#elif defined(SIZEOF_LONG_LONG)
/* Otherwise compute from SIZEOF_LONG_LONG, assuming two's complement, no
padding bits, and no trap representation. Note: PY_ULLONG_MAX was
previously #defined as (~0ULL) here; but that'll give the wrong value in a
preprocessor expression on systems where long long != intmax_t. */
#define PY_LLONG_MAX \
(1 + 2 * ((Py_LL(1) << (CHAR_BIT * SIZEOF_LONG_LONG - 2)) - 1))
#define PY_LLONG_MIN (-PY_LLONG_MAX - 1)
#define PY_ULLONG_MAX (PY_LLONG_MAX * Py_ULL(2) + 1)
#endif /* LLONG_MAX */
#endif

#define PY_UINT32_T uint32_t
Expand Down Expand Up @@ -159,19 +142,6 @@ typedef int Py_ssize_clean_t;
# endif
#endif

/* PY_FORMAT_LONG_LONG is analogous to PY_FORMAT_SIZE_T above, but for
* the long long type instead of the size_t type. The "high level" Python format
* functions listed above will interpret "lld" or "llu" correctly on
* all platforms.
*/
#ifndef PY_FORMAT_LONG_LONG
# ifdef MS_WINDOWS
# define PY_FORMAT_LONG_LONG "I64"
# else
# error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"
# endif
#endif

/* Py_LOCAL can be used instead of static to get the fastest possible calling
* convention for functions that are local to a given module.
*
Expand Down
5 changes: 0 additions & 5 deletions Lib/test/test_getargs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
# Skip this test if the _testcapi module isn't available.
support.import_module('_testcapi')
from _testcapi import getargs_keywords, getargs_keyword_only
try:
from _testcapi import getargs_L, getargs_K
except ImportError:
getargs_L = None # PY_LONG_LONG not available

# > How about the following counterproposal. This also changes some of
# > the other format codes to be a little more regular.
Expand Down Expand Up @@ -309,7 +305,6 @@ def test_n(self):
self.assertRaises(OverflowError, getargs_n, VERY_LARGE)


@unittest.skipIf(getargs_L is None, 'PY_LONG_LONG is not available')
class LongLong_TestCase(unittest.TestCase):
def test_L(self):
from _testcapi import getargs_L
Expand Down
4 changes: 2 additions & 2 deletions Modules/_blake2/blake2b_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
Py_buffer buf;

unsigned long leaf_size = 0;
unsigned PY_LONG_LONG node_offset = 0;
unsigned long long node_offset = 0;

self = new_BLAKE2bObject(type);
if (self == NULL) {
Expand Down Expand Up @@ -170,7 +170,7 @@ py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size,

if (node_offset_obj != NULL) {
node_offset = PyLong_AsUnsignedLongLong(node_offset_obj);
if (node_offset == (unsigned PY_LONG_LONG) -1 && PyErr_Occurred()) {
if (node_offset == (unsigned long long) -1 && PyErr_Occurred()) {
goto error;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/_blake2/blake2s_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
Py_buffer buf;

unsigned long leaf_size = 0;
unsigned PY_LONG_LONG node_offset = 0;
unsigned long long node_offset = 0;

self = new_BLAKE2sObject(type);
if (self == NULL) {
Expand Down Expand Up @@ -170,7 +170,7 @@ py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size,

if (node_offset_obj != NULL) {
node_offset = PyLong_AsUnsignedLongLong(node_offset_obj);
if (node_offset == (unsigned PY_LONG_LONG) -1 && PyErr_Occurred()) {
if (node_offset == (unsigned long long) -1 && PyErr_Occurred()) {
goto error;
}
}
Expand Down
40 changes: 20 additions & 20 deletions Modules/_ctypes/_ctypes_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ EXPORT(int) _testfunc_callback_with_pointer(int (*func)(int *))
return (*func)(table);
}

EXPORT(PY_LONG_LONG) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f,
double d, PY_LONG_LONG q)
EXPORT(long long) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f,
double d, long long q)
{
return (PY_LONG_LONG)(b + h + i + l + f + d + q);
return (long long)(b + h + i + l + f + d + q);
}

EXPORT(PY_LONG_LONG) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d)
EXPORT(long long) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d)
{
return (PY_LONG_LONG)(b + h + i + l + f + d);
return (long long)(b + h + i + l + f + d);
}

EXPORT(int) _testfunc_callback_i_if(int value, int (*func)(int))
Expand All @@ -254,10 +254,10 @@ EXPORT(int) _testfunc_callback_i_if(int value, int (*func)(int))
return sum;
}

EXPORT(PY_LONG_LONG) _testfunc_callback_q_qf(PY_LONG_LONG value,
PY_LONG_LONG (*func)(PY_LONG_LONG))
EXPORT(long long) _testfunc_callback_q_qf(long long value,
long long (*func)(long long))
{
PY_LONG_LONG sum = 0;
long long sum = 0;

while (value != 0) {
sum += func(value);
Expand Down Expand Up @@ -381,8 +381,8 @@ EXPORT(void) _py_func(void)
{
}

EXPORT(PY_LONG_LONG) last_tf_arg_s;
EXPORT(unsigned PY_LONG_LONG) last_tf_arg_u;
EXPORT(long long) last_tf_arg_s;
EXPORT(unsigned long long) last_tf_arg_u;

struct BITS {
int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9;
Expand Down Expand Up @@ -445,8 +445,8 @@ static PyMethodDef module_methods[] = {
{ NULL, NULL, 0, NULL},
};

#define S last_tf_arg_s = (PY_LONG_LONG)c
#define U last_tf_arg_u = (unsigned PY_LONG_LONG)c
#define S last_tf_arg_s = (long long)c
#define U last_tf_arg_u = (unsigned long long)c

EXPORT(signed char) tf_b(signed char c) { S; return c/3; }
EXPORT(unsigned char) tf_B(unsigned char c) { U; return c/3; }
Expand All @@ -456,8 +456,8 @@ EXPORT(int) tf_i(int c) { S; return c/3; }
EXPORT(unsigned int) tf_I(unsigned int c) { U; return c/3; }
EXPORT(long) tf_l(long c) { S; return c/3; }
EXPORT(unsigned long) tf_L(unsigned long c) { U; return c/3; }
EXPORT(PY_LONG_LONG) tf_q(PY_LONG_LONG c) { S; return c/3; }
EXPORT(unsigned PY_LONG_LONG) tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; }
EXPORT(long long) tf_q(long long c) { S; return c/3; }
EXPORT(unsigned long long) tf_Q(unsigned long long c) { U; return c/3; }
EXPORT(float) tf_f(float c) { S; return c/3; }
EXPORT(double) tf_d(double c) { S; return c/3; }
EXPORT(long double) tf_D(long double c) { S; return c/3; }
Expand All @@ -471,8 +471,8 @@ EXPORT(int) __stdcall s_tf_i(int c) { S; return c/3; }
EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { U; return c/3; }
EXPORT(long) __stdcall s_tf_l(long c) { S; return c/3; }
EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { U; return c/3; }
EXPORT(PY_LONG_LONG) __stdcall s_tf_q(PY_LONG_LONG c) { S; return c/3; }
EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; }
EXPORT(long long) __stdcall s_tf_q(long long c) { S; return c/3; }
EXPORT(unsigned long long) __stdcall s_tf_Q(unsigned long long c) { U; return c/3; }
EXPORT(float) __stdcall s_tf_f(float c) { S; return c/3; }
EXPORT(double) __stdcall s_tf_d(double c) { S; return c/3; }
EXPORT(long double) __stdcall s_tf_D(long double c) { S; return c/3; }
Expand All @@ -487,8 +487,8 @@ EXPORT(int) tf_bi(signed char x, int c) { S; return c/3; }
EXPORT(unsigned int) tf_bI(signed char x, unsigned int c) { U; return c/3; }
EXPORT(long) tf_bl(signed char x, long c) { S; return c/3; }
EXPORT(unsigned long) tf_bL(signed char x, unsigned long c) { U; return c/3; }
EXPORT(PY_LONG_LONG) tf_bq(signed char x, PY_LONG_LONG c) { S; return c/3; }
EXPORT(unsigned PY_LONG_LONG) tf_bQ(signed char x, unsigned PY_LONG_LONG c) { U; return c/3; }
EXPORT(long long) tf_bq(signed char x, long long c) { S; return c/3; }
EXPORT(unsigned long long) tf_bQ(signed char x, unsigned long long c) { U; return c/3; }
EXPORT(float) tf_bf(signed char x, float c) { S; return c/3; }
EXPORT(double) tf_bd(signed char x, double c) { S; return c/3; }
EXPORT(long double) tf_bD(signed char x, long double c) { S; return c/3; }
Expand All @@ -503,8 +503,8 @@ EXPORT(int) __stdcall s_tf_bi(signed char x, int c) { S; return c/3; }
EXPORT(unsigned int) __stdcall s_tf_bI(signed char x, unsigned int c) { U; return c/3; }
EXPORT(long) __stdcall s_tf_bl(signed char x, long c) { S; return c/3; }
EXPORT(unsigned long) __stdcall s_tf_bL(signed char x, unsigned long c) { U; return c/3; }
EXPORT(PY_LONG_LONG) __stdcall s_tf_bq(signed char x, PY_LONG_LONG c) { S; return c/3; }
EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_bQ(signed char x, unsigned PY_LONG_LONG c) { U; return c/3; }
EXPORT(long long) __stdcall s_tf_bq(signed char x, long long c) { S; return c/3; }
EXPORT(unsigned long long) __stdcall s_tf_bQ(signed char x, unsigned long long c) { U; return c/3; }
EXPORT(float) __stdcall s_tf_bf(signed char x, float c) { S; return c/3; }
EXPORT(double) __stdcall s_tf_bd(signed char x, double c) { S; return c/3; }
EXPORT(long double) __stdcall s_tf_bD(signed char x, long double c) { S; return c/3; }
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ union result {
short h;
int i;
long l;
PY_LONG_LONG q;
long long q;
long double D;
double d;
float f;
Expand Down
Loading

0 comments on commit 47ff073

Please sign in to comment.