mirror of https://github.com/python/cpython
Patch by Mark Hammond to support 64-bit ints on MS platforms.
The MS compiler doesn't call it 'long long', it uses __int64, so a new #define, LONG_LONG, has been added and all occurrences of 'long long' are replaced with it.
This commit is contained in:
parent
859b407cf1
commit
3293b07df5
|
@ -51,11 +51,14 @@ extern unsigned long PyLong_AsUnsignedLong Py_PROTO((PyObject *));
|
|||
extern double PyLong_AsDouble Py_PROTO((PyObject *));
|
||||
|
||||
#ifdef HAVE_LONG_LONG
|
||||
extern PyObject *PyLong_FromLongLong Py_PROTO((long long ));
|
||||
extern PyObject *PyLong_FromUnsignedLongLong Py_PROTO((unsigned long long));
|
||||
extern long long PyLong_AsLongLong Py_PROTO((PyObject *));
|
||||
extern unsigned long long PyLong_AsUnsignedLongLong Py_PROTO((PyObject *));
|
||||
#ifndef LONG_LONG
|
||||
#define LONG_LONG long long
|
||||
#endif
|
||||
extern PyObject *PyLong_FromLongLong Py_PROTO((LONG_LONG));
|
||||
extern PyObject *PyLong_FromUnsignedLongLong Py_PROTO((unsigned LONG_LONG));
|
||||
extern LONG_LONG PyLong_AsLongLong Py_PROTO((PyObject *));
|
||||
extern unsigned LONG_LONG PyLong_AsUnsignedLongLong Py_PROTO((PyObject *));
|
||||
#endif /* HAVE_LONG_LONG */
|
||||
|
||||
PyObject *PyLong_FromString Py_PROTO((char *, char **, int));
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ PyLong_AsDouble(vv)
|
|||
|
||||
#ifdef HAVE_LONG_LONG
|
||||
/*
|
||||
* long long support by Chris Herborth (chrish@qnx.com)
|
||||
* LONG_LONG support by Chris Herborth (chrish@qnx.com)
|
||||
*
|
||||
* For better or worse :-), I tried to follow the coding style already
|
||||
* here.
|
||||
|
@ -303,30 +303,30 @@ PyLong_AsDouble(vv)
|
|||
#define ULONGLONG_MAX 0xffffffffffffffffULL
|
||||
#endif
|
||||
|
||||
/* Create a new long int object from a C long long int */
|
||||
/* Create a new long int object from a C LONG_LONG int */
|
||||
|
||||
PyObject *
|
||||
PyLong_FromLongLong(ival)
|
||||
long long ival;
|
||||
LONG_LONG ival;
|
||||
{
|
||||
#if SIZEOF_LONG_LONG == SIZEOF_LONG
|
||||
/* In case the compiler is faking it. */
|
||||
return PyLong_FromLong( (long)ival );
|
||||
#else
|
||||
if( ival <= (long long)LONG_MAX ) {
|
||||
if( ival <= (LONG_LONG)LONG_MAX ) {
|
||||
return PyLong_FromLong( (long)ival );
|
||||
}
|
||||
else if( ival <= (unsigned long long)ULONG_MAX ) {
|
||||
else if( ival <= (unsigned LONG_LONG)ULONG_MAX ) {
|
||||
return PyLong_FromUnsignedLong( (unsigned long)ival );
|
||||
}
|
||||
else {
|
||||
/* Assume a C long long fits in at most 10 'digits'.
|
||||
/* Assume a C LONG_LONG fits in at most 10 'digits'.
|
||||
* Should be OK if we're assuming long fits in 5.
|
||||
*/
|
||||
PyLongObject *v = _PyLong_New(10);
|
||||
|
||||
if (v != NULL) {
|
||||
unsigned long long t = ival;
|
||||
unsigned LONG_LONG t = ival;
|
||||
int i;
|
||||
if (ival < 0) {
|
||||
t = -ival;
|
||||
|
@ -350,16 +350,16 @@ PyLong_FromLongLong(ival)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* Create a new long int object from a C unsigned long long int */
|
||||
/* Create a new long int object from a C unsigned LONG_LONG int */
|
||||
PyObject *
|
||||
PyLong_FromUnsignedLongLong(ival)
|
||||
unsigned long long ival;
|
||||
unsigned LONG_LONG ival;
|
||||
{
|
||||
#if SIZEOF_LONG_LONG == SIZEOF_LONG
|
||||
/* In case the compiler is faking it. */
|
||||
return PyLong_FromUnsignedLong( (unsigned long)ival );
|
||||
#else
|
||||
if( ival <= (unsigned long long)ULONG_MAX ) {
|
||||
if( ival <= (unsigned LONG_LONG)ULONG_MAX ) {
|
||||
return PyLong_FromUnsignedLong( (unsigned long)ival );
|
||||
}
|
||||
else {
|
||||
|
@ -367,7 +367,7 @@ PyLong_FromUnsignedLongLong(ival)
|
|||
PyLongObject *v = _PyLong_New(10);
|
||||
|
||||
if (v != NULL) {
|
||||
unsigned long long t = ival;
|
||||
unsigned LONG_LONG t = ival;
|
||||
int i;
|
||||
for (i = 0; i < 10; i++) {
|
||||
v->ob_digit[i] = (digit) (t & MASK);
|
||||
|
@ -386,19 +386,19 @@ PyLong_FromUnsignedLongLong(ival)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* Get a C long long int from a long int object.
|
||||
/* Get a C LONG_LONG int from a long int object.
|
||||
Returns -1 and sets an error condition if overflow occurs. */
|
||||
|
||||
long long
|
||||
LONG_LONG
|
||||
PyLong_AsLongLong(vv)
|
||||
PyObject *vv;
|
||||
{
|
||||
#if SIZEOF_LONG_LONG == SIZEOF_LONG
|
||||
/* In case the compiler is faking it. */
|
||||
return (long long)PyLong_AsLong( vv );
|
||||
return (LONG_LONG)PyLong_AsLong( vv );
|
||||
#else
|
||||
register PyLongObject *v;
|
||||
long long x, prev;
|
||||
LONG_LONG x, prev;
|
||||
int i, sign;
|
||||
|
||||
if (vv == NULL || !PyLong_Check(vv)) {
|
||||
|
@ -430,21 +430,21 @@ PyLong_AsLongLong(vv)
|
|||
#endif
|
||||
}
|
||||
|
||||
unsigned long long
|
||||
unsigned LONG_LONG
|
||||
PyLong_AsUnsignedLongLong(vv)
|
||||
PyObject *vv;
|
||||
{
|
||||
#if SIZEOF_LONG_LONG == 4
|
||||
/* In case the compiler is faking it. */
|
||||
return (unsigned long long)PyLong_AsUnsignedLong( vv );
|
||||
return (unsigned LONG_LONG)PyLong_AsUnsignedLong( vv );
|
||||
#else
|
||||
register PyLongObject *v;
|
||||
unsigned long long x, prev;
|
||||
unsigned LONG_LONG x, prev;
|
||||
int i;
|
||||
|
||||
if (vv == NULL || !PyLong_Check(vv)) {
|
||||
PyErr_BadInternalCall();
|
||||
return (unsigned long long) -1;
|
||||
return (unsigned LONG_LONG) -1;
|
||||
}
|
||||
|
||||
v = (PyLongObject *)vv;
|
||||
|
@ -454,7 +454,7 @@ PyLong_AsUnsignedLongLong(vv)
|
|||
if (i < 0) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"can't convert negative value to unsigned long");
|
||||
return (unsigned long long) -1;
|
||||
return (unsigned LONG_LONG) -1;
|
||||
}
|
||||
|
||||
while (--i >= 0) {
|
||||
|
@ -463,7 +463,7 @@ PyLong_AsUnsignedLongLong(vv)
|
|||
if ((x >> SHIFT) != prev) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"long int too long to convert");
|
||||
return (unsigned long long) -1;
|
||||
return (unsigned LONG_LONG) -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -907,7 +907,7 @@ x_divrem(v1, w1, prem)
|
|||
static void long_dealloc Py_PROTO((PyObject *));
|
||||
static PyObject *long_repr Py_PROTO((PyObject *));
|
||||
static int long_compare Py_PROTO((PyLongObject *, PyLongObject *));
|
||||
static long long_hash Py_PROTO((PyLongObject *));
|
||||
static LONG_LONG_hash Py_PROTO((PyLongObject *));
|
||||
|
||||
static PyObject *long_add Py_PROTO((PyLongObject *, PyLongObject *));
|
||||
static PyObject *long_sub Py_PROTO((PyLongObject *, PyLongObject *));
|
||||
|
|
|
@ -85,6 +85,8 @@ typedef int pid_t;
|
|||
#define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
|
||||
#endif
|
||||
|
||||
#define HAVE_LONG_LONG 1
|
||||
#define LONG_LONG __int64
|
||||
#endif /* _MSC_VER && > 850 */
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 850
|
||||
|
|
|
@ -500,11 +500,11 @@ convertsimple1(arg, p_format, p_va)
|
|||
}
|
||||
|
||||
#if HAVE_LONG_LONG
|
||||
case 'L': /* long long */
|
||||
case 'L': /* LONG_LONG */
|
||||
{
|
||||
long long *p = va_arg( *p_va, long long * );
|
||||
long long ival = PyLong_AsLongLong( arg );
|
||||
if( ival == (long long)-1 && PyErr_Occurred() ) {
|
||||
LONG_LONG *p = va_arg( *p_va, LONG_LONG * );
|
||||
LONG_LONG ival = PyLong_AsLongLong( arg );
|
||||
if( ival == (LONG_LONG)-1 && PyErr_Occurred() ) {
|
||||
return "long<L>";
|
||||
} else {
|
||||
*p = ival;
|
||||
|
@ -1003,9 +1003,9 @@ skipitem(p_format, p_va)
|
|||
}
|
||||
|
||||
#if HAVE_LONG_LONG
|
||||
case 'L': /* long long int */
|
||||
case 'L': /* LONG_LONG int */
|
||||
{
|
||||
(void) va_arg(*p_va, long long *);
|
||||
(void) va_arg(*p_va, LONG_LONG *);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -293,7 +293,7 @@ do_mkvalue(p_format, p_va)
|
|||
|
||||
#if HAVE_LONG_LONG
|
||||
case 'L':
|
||||
return PyLong_FromLongLong((long long)va_arg(*p_va, long long));
|
||||
return PyLong_FromLongLong((LONG_LONG)va_arg(*p_va, LONG_LONG));
|
||||
#endif
|
||||
|
||||
case 'f':
|
||||
|
|
Loading…
Reference in New Issue