diff options
author | Guido van Rossum <guido@python.org> | 1998-08-25 16:07:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-08-25 16:07:15 (GMT) |
commit | 3293b07df58a875afaf3fc82c1e499af59bc99e4 (patch) | |
tree | 8f72dc01a6d24e4df800dddd1d406e966c4ea61d | |
parent | 859b407cf12b0bcf6d7d56e48df765664e41e82b (diff) | |
download | cpython-3293b07df58a875afaf3fc82c1e499af59bc99e4.zip cpython-3293b07df58a875afaf3fc82c1e499af59bc99e4.tar.gz cpython-3293b07df58a875afaf3fc82c1e499af59bc99e4.tar.bz2 |
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.
-rw-r--r-- | Include/longobject.h | 11 | ||||
-rw-r--r-- | Objects/longobject.c | 44 | ||||
-rw-r--r-- | PC/config.h | 2 | ||||
-rw-r--r-- | Python/getargs.c | 12 | ||||
-rw-r--r-- | Python/modsupport.c | 2 |
5 files changed, 38 insertions, 33 deletions
diff --git a/Include/longobject.h b/Include/longobject.h index 774bfda..d9bc086 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -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)); diff --git a/Objects/longobject.c b/Objects/longobject.c index 992e769..742b184 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -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 *)); diff --git a/PC/config.h b/PC/config.h index 0bc8cc5..495b985 100644 --- a/PC/config.h +++ b/PC/config.h @@ -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 diff --git a/Python/getargs.c b/Python/getargs.c index 34e3a5c..86fd471 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -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 diff --git a/Python/modsupport.c b/Python/modsupport.c index 7e1acab..6066aa8 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -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': |