Update of /cvsroot/pywin32/pywin32/win32/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv25499/win32/src
Modified Files:
Tag: py3k
PyWinTypes.h PyUnicode.cpp
Log Message:
* PyUnicode_Size dies.
* PyWinObject_FromTCHAR returns a unicode object in py3k, even
for non-UNICODE builds.
* New PyWinCoreString_FromString() helper that always returns a
string in py2x and unicode in py3k
* PyString_FromUnicode dies (its very rare you want a 2x style
string object from unicode, and all those cases are now
handled by PyWinCoreString_FromString
* PyUnicodeObject_FromString takes an optional length arg.
* PyWinStringObject_FromIID/PyWinUnicodeObject_FromIID replaced with
PyWinCoreString_FromIID.
Index: PyWinTypes.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypes.h,v
retrieving revision 1.51.2.3
retrieving revision 1.51.2.4
diff -C2 -d -r1.51.2.3 -r1.51.2.4
*** PyWinTypes.h 27 Sep 2008 15:56:00 -0000 1.51.2.3
--- PyWinTypes.h 1 Oct 2008 12:53:00 -0000 1.51.2.4
***************
*** 139,144 ****
PYWINTYPES_EXPORT PyObject *PyWin_SetBasicCOMError(HRESULT hr);
- extern PYWINTYPES_EXPORT int PyUnicode_Size(PyObject *op);
-
// Given a PyObject (string, Unicode, etc) create a "BSTR" with the value
PYWINTYPES_EXPORT BOOL PyWinObject_AsBstr(PyObject *stringObject, BSTR *pResult, BOOL bNoneOK = FALSE, DWORD *pResultLen = NULL);
--- 139,142 ----
***************
*** 207,249 ****
*/
! #ifdef UNICODE
! #define PyWinObject_AsTCHAR PyWinObject_AsWCHAR
! #define PyWinObject_FreeTCHAR PyWinObject_FreeWCHAR
! #define PyWinObject_FromTCHAR PyWinObject_FromOLECHAR
! #define PyString_FromTCHAR PyString_FromUnicode
! #else /* not UNICODE */
! #define PyWinObject_AsTCHAR PyWinObject_AsString
! #define PyWinObject_FreeTCHAR PyWinObject_FreeString
! inline PyObject *PyWinObject_FromTCHAR(const char *str )
! {
! if (str==NULL){
! Py_INCREF(Py_None);
! return Py_None;
! }
! return PyString_FromString(str);
! }
!
! /* ??? In ANSI mode, compiler won't select either one of the other
! overloads even when the CString is explicitely cast to (TCHAR *) or (char *).
! However, it does work when UNICODE is defined, maybe something
! to do with inline ????
! */
! /*
! inline PyObject *PyWinObject_FromTCHAR(CString *str )
{
! return PyWinObject_FromTCHAR((TCHAR *)str);
}
- */
! inline PyObject *PyWinObject_FromTCHAR(const char *str, int numChars )
{
! if (str==NULL){
! Py_INCREF(Py_None);
! return Py_None;
! }
! return PyString_FromStringAndSize(str, numChars);
! }
! #define PyString_FromTCHAR PyString_FromString
#endif
#define PyWinObject_FromWCHAR PyWinObject_FromOLECHAR
--- 205,236 ----
*/
! // Helpers with py3k in mind: the result object is always a "core string"
! // object; ie, a string in py2k and unicode in py3k. Mainly to be used for
! // objects that *must* be that type - tp_str slots, __dict__ items, etc. If
! // Python doesn't *insist* the result be this type, consider using a function
! // that always returns a unicode object (ie, most of the "PyWinObject_From*CHAR"
! // functions)
! // XXX - move these from being inlines...
! inline PyObject *PyWinCoreString_FromString(const char *str, Py_ssize_t len=(Py_ssize_t)-1)
{
! if (len==(Py_ssize_t)-1)
! len = strlen(str);
! #if (PY_VERSION_HEX < 0x03000000)
! return PyString_FromStringAndSize(str, len);
! #else
! return PyUnicode_DecodeMBCS(str, len, "ignore");
! #endif
}
! inline PyObject *PyWinCoreString_FromString(const WCHAR *str, Py_ssize_t len=(Py_ssize_t)-1)
{
! if (len==(Py_ssize_t)-1)
! len = wcslen(str);
! #if (PY_VERSION_HEX < 0x03000000)
! return PyUnicode_EncodeMBCS(str, len, "ignore");
! #else
! return PyUnicode_FromWideChar(str, len);
#endif
+ }
#define PyWinObject_FromWCHAR PyWinObject_FromOLECHAR
***************
*** 270,275 ****
PYWINTYPES_EXPORT BOOL PyWinObject_AsCharArray(PyObject *str_seq, char ***pchars, DWORD *str_cnt, BOOL bNoneOK = FALSE);
! PYWINTYPES_EXPORT PyObject *PyString_FromUnicode( const OLECHAR *str );
! PYWINTYPES_EXPORT PyObject *PyUnicodeObject_FromString(const char *string);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromOLECHAR(const OLECHAR * str);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromOLECHAR(const OLECHAR * str, int numChars);
--- 257,261 ----
PYWINTYPES_EXPORT BOOL PyWinObject_AsCharArray(PyObject *str_seq, char ***pchars, DWORD *str_cnt, BOOL bNoneOK = FALSE);
! PYWINTYPES_EXPORT PyObject *PyUnicodeObject_FromString(const char *string, Py_ssize_t len=(Py_ssize_t)-1);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromOLECHAR(const OLECHAR * str);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromOLECHAR(const OLECHAR * str, int numChars);
***************
*** 282,285 ****
--- 268,302 ----
DWORD *pResultLen = NULL);
+ #ifdef UNICODE
+ // XXX - "AsTCHAR" functions should all die - the type of the Python object
+ // being returned should not depend on UNICODE or not.
+ #define PyWinObject_AsTCHAR PyWinObject_AsWCHAR
+ #define PyWinObject_FreeTCHAR PyWinObject_FreeWCHAR
+ #define PyWinObject_FromTCHAR PyWinObject_FromOLECHAR
+ #else /* not UNICODE */
+ #define PyWinObject_AsTCHAR PyWinObject_AsString
+ #define PyWinObject_FreeTCHAR PyWinObject_FreeString
+
+ inline PyObject *PyWinObject_FromTCHAR(const char *str, Py_ssize_t len=(Py_ssize_t)-1)
+ {
+ if (str==NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ // PyWinObject_FromTCHAR in a non-unicode build still depends on py3k or not:
+ // py2x a string object is returned (no conversions). py3x a unicode object
+ // is returned (ie, the string is decoded)
+ #if (PY_VERSION_HEX < 0x03000000)
+ if (len==(Py_ssize_t)-1)
+ return PyString_FromString(str);
+ else
+ return PyString_FromStringAndSize(str, len);
+ #else
+ return PyUnicodeObject_FromString(str, len);
+ #endif
+ }
+ #define PyString_FromTCHAR PyString_FromString
+ #endif
+
// String support for buffers allocated via CoTaskMemAlloc and CoTaskMemFree
PYWINTYPES_EXPORT BOOL PyWinObject_AsTaskAllocatedWCHAR(PyObject *stringObject, WCHAR **ppResult, BOOL bNoneOK /*= FALSE*/,DWORD *pResultLen /*= NULL*/);
***************
*** 311,316 ****
PYWINTYPES_EXPORT PyObject *PyWinObject_FromLARGE_INTEGER(LARGE_INTEGER &val);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromULARGE_INTEGER(ULARGE_INTEGER &val);
- #define PyLong_FromLARGE_INTEGER PyWinObject_FromLARGE_INTEGER
- #define PyLong_FromULARGE_INTEGER PyWinObject_FromULARGE_INTEGER
// Helpers that take a Py_LONG_LONG, but (a) have pywin32 consistent signatures
// and (b) handle int *and* long (where Python only starts doing that in the
--- 328,331 ----
***************
*** 377,382 ****
// return a string/Unicode object representing an IID
! PYWINTYPES_EXPORT PyObject *PyWinStringObject_FromIID(const IID &riid);
! PYWINTYPES_EXPORT PyObject *PyWinUnicodeObject_FromIID(const IID &riid);
// A global function that can work as a module method for making an IID object.
--- 392,396 ----
// return a string/Unicode object representing an IID
! PYWINTYPES_EXPORT PyObject *PyWinCoreString_FromIID(const IID &riid);
// A global function that can work as a module method for making an IID object.
Index: PyUnicode.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyUnicode.cpp,v
retrieving revision 1.27.2.1
retrieving revision 1.27.2.2
diff -C2 -d -r1.27.2.1 -r1.27.2.2
*** PyUnicode.cpp 29 Aug 2008 04:59:25 -0000 1.27.2.1
--- PyUnicode.cpp 1 Oct 2008 12:53:00 -0000 1.27.2.2
***************
*** 81,85 ****
/* Implement our Windows Unicode API using the Python widestring object */
! PyObject *PyUnicodeObject_FromString(const char *string)
{
if (string==NULL) {
--- 81,85 ----
/* Implement our Windows Unicode API using the Python widestring object */
! PyObject *PyUnicodeObject_FromString(const char *string, Py_ssize_t len /* = -1 */)
{
if (string==NULL) {
***************
*** 87,91 ****
return Py_None;
}
! return (PyObject *)PyUnicode_DecodeMBCS(string, strlen(string), NULL);
}
--- 87,93 ----
return Py_None;
}
! if (len==(Py_ssize_t)-1)
! len = strlen(string);
! return (PyObject *)PyUnicode_DecodeMBCS(string, len, NULL);
}
***************
*** 227,252 ****
}
- PyObject *PyString_FromUnicode( const OLECHAR *str )
- {
- if (str==NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- PyObject *uo = PyWinObject_FromOLECHAR(str);
- if (uo==NULL) return NULL;
- PyObject *ret = PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(uo), PyUnicode_GET_SIZE(uo), NULL);
- Py_DECREF(uo);
- return ret;
- }
-
- int PyUnicode_Size(PyObject *op)
- {
- if (!PyUnicode_Check(op)) {
- PyErr_BadInternalCall();
- return -1;
- }
- return PyUnicode_GET_SIZE(op);
- }
-
PyObject *PyWinObject_FromBstr(const BSTR bstr, BOOL takeOwnership /*=FALSE*/)
{
--- 229,232 ----
***************
*** 383,387 ****
else if (PyUnicode_Check(stringObject))
{
! resultLen = PyUnicode_Size(stringObject);
size_t cb = sizeof(WCHAR) * (resultLen+1);
*pResult = (WCHAR *)PyMem_Malloc(cb);
--- 363,367 ----
else if (PyUnicode_Check(stringObject))
{
! resultLen = PyUnicode_GET_SIZE(stringObject);
size_t cb = sizeof(WCHAR) * (resultLen+1);
*pResult = (WCHAR *)PyMem_Malloc(cb);
|