Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7953
Modified Files:
PyLARGE_INTEGER.cpp PyUnicode.cpp
Log Message:
Remove support for PYWIN_USE_PYUNICODE, MS_WINCE, NO_PYWINTYPES_BSTR
and PYWIN_NO_PYTHON_LONG_LONG
Index: PyUnicode.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyUnicode.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** PyUnicode.cpp 6 Feb 2008 18:37:46 -0000 1.26
--- PyUnicode.cpp 10 Feb 2008 13:46:57 -0000 1.27
***************
*** 8,15 ****
#include "malloc.h"
#include "tchar.h"
-
- #ifndef MS_WINCE
#include "locale.h"
- #endif
// @object PyUnicode|A Python object, representing a Unicode string.
--- 8,12 ----
***************
*** 21,26 ****
// a string must be passed a string.
- #ifndef MS_WINCE
-
BOOL PyWinObject_AsPfnAllocatedWCHAR(PyObject *stringObject, void *(*pfnAllocator)(ULONG), WCHAR **ppResult, BOOL bNoneOK /*= FALSE*/,DWORD *pResultLen /*= NULL*/)
{
--- 18,21 ----
***************
*** 43,53 ****
} else if (PyUnicode_Check(stringObject)) {
// copy the value, including embedded NULLs
- #if defined(PYWIN_USE_PYUNICODE)
WCHAR *v = (WCHAR *)PyUnicode_AS_UNICODE(stringObject);
UINT cch = PyUnicode_GET_SIZE(stringObject);
- #else
- WCHAR *v = ((PyUnicode *)stringObject)->m_bstrValue;
- UINT cch = SysStringLen(v);
- #endif
*ppResult = (WCHAR *)pfnAllocator((cch+1) * sizeof(WCHAR));
if (*ppResult)
--- 38,43 ----
***************
*** 90,97 ****
}
- #endif /* MS_WINCE */
-
- #if defined(PYWIN_USE_PYUNICODE)
-
/* Implement our Windows Unicode API using the Python widestring object */
PyObject *PyUnicodeObject_FromString(const char *string)
--- 80,83 ----
***************
*** 263,267 ****
}
- #ifndef NO_PYWINTYPES_BSTR
PyObject *PyWinObject_FromBstr(const BSTR bstr, BOOL takeOwnership /*=FALSE*/)
{
--- 249,252 ----
***************
*** 274,880 ****
return ret;
}
- #endif // NO_PYWINTYPES_BSTR
-
- #else /* not PYWIN_USE_PYUNICODE */
-
- PyObject *PyString_FromUnicode( const OLECHAR *str )
- {
- char *buf;
- if (str==NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- if (!PyWin_WCHAR_AsString((OLECHAR *)str, -1, &buf))
- return NULL;
- PyObject *ret = PyString_FromString(buf);
- PyWinObject_FreeString(buf);
- return ret;
- }
-
- PyObject *PyUnicodeObject_FromString(const char *string)
- {
- return new PyUnicode(string);
- }
-
- int PyUnicode_Size(PyObject *op)
- {
- if (!PyUnicode_Check(op)) {
- PyErr_BadInternalCall();
- return -1;
- }
- return PyUnicode::lengthFunc((PyUnicode *)op);
- }
-
- // Moved to a #define as it clashes with the new standard Python function
- /**
- WCHAR *PyUnicode_AsUnicode(PyObject *op)
- {
- return ((PyUnicode *)op)->m_bstrValue;
- }
- **/
-
-
- // Convert a WCHAR string to "char *"
- // If len is known, pass it, else -1
- // NOTE - string must be freed with PyWinObject_FreeString
- BOOL PyWin_WCHAR_AsString(WCHAR *input, DWORD inLen, char **pResult)
- {
- if (inLen==-1)
- inLen = wcslen(input);
- // convert from string len to include terminator.
- inLen++;
- char *buf = (char *)PyMem_Malloc(inLen);
-
- DWORD len = WideCharToMultiByte(CP_ACP, 0, input, inLen, buf, inLen, NULL, NULL);
- if (len==0) {
- PyMem_Free(buf);
- PyWin_SetAPIError("WideCharToMultiByte");
- return FALSE;
- }
- *pResult = buf;
- return TRUE;
- }
-
- BOOL PyWin_Bstr_AsString(BSTR input, char **pResult)
- {
- DWORD wideSize = SysStringLen(input);
- return PyWin_WCHAR_AsString(input, wideSize, pResult);
- }
-
- // Convert a Python object to a "char *" - allow embedded NULLs, None, etc.
- BOOL PyWinObject_AsString(PyObject *stringObject, char **pResult, BOOL bNoneOK /*= FALSE*/, DWORD *pResultLen /* = NULL */)
- {
- int strLen;
- BOOL rc = TRUE;
- if (PyString_Check(stringObject)) {
- strLen = PyString_Size(stringObject);
- *pResult = (char *)PyMem_Malloc((strLen + 1) * sizeof(char));
- if (*pResult==NULL) {
- PyErr_SetString(PyExc_MemoryError, "copying string");
- return FALSE;
- }
- memcpy(*pResult, PyString_AsString(stringObject), strLen);
- (*pResult)[strLen] = '\0';
- } else if (PyUnicode_Check(stringObject)) {
- strLen = SysStringLen(((PyUnicode *)stringObject)->m_bstrValue);
- rc = PyWin_Bstr_AsString(((PyUnicode *)stringObject)->m_bstrValue, pResult);
- } else if (stringObject == Py_None) {
- strLen = 0;
- if (bNoneOK) {
- *pResult = NULL;
- } else {
- PyErr_SetString(PyExc_TypeError, "None is not a valid string in this context");
- rc = FALSE;
- }
- } else {
- const char *tp_name = stringObject && stringObject->ob_type ? stringObject->ob_type->tp_name : "<NULL!!>";
- PyErr_Format(PyExc_TypeError, "Objects of type '%s' can not be converted to Unicode.", tp_name);
- rc = FALSE;
- }
- if (rc && !pResult) {
- PyErr_SetString(PyExc_MemoryError, "Allocating string");
- return FALSE;
- }
- if (rc && pResultLen) *pResultLen = strLen;
- return rc;
- }
-
- void PyWinObject_FreeString(char *str)
- {
- PyMem_Free(str);
- }
-
-
-
- // PyWinObject_FromBstr - convert a BSTR into a Python string.
- //
- // ONLY USE THIS FOR TRUE BSTR's - Use the fn below for OLECHAR *'s.
- // NOTE - does not use standard macros, so NULLs get through!
- PyObject *PyWinObject_FromBstr(const BSTR bstr, BOOL takeOwnership/*=FALSE*/)
- {
- if (bstr==NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return new PyUnicode(bstr, takeOwnership);
- }
-
- // Size info is available (eg, a fn returns a string and also fills in a size variable)
- PyObject *PyWinObject_FromOLECHAR(const OLECHAR * str, int numChars)
- {
- if (str==NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return new PyUnicode(str, numChars);
- }
-
- // No size info avail.
- PyObject *PyWinObject_FromOLECHAR(const OLECHAR * str)
- {
- if (str==NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return new PyUnicode(str);
- }
-
- static PySequenceMethods PyUnicode_SequenceMethods = {
- (inquiry)PyUnicode::lengthFunc, /*sq_length*/
- (binaryfunc)PyUnicode::concatFunc, /*sq_concat*/
- (intargfunc)PyUnicode::repeatFunc, /*sq_repeat*/
- (intargfunc)PyUnicode::itemFunc, /*sq_item*/
- (intintargfunc)PyUnicode::sliceFunc, /*sq_slice*/
- 0, /*sq_ass_item*/
- 0, /*sq_ass_slice*/
- };
-
- PYWINTYPES_EXPORT PyTypeObject PyUnicodeType =
- {
- PyObject_HEAD_INIT(&PyType_Type)
- 0,
- "PyUnicode",
- sizeof(PyUnicode),
- 0,
- PyUnicode::deallocFunc, /* tp_dealloc */
- PyUnicode::printFunc, /* tp_print */
- PyUnicode::getattrFunc, /* tp_getattr */
- 0, /* tp_setattr */
- PyUnicode::compareFunc, /* tp_compare */
- PyUnicode::reprFunc, /* tp_repr */
- 0, /* tp_as_number */
- &PyUnicode_SequenceMethods, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- PyUnicode::hashFunc, /* tp_hash */
- 0, /* tp_call */
- PyUnicode::strFunc, /* tp_str */
- };
-
- PyUnicode::PyUnicode(void)
- {
- ob_type = &PyUnicodeType;
- _Py_NewReference(this);
-
- m_bstrValue = NULL;
- }
-
- PyUnicode::PyUnicode(const char *value)
- {
- ob_type = &PyUnicodeType;
- _Py_NewReference(this);
- m_bstrValue = PyWin_String_AsBstr(value);
- }
-
- PyUnicode::PyUnicode(const char *value, unsigned int numBytes)
- {
- ob_type = &PyUnicodeType;
- _Py_NewReference(this);
-
- m_bstrValue = SysAllocStringByteLen(value, numBytes);
- }
-
- PyUnicode::PyUnicode(const OLECHAR *value)
- {
- ob_type = &PyUnicodeType;
- _Py_NewReference(this);
-
- m_bstrValue = SysAllocString(value);
- }
-
- PyUnicode::PyUnicode(const OLECHAR *value, int numChars)
- {
- ob_type = &PyUnicodeType;
- _Py_NewReference(this);
-
- m_bstrValue = SysAllocStringLen(value, numChars);
- }
-
- PyUnicode::PyUnicode(const BSTR value, BOOL takeOwnership /* = FALSE */)
- {
- ob_type = &PyUnicodeType;
- _Py_NewReference(this);
-
- if ( takeOwnership )
- m_bstrValue = value;
- else
- // copy the value, including embedded NULLs
- m_bstrValue = SysAllocStringLen(value, SysStringLen(value));
- }
-
- PyUnicode::PyUnicode(PyObject *value)
- {
- ob_type = &PyUnicodeType;
- _Py_NewReference(this);
-
- m_bstrValue = NULL;
- (void)PyWinObject_AsBstr(value, &m_bstrValue);
- }
-
- PyUnicode::~PyUnicode(void)
- {
- SysFreeString(m_bstrValue);
- }
-
- int PyUnicode::compare(PyObject *ob)
- {
- int l1 = SysStringByteLen(m_bstrValue);
- OLECHAR *s = ((PyUnicode *)ob)->m_bstrValue;
- int l2 = SysStringByteLen(s);
- if ( l1 == 0 )
- if ( l2 > 0 )
- return -1;
- else
- return 0;
- if ( l2 == 0 && l1 > 0 )
- return 1;
- int len = l1;
- if ( l2 < l1 )
- len = l2;
- int cmp = memcmp(m_bstrValue, s, len);
- if ( cmp == 0 )
- {
- if ( l1 < l2 )
- return -1;
- return l1 > l2;
- }
- return cmp;
- }
-
- PyObject * PyUnicode::concat(PyObject *ob)
- {
- if ( !PyUnicode_Check(ob) ) {
- PyErr_SetString(PyExc_TypeError, "illegal argument type for PyUnicode concatenation");
- return NULL;
- }
-
- BSTR s2 = ((PyUnicode *)ob)->m_bstrValue;
- int l1 = SysStringLen(m_bstrValue);
- int l2 = SysStringLen(s2);
- BSTR bres = SysAllocStringLen(NULL, l1 + l2);
- if ( m_bstrValue )
- memcpy(bres, m_bstrValue, l1 * sizeof(*bres));
- if ( s2 )
- memcpy(&bres[l1], s2, l2 * sizeof(*bres));
- bres[l1+l2] = L'\0';
- return new PyUnicode(bres, /* takeOwnership= */ TRUE);
- }
-
- PyObject * PyUnicode::repeat(int count)
- {
- int l = SysStringLen(m_bstrValue);
- if ( l == 0 )
- return new PyUnicode();
-
- BSTR bres = SysAllocStringLen(NULL, l * count);
- OLECHAR *p = bres;
- for ( int i = count; i--; p += l )
- memcpy(p, m_bstrValue, l * sizeof(*p));
- bres[l*count] = L'\0';
- return new PyUnicode(bres, /* takeOwnership= */ TRUE);
- }
-
- PyObject * PyUnicode::item(int index)
- {
- int l = SysStringLen(m_bstrValue);
- if ( index < 0 || index >= l )
- {
- PyErr_SetString(PyExc_IndexError, "unicode index out of range");
- return NULL;
- }
- // ### tricky to get the correct constructor
- return new PyUnicode((const OLECHAR *)&m_bstrValue[index], (int)1);
- }
-
- PyObject * PyUnicode::slice(int start, int end)
- {
- int l = SysStringLen(m_bstrValue);
- if ( start < 0 )
- start = 0;
- if ( end < 0 )
- end = 0;
- if ( end > l )
- end = l;
- if ( start == 0 && end == l )
- {
- Py_INCREF(this);
- return this;
- }
- if ( end <= start )
- return new PyUnicode();
-
- BSTR bres = SysAllocStringLen(&m_bstrValue[start], end - start);
- return new PyUnicode(bres, /* takeOwnership= */ TRUE);
- }
-
- long PyUnicode::hash(void)
- {
- /* snarfed almost exactly from stringobject.c */
-
- int orig_len = SysStringByteLen(m_bstrValue);
- register int len = orig_len;
- register unsigned char *p;
- register long x;
-
- p = (unsigned char *)m_bstrValue;
- x = *p << 7;
- while (--len >= 0)
- x = (1000003*x) ^ *p++;
- x ^= orig_len;
- if (x == -1)
- x = -2;
- return x;
- }
-
- PyObject * PyUnicode::asStr(void)
- {
- if ( m_bstrValue == NULL )
- return PyString_FromString("");
-
- /*
- ** NOTE: we always provide lengths to avoid computing null-term and
- ** and to carry through any NULL values.
- */
-
- /* how many chars (including nulls) are in the BSTR? */
- int cchWideChar = SysStringLen(m_bstrValue);
-
- /* get the output length */
- int cchMultiByte = WideCharToMultiByte(CP_ACP, 0, m_bstrValue, cchWideChar,
- NULL, 0, NULL, NULL);
-
- /* Create the Python string, and use it as the conversion buffer. */
- PyObject *result = PyString_FromStringAndSize(NULL, cchMultiByte);
- if (result==NULL) return NULL;
-
- /* do the conversion */
- WideCharToMultiByte(CP_ACP, 0, m_bstrValue, cchWideChar, PyString_AS_STRING((PyStringObject *)result),
- cchMultiByte, NULL, NULL);
-
- /* return the Python object */
- return result;
- }
-
- int PyUnicode::print(FILE *fp, int flags)
- {
- LPSTR s;
- if ( m_bstrValue )
- {
- /* NOTE: BSTR values are *always* null-termed */
- int numBytes = WideCharToMultiByte(CP_ACP, 0, m_bstrValue, -1, NULL, 0, NULL, NULL);
- s = (LPSTR)alloca(numBytes+1);
- WideCharToMultiByte(CP_ACP, 0, m_bstrValue, -1, s, numBytes, NULL, NULL);
- }
- else
- s = NULL;
-
- // USES_CONVERSION;
- // char *s = W2A(m_bstrValue);
- TCHAR resBuf[80];
-
- if ( s == NULL )
- _tcscpy(resBuf, _T("<PyUnicode: NULL>"));
- else if ( strlen(s) > 40 )
- {
- s[40] = '\0';
- wsprintf(resBuf, _T("<PyUnicode: '%s'...>"), s);
- }
- else
- wsprintf(resBuf, _T("<PyUnicode: '%s'>"), s);
-
- //
- // ### ACK! Python uses a non-debug runtime. We can't use stream
- // ### functions when in DEBUG mode!! (we link against a different
- // ### runtime library) Hack it by getting Python to do the print!
- //
- // ### - Double Ack - Always use the hack!
- // #ifdef _DEBUG
- PyObject *ob = PyString_FromTCHAR(resBuf);
- PyObject_Print(ob, fp, flags|Py_PRINT_RAW);
- Py_DECREF(ob);
- /***#else
- fputs(resBuf, fp);
- #endif
- ***/
- return 0;
- }
-
- PyObject *PyUnicode::repr()
- {
- // Do NOT write an "L" - Python opted for "u" anyway,
- // and pre 2.0 builds work nicer if we just pretend we are a string in repr.
- PyObject *obStr = asStr();
- if (obStr==NULL)
- return NULL;
- PyObject *obRepr = PyObject_Repr(obStr);
- Py_DECREF(obStr);
- return obRepr;
- /***
- // This is not quite correct, but good enough for now.
- // To save me lots of work, I convert the Unicode to a temporary
- // string object, then perform a repr on the string object, then
- // simply prefix with an 'L' to indicate the string is Unicode.
- PyObject *obStr = asStr();
- if (obStr==NULL)
- return NULL;
- PyObject *obRepr = PyObject_Repr(obStr);
- Py_DECREF(obStr);
- if (obRepr==NULL)
- return NULL;
-
- char *szVal = PyString_AsString(obRepr);
- int strSize = PyString_Size(obRepr);
- char *buffer = (char *)alloca(strSize+2); // trailing NULL and L
- buffer[0] = 'L';
- memcpy(buffer+1, szVal, strSize);
- buffer[strSize+1] = '\0';
- Py_DECREF(obRepr);
- return PyString_FromStringAndSize(buffer, strSize+1);
- ***/
- }
-
- PyObject * PyUnicode::upper(void)
- {
- /* copy the value; don't worry about NULLs since _wcsupr doesn't */
- BSTR v = SysAllocString(m_bstrValue);
-
- /* upper-case the thing */
- if ( v )
- {
- #ifndef MS_WINCE
- setlocale(LC_CTYPE, "");
- #endif
- _wcsupr(v);
- }
-
- /* wrap it into a new object and return it */
- return new PyUnicode(v, /* takeOwnership= */ TRUE);
- }
-
- PyObject * PyUnicode::lower(void)
- {
- /* copy the value; don't worry about NULLs since _wcsupr doesn't */
- BSTR v = SysAllocString(m_bstrValue);
-
- /* upper-case the thing */
- if ( v )
- {
- #ifndef MS_WINCE
- setlocale(LC_CTYPE, "");
- #endif
- _wcslwr(v);
- }
-
- /* wrap it into a new object and return it */
- return new PyUnicode(v, /* takeOwnership= */ TRUE);
- }
-
- static struct PyMethodDef PyUnicode_methods[] = {
- { "upper", PyUnicode::upperFunc, METH_VARARGS },
- { "lower", PyUnicode::lowerFunc, METH_VARARGS },
- { NULL, NULL } /* sentinel */
- };
-
- PyObject * PyUnicode::getattr(char *name)
- {
- if ( !strcmp(name, "raw") )
- {
- if ( m_bstrValue == NULL )
- return PyString_FromString("");
-
- int len = SysStringByteLen(m_bstrValue);
- return PyString_FromStringAndSize((char *)(void *)m_bstrValue, len);
- }
-
- return Py_FindMethod(PyUnicode_methods, this, name);
- }
-
- /*static*/ void PyUnicode::deallocFunc(PyObject *ob)
- {
- delete (PyUnicode *)ob;
- }
-
- // @pymethod int|PyUnicode|__cmp__|Used when objects are compared.
- int PyUnicode::compareFunc(PyObject *ob1, PyObject *ob2)
- {
- return ((PyUnicode *)ob1)->compare(ob2);
- }
-
- // @pymethod int|PyUnicode|__hash__|Used when the hash value of a Unicode object is required
- long PyUnicode::hashFunc(PyObject *ob)
- {
- return ((PyUnicode *)ob)->hash();
- }
-
- // @pymethod |PyUnicode|__str__|Used when a (8-bit) string representation of the Unicode object is required.
- PyObject * PyUnicode::strFunc(PyObject *ob)
- {
- return ((PyUnicode *)ob)->asStr();
- }
-
- // @pymethod |PyUnicode|__print__|Used when the Unicode object is printed.
- int PyUnicode::printFunc(PyObject *ob, FILE *fp, int flags)
- {
- return ((PyUnicode *)ob)->print(fp, flags);
- }
-
- // @pymethod |PyUnicode|__repr__|Used when repr(object) is used.
- PyObject *PyUnicode::reprFunc(PyObject *ob)
- {
- // @comm Note the format is L'string' and that the string portion
- // is currently not escaped, as Python does for normal strings.
- return ((PyUnicode *)ob)->repr();
- }
-
- // @pymethod |PyUnicode|__getattr__|Used to access attributes of the Unicode object.
- PyObject * PyUnicode::getattrFunc(PyObject *ob, char *name)
- {
- return ((PyUnicode *)ob)->getattr(name);
- }
-
- int PyUnicode::lengthFunc(PyObject *ob)
- {
- return SysStringLen(((PyUnicode *)ob)->m_bstrValue);
- }
-
- PyObject * PyUnicode::concatFunc(PyObject *ob1, PyObject *ob2)
- {
- return ((PyUnicode *)ob1)->concat(ob2);
- }
-
- PyObject * PyUnicode::repeatFunc(PyObject *ob, int count)
- {
- return ((PyUnicode *)ob)->repeat(count);
- }
-
- PyObject * PyUnicode::itemFunc(PyObject *ob, int index)
- {
- return ((PyUnicode *)ob)->item(index);
- }
-
- PyObject * PyUnicode::sliceFunc(PyObject *ob, int start, int end)
- {
- return ((PyUnicode *)ob)->slice(start, end);
- }
-
- PyObject * PyUnicode::upperFunc(PyObject *ob, PyObject *args)
- {
- if ( !PyArg_ParseTuple(args, ":upper"))
- return NULL;
- return ((PyUnicode *)ob)->upper();
- }
-
- PyObject * PyUnicode::lowerFunc(PyObject *ob, PyObject *args)
- {
- if ( !PyArg_ParseTuple(args, ":lower"))
- return NULL;
- return ((PyUnicode *)ob)->lower();
- }
-
- #endif /* PYWIN_USE_PYUNICODE */
///////////////////////////////////////////////////////////
//
// Some utilities etc
- #ifndef NO_PYWINTYPES_BSTR
PyWin_AutoFreeBstr::PyWin_AutoFreeBstr( BSTR bstr /*= NULL*/ )
--- 259,266 ----
***************
*** 932,936 ****
{
// copy the value, including embedded NULLs
- #if defined(PYWIN_USE_PYUNICODE)
int nchars = PyUnicode_GET_SIZE(stringObject);
*pResult = SysAllocStringLen(NULL, nchars);
--- 318,321 ----
***************
*** 944,951 ****
(*pResult)[nchars] = 0;
}
- #else
- BSTR v = ((PyUnicode *)stringObject)->m_bstrValue;
- *pResult = SysAllocStringLen(v, SysStringLen(v));
- #endif
}
else if (stringObject == Py_None) {
--- 329,332 ----
***************
*** 974,979 ****
}
- #endif // NO_PYWINTYPES_BSTR
-
// String conversions
// Convert a Python object to a WCHAR - allow embedded NULLs, None, etc.
--- 355,358 ----
Index: PyLARGE_INTEGER.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyLARGE_INTEGER.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** PyLARGE_INTEGER.cpp 24 May 2007 06:01:05 -0000 1.11
--- PyLARGE_INTEGER.cpp 10 Feb 2008 13:46:57 -0000 1.12
***************
*** 29,77 ****
#endif
- #ifdef PYWIN_NO_PYTHON_LONG_LONG
- /* If we either dont have, or dont want to use, Python's native
- 64bit integer support.
- */
- PyLongObject *PyLong_Normalize(register PyLongObject *v);
- PyLongObject *alloclongobject(int size);
- static __int64 PyWLong_AsLongLong(PyObject *vv);
- #define PyLong_AsLongLong PyWLong_AsLongLong
-
- static unsigned __int64 PyWLong_AsUnsignedLongLong(PyObject *vv);
- #define PyLong_AsUnsignedLongLong PyWLong_AsUnsignedLongLong
-
-
- PyObject *PyLong_FromI64(__int64 ival)
- {
- int i;
-
- /* A 64-bit value should fit in 5 'digits' */
- int n = 5;
- PyLongObject *v = alloclongobject(n);
- if (v == NULL)
- return NULL;
-
- if (ival < 0)
- {
- ival = -ival;
- v->ob_size = -(v->ob_size);
- }
-
- unsigned __int64 uval = (unsigned __int64)ival;
- for (i = 0; i < n; i++)
- {
- v->ob_digit[i] = (unsigned short)(uval & MASK);
- uval = (uval >> SHIFT);
- }
- v = PyLong_Normalize(v);
-
- return (PyObject*)v;
- }
-
- // ### the hack already does unsigned(!)
- #define PyLong_FromUI64(x) PyLong_FromI64(x)
-
- #else // PYWIN_NO_PYTHON_LONG_LONG
- // We have native support - use it.
PyObject *PyLong_FromI64(__int64 ival)
{
--- 29,32 ----
***************
*** 83,88 ****
}
- #endif // PYWIN_NO_PYTHON_LONG_LONG
-
BOOL PyLong_AsI64(PyObject *val, __int64 *lval)
{
--- 38,41 ----
***************
*** 191,259 ****
return PyLong_FromUI64(val.QuadPart);
}
-
- #ifdef PYWIN_NO_PYTHON_LONG_LONG
- // Our own hacks for 64bit support.
- #include <longintrepr.h>
-
- #define ABS(x) ((x) < 0 ? -(x) : (x))
-
- PyLongObject *PyLong_Normalize(register PyLongObject *v)
- {
- Py_ssize_t j = ABS(v->ob_size);
- register Py_ssize_t i = j;
-
- while (i > 0 && v->ob_digit[i-1] == 0)
- --i;
- if (i != j)
- v->ob_size = (v->ob_size < 0) ? -(i) : i;
- return v;
- }
-
- PyLongObject *alloclongobject(int size)
- {
- return PyObject_NEW_VAR(PyLongObject, &PyLong_Type, size);
- }
-
-
- __int64
- PyWLong_AsLongLong(PyObject *vv)
- {
- register PyLongObject *v;
- __int64 x, prev;
- Py_ssize_t i, sign;
-
- if (vv == NULL || !PyLong_Check(vv)) {
- PyErr_BadInternalCall();
- return -1;
- }
-
- v = (PyLongObject *)vv;
- i = v->ob_size;
- sign = 1;
- x = 0;
-
- if (i < 0) {
- sign = -1;
- i = -(i);
- }
-
- while (--i >= 0) {
- prev = x;
- x = (x << SHIFT) + v->ob_digit[i];
- if ((x >> SHIFT) != prev) {
- PyErr_SetString(PyExc_OverflowError,
- "long int too long to convert");
- return -1;
- }
- }
-
- return x * sign;
- }
-
- // ### hack this dumb thing for now
- unsigned __int64
- PyWLong_AsUnsignedLongLong(PyObject *vv)
- {
- return (unsigned __int64)PyLong_AsLongLong(vv);
- }
- #endif
--- 144,145 ----
|