Update of /cvsroot/pywin32/pywin32/com/win32com/src/extensions
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv13555/extensions
Modified Files:
PySTGMEDIUM.cpp
Log Message:
Special handling for unicode so Py3k can pass unicode objects as a
HGLOBAL in a STGMEDIUM.
Index: PySTGMEDIUM.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/extensions/PySTGMEDIUM.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** PySTGMEDIUM.cpp 3 Jun 2007 09:40:56 -0000 1.8
--- PySTGMEDIUM.cpp 26 Nov 2008 01:19:25 -0000 1.9
***************
*** 55,69 ****
const void * buf = NULL;
Py_ssize_t cb = 0;
! if (PyObject_AsReadBuffer(ob,&buf,&cb)==-1)
! return PyErr_Format(PyExc_TypeError, "tymed value of %d requires a string/unicode/buffer", tymed);
! // size doesnt include nulls!
// We need to include the NULL for strings and unicode, as the
// Windows clipboard functions will assume it is there for
// text related formats (eg, CF_TEXT).
! if (PyString_Check(ob))
! cb += 1;
! else if (PyUnicode_Check(ob))
! cb += sizeof(wchar_t);
! // else assume buffer needs no terminator...
ps->medium.hGlobal = GlobalAlloc(GMEM_FIXED, cb);
if (!ps->medium.hGlobal)
--- 55,74 ----
const void * buf = NULL;
Py_ssize_t cb = 0;
! // In py3k, unicode objects don't support the buffer
! // protocol, so explicitly check string types first.
// We need to include the NULL for strings and unicode, as the
// Windows clipboard functions will assume it is there for
// text related formats (eg, CF_TEXT).
! if (PyString_Check(ob)) {
! cb = PyString_GET_SIZE(ob) + 1; // for the NULL
! buf = (void *)PyString_AS_STRING(ob);
! } else if (PyUnicode_Check(ob)) {
! cb = PyUnicode_GET_DATA_SIZE(ob) + sizeof(Py_UNICODE);
! buf = (void *)PyUnicode_AS_UNICODE(ob);
! } else {
! if (PyObject_AsReadBuffer(ob,&buf,&cb)==-1)
! return PyErr_Format(PyExc_TypeError, "tymed value of %d requires a string/unicode/buffer", tymed);
! // no extra nulls etc needed here.
! }
ps->medium.hGlobal = GlobalAlloc(GMEM_FIXED, cb);
if (!ps->medium.hGlobal)
|