[pywin32-checkins] pywin32/com/win32com/src/extensions PySTGMEDIUM.cpp,1.3,1.4
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2004-04-26 00:18:14
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src/extensions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32762/extensions Modified Files: PySTGMEDIUM.cpp Log Message: Bite the bullet - do the buffer/unicode thing now. If nothing else, it makes the tests seem more complete Index: PySTGMEDIUM.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/extensions/PySTGMEDIUM.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PySTGMEDIUM.cpp 25 Apr 2004 23:58:38 -0000 1.3 --- PySTGMEDIUM.cpp 26 Apr 2004 00:17:58 -0000 1.4 *************** *** 47,64 **** break; case TYMED_HGLOBAL: { ! // todo: support buffer (but see byte-count discussion below) ! if (!PyString_Check(ob)) ! return PyErr_Format(PyExc_TypeError, "tymed value of %d requires a string", tymed); ! // We need to include the NULL, as the Windows clipboard functions ! // will assume it is there for text related formats (eg, CF_TEXT). ! // I can't see one extra byte could cause any problems - but if ! // in the future it does, we can take the win32clipboard route, ! // and only include the extra \0 for strings, allowing buffers to ! // use the exact cb. ! int cb = PyString_Size(ob)+1; ps->medium.hGlobal = GlobalAlloc(GMEM_FIXED, cb); if (!ps->medium.hGlobal) return PyErr_NoMemory(); ! memcpy( (void *)ps->medium.hGlobal, PyString_AsString(ob), cb); break; } --- 47,67 ---- break; case TYMED_HGLOBAL: { ! const void * buf = NULL; ! int 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) return PyErr_NoMemory(); ! memcpy( (void *)ps->medium.hGlobal, buf, cb); break; } |