Skip to content

Commit 13ac4bd

Browse files
committed
Replace PYWIN_ATTR_CONVERT with PyUnicode_AsUTF8
1 parent c18be83 commit 13ac4bd

27 files changed

+64
-69
lines changed

Pythonwin/win32cmdui.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ BOOL Python_OnCmdMsg(CCmdTarget *obj, UINT nID, int nCode, void *pExtra, AFX_CMD
8282
pObj->pOleEventHookList->Lookup((unsigned short)pEvent->m_dispid, (void *&)method)) {
8383
if (pfnMakeOlePythonCall == NULL) {
8484
pfnMakeOlePythonCall =
85-
(BOOL(*)(PyObject *, DISPPARAMS FAR *, VARIANT FAR *, EXCEPINFO FAR *, UINT FAR *,
86-
PyObject *))GetPythonOleProcAddress("PyCom_MakeOlePythonCall");
85+
(BOOL (*)(PyObject *, DISPPARAMS FAR *, VARIANT FAR *, EXCEPINFO FAR *, UINT FAR *,
86+
PyObject *))GetPythonOleProcAddress("PyCom_MakeOlePythonCall");
8787

8888
ASSERT(pfnMakeOlePythonCall);
8989
}
@@ -282,7 +282,7 @@ static struct PyMethodDef PyCCmdUI_methods[] = {
282282

283283
PyObject *PyCCmdUI::getattro(PyObject *obname)
284284
{
285-
char *name = PYWIN_ATTR_CONVERT(obname);
285+
const char *name = PyUnicode_AsUTF8(obname);
286286
if (strcmp(name, "m_nIndex") == 0) { // @prop int|m_nIndex|
287287
CCmdUI *pCU = PyCCmdUI::GetCCmdUIPtr(this);
288288
if (!pCU)

Pythonwin/win32dlg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ PyCDialog::~PyCDialog()
171171

172172
PyObject *PyCDialog::getattro(PyObject *obname)
173173
{
174-
char *name = PYWIN_ATTR_CONVERT(obname);
174+
const char *name = PyUnicode_AsUTF8(obname);
175175
if (strcmp(name, "data") == 0) {
176176
Py_INCREF(dddict);
177177
return dddict;

Pythonwin/win32toolbar.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct MyMemberList dcmembers[] = {
164164

165165
PyObject *PyCDockContext::getattro(PyObject *obname)
166166
{
167-
char *name = PYWIN_ATTR_CONVERT(obname);
167+
const char *name = PyUnicode_AsUTF8(obname);
168168
if (name == NULL)
169169
return NULL;
170170
CDockContext *pC = GetDockContext(this);
@@ -200,7 +200,7 @@ PyObject *PyCDockContext::getattro(PyObject *obname)
200200

201201
int PyCDockContext::setattro(PyObject *obname, PyObject *value)
202202
{
203-
char *name = PYWIN_ATTR_CONVERT(obname);
203+
const char *name = PyUnicode_AsUTF8(obname);
204204
if (name == NULL)
205205
return -1;
206206
CDockContext *pC = GetDockContext(this);
@@ -446,7 +446,7 @@ static struct PyMethodDef PyCControlBar_methods[] = {
446446

447447
PyObject *PyCControlBar::getattro(PyObject *obname)
448448
{
449-
char *name = PYWIN_ATTR_CONVERT(obname);
449+
const char *name = PyUnicode_AsUTF8(obname);
450450
if (name == NULL)
451451
return NULL;
452452
CControlBar *pCtlBar = PyCControlBar::GetControlBar(this);
@@ -477,7 +477,7 @@ PyObject *PyCControlBar::getattro(PyObject *obname)
477477

478478
int PyCControlBar::setattro(PyObject *obname, PyObject *v)
479479
{
480-
char *name = PYWIN_ATTR_CONVERT(obname);
480+
const char *name = PyUnicode_AsUTF8(obname);
481481
if (name == NULL)
482482
return -1;
483483

Pythonwin/win32util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static PySequenceMethods PyCRect_Sequence = {
9292

9393
PyObject *PyCRect::getattro(PyObject *obname)
9494
{
95-
char *name = PYWIN_ATTR_CONVERT(obname);
95+
const char *name = PyUnicode_AsUTF8(obname);
9696
if (name == NULL)
9797
return NULL;
9898
if (strcmp(name, "left") == 0)
@@ -140,7 +140,7 @@ CString PyCRect::repr()
140140

141141
int PyCRect::setattro(PyObject *obname, PyObject *v)
142142
{
143-
char *name = PYWIN_ATTR_CONVERT(obname);
143+
const char *name = PyUnicode_AsUTF8(obname);
144144
if (name == NULL)
145145
return -1;
146146
int intval = PyLong_AsLong(v);

com/win32com/src/PyIBase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ PyObject *PyIBase::getattr(char *name) { return PyObject_GetAttrString(this, nam
3232

3333
/*static*/ int PyIBase::setattro(PyObject *op, PyObject *obname, PyObject *v)
3434
{
35-
char *name = PYWIN_ATTR_CONVERT(obname);
35+
const char *name = PyUnicode_AsUTF8(obname);
3636
if (name == NULL)
3737
return -1;
3838
PyIBase *bc = (PyIBase *)op;
3939
return bc->setattr(name, v);
4040
}
4141

42-
int PyIBase::setattr(char *name, PyObject *v)
42+
int PyIBase::setattr(const char *name, PyObject *v)
4343
{
4444
char buf[128];
4545
sprintf(buf, "%s has read-only attributes", ob_type->tp_name);

com/win32com/src/PyRecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ PyObject *PyRecord::getattro(PyObject *self, PyObject *obname)
590590
PyRecord *pyrec = (PyRecord *)self;
591591
GUID structguid;
592592
OLECHAR *guidString;
593-
char *name = PYWIN_ATTR_CONVERT(obname);
593+
const char *name = PyUnicode_AsUTF8(obname);
594594
if (name == NULL)
595595
return NULL;
596596
if (strcmp(name, "__record_type_guid__") == 0) {

com/win32com/src/extensions/PySTGMEDIUM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void PySTGMEDIUM::Close()
230230

231231
PyObject *PySTGMEDIUM::getattro(PyObject *self, PyObject *obname)
232232
{
233-
char *name = PYWIN_ATTR_CONVERT(obname);
233+
const char *name = PyUnicode_AsUTF8(obname);
234234
if (name == NULL)
235235
return NULL;
236236

com/win32com/src/include/PythonCOM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class PYCOM_EXPORT PyIBase : public PyObject {
168168
public:
169169
// virtuals for Python support
170170
virtual PyObject *getattr(char *name);
171-
virtual int setattr(char *name, PyObject *v);
171+
virtual int setattr(const char *name, PyObject *v);
172172
virtual PyObject *repr();
173173
virtual int compare(PyObject *other)
174174
{

com/win32comext/adsi/src/PyADSIUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class PyADS_ATTR_INFO : public PyObject {
449449

450450
static PyObject *getattro(PyObject *self, PyObject *obname)
451451
{
452-
char *name = PYWIN_ATTR_CONVERT(obname);
452+
const char *name = PyUnicode_AsUTF8(obname);
453453
if (name == NULL)
454454
return NULL;
455455
if (strcmp(name, "__members__") == 0) {

com/win32comext/directsound/src/PyDSBUFFERDESC.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ PyTypeObject PyDSBUFFERDESCType = {
103103
// IDirectSound::CreateSoundBuffer call. With this flag set, an application using DirectSound can continue to play
104104
// its sticky focus buffers if the user switches to another application not using DirectSound. In this situation,
105105
// the application's normal buffers are muted, but the sticky focus buffers are still audible. This is useful for
106-
// nongame applications, such as movie playback (DirectShow), when the user wants to hear the soundtrack while
107-
// typing in Microsoft Word or Microsoft® Excel, for example. However, if the user switches to another DirectSound
106+
// nongame applications, such as movie playback (DirectShow), when the user wants to hear the soundtrack while
107+
// typing in Microsoft Word or Microsoft Excel, for example. However, if the user switches to another DirectSound
108108
// application, all sound buffers, both normal and sticky focus, in the previous application are muted.
109109
// @flag DSBCAPS_GLOBALFOCUS|The buffer is a global sound buffer. With this flag set, an application using
110110
// DirectSound can continue to play its buffers if the user switches focus to another application, even if the new
@@ -167,7 +167,7 @@ PyDSBUFFERDESC::~PyDSBUFFERDESC() { Py_XDECREF(m_obWFX); }
167167
int PyDSBUFFERDESC::setattro(PyObject *self, PyObject *obname, PyObject *obvalue)
168168
{
169169
PyDSBUFFERDESC *obself = (PyDSBUFFERDESC *)self;
170-
char *name = PYWIN_ATTR_CONVERT(obname);
170+
const char *name = PyUnicode_AsUTF8(obname);
171171
if (name == NULL)
172172
return -1;
173173

com/win32comext/directsound/src/PyDSCBUFFERDESC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ PyDSCBUFFERDESC::~PyDSCBUFFERDESC() { Py_XDECREF(m_obWFX); }
135135
int PyDSCBUFFERDESC::setattro(PyObject *self, PyObject *obname, PyObject *obvalue)
136136
{
137137
PyDSCBUFFERDESC *obself = (PyDSCBUFFERDESC *)self;
138-
char *name = PYWIN_ATTR_CONVERT(obname);
138+
const char *name = PyUnicode_AsUTF8(obname);
139139

140140
if (name == NULL)
141141
return -1;

win32/src/PyOVERLAPPED.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ PYWINTYPES_EXPORT PyTypeObject PyOVERLAPPEDType = {
110110
{"Offset", T_ULONG,
111111
OFF(m_overlapped.Offset)}, // @prop integer|Offset|Specifies a file position at which to start the transfer. The
112112
// file position is a byte offset from the start of the file. The calling process sets
113-
// this member before calling the ReadFile or WriteFile function. This member is
113+
// this member before calling the ReadFileor WriteFile function. This member is
114114
// ignored when reading from or writing to named pipes and communications devices.
115115
{"OffsetHigh", T_ULONG, OFF(m_overlapped.OffsetHigh)}, // @prop integer|OffsetHigh|Specifies the high word of the
116116
// byte offset at which to start the transfer.
@@ -123,7 +123,7 @@ PYWINTYPES_EXPORT PyTypeObject PyOVERLAPPEDType = {
123123
{"hEvent", T_OBJECT, OFF(obDummy)}, // @prop <o PyHANDLE>|hEvent|Identifies an event set to the signaled state when
124124
// the transfer has been completed. The calling process sets this member before
125125
// calling the <om win32file.ReadFile>, <om win32file.WriteFile>, <om
126-
// win32pipe.ConnectNamedPipe>, or <om win32pipe.TransactNamedPipe> function.
126+
// win32pipe.ConnectNamedPipe>, or <om win32pipe.TransactNamedPipe>function.
127127
{"Internal", T_OBJECT,
128128
OFF(obDummy)}, // @prop integer|Internal|Reserved for operating system use. (pointer-sized value)
129129
{"InternalHigh", T_OBJECT,
@@ -182,7 +182,7 @@ PyObject *PyOVERLAPPED::richcompareFunc(PyObject *ob, PyObject *other, int op)
182182

183183
PyObject *PyOVERLAPPED::getattro(PyObject *self, PyObject *obname)
184184
{
185-
char *name = PYWIN_ATTR_CONVERT(obname);
185+
const char *name = PyUnicode_AsUTF8(obname);
186186
if (name == NULL)
187187
return NULL;
188188
if (strcmp("hEvent", name) == 0) {
@@ -210,7 +210,7 @@ int PyOVERLAPPED::setattro(PyObject *self, PyObject *obname, PyObject *v)
210210
PyErr_SetString(PyExc_AttributeError, "can't delete OVERLAPPED attributes");
211211
return -1;
212212
}
213-
char *name = PYWIN_ATTR_CONVERT(obname);
213+
const char *name = PyUnicode_AsUTF8(obname);
214214
if (name == NULL)
215215
return NULL;
216216
if (strcmp("hEvent", name) == 0) {

win32/src/PySECURITY_ATTRIBUTES.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ int PySECURITY_ATTRIBUTES::setattro(PyObject *self, PyObject *obname, PyObject *
157157
PyErr_SetString(PyExc_AttributeError, "can't delete SECURITY_ATTRIBUTES attributes");
158158
return -1;
159159
}
160-
char *name = PYWIN_ATTR_CONVERT(obname);
160+
const char *name = PyUnicode_AsUTF8(obname);
161161
if (name == NULL)
162162
return -1;
163163
if (strcmp(name, "SECURITY_DESCRIPTOR") == 0) {

win32/src/PyWinTypes.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
// Macro to handle PyObject layout changes in Py3k
5353
#define PYWIN_OBJECT_HEAD PyVarObject_HEAD_INIT(NULL, 0)
5454

55-
// This macro is kept for legacy reason as it's casting from `const char *` to `char *`
56-
#define PYWIN_ATTR_CONVERT (char *)PyUnicode_AsUTF8
57-
5855
typedef Py_ssize_t Py_hash_t;
5956

6057
// This only enables runtime checks in debug builds - so we use

win32/src/win32api_display.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ PyObject *PyDISPLAY_DEVICE::Clear(PyObject *self, PyObject *args)
125125
PyObject *PyDISPLAY_DEVICE::getattro(PyObject *self, PyObject *obname)
126126
{
127127
PDISPLAY_DEVICE pdisplay_device = &((PyDISPLAY_DEVICE *)self)->display_device;
128-
char *name = PYWIN_ATTR_CONVERT(obname);
128+
const char *name = PyUnicode_AsUTF8(obname);
129129
if (name == NULL)
130130
return NULL;
131131

@@ -162,7 +162,7 @@ PyObject *PyDISPLAY_DEVICE::getattro(PyObject *self, PyObject *obname)
162162

163163
int PyDISPLAY_DEVICE::setattro(PyObject *self, PyObject *obname, PyObject *obvalue)
164164
{
165-
char *name = PYWIN_ATTR_CONVERT(obname);
165+
const char *name = PyUnicode_AsUTF8(obname);
166166
if (name == NULL)
167167
return -1;
168168

win32/src/win32consolemodule.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ struct PyMemberDef PyINPUT_RECORD::members[] = {
466466
PyObject *PyINPUT_RECORD::tp_getattro(PyObject *self, PyObject *obname)
467467
{
468468
INPUT_RECORD *pir = &((PyINPUT_RECORD *)self)->input_record;
469-
char *name = PYWIN_ATTR_CONVERT(obname);
469+
const char *name = PyUnicode_AsUTF8(obname);
470470
if (name == NULL)
471471
return NULL;
472472
if (strcmp(name, "ControlKeyState") == 0) {
@@ -514,8 +514,7 @@ PyObject *PyINPUT_RECORD::tp_getattro(PyObject *self, PyObject *obname)
514514
int PyINPUT_RECORD::tp_setattro(PyObject *self, PyObject *obname, PyObject *obvalue)
515515
{
516516
INPUT_RECORD *pir = &((PyINPUT_RECORD *)self)->input_record;
517-
char *name;
518-
name = PYWIN_ATTR_CONVERT(obname);
517+
const char *name = PyUnicode_AsUTF8(obname);
519518
if (name == NULL)
520519
return -1;
521520
if (obvalue == NULL) {

win32/src/win32crypt/PyCERT_CONTEXT.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ PyObject *PyWinObject_FromCERT_EXTENSIONArray(PCERT_EXTENSION pce, DWORD ext_cnt
141141

142142
PyObject *PyCERT_CONTEXT::getattro(PyObject *self, PyObject *obname)
143143
{
144-
char *name = PYWIN_ATTR_CONVERT(obname);
144+
const char *name = PyUnicode_AsUTF8(obname);
145145
if (name == NULL)
146146
return NULL;
147147
PCCERT_CONTEXT pcc = ((PyCERT_CONTEXT *)self)->GetPCCERT_CONTEXT();

win32/src/win32crypt/PyCRYPTKEY.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int PyCRYPTKEY::setattro(PyObject *self, PyObject *obname, PyObject *v)
6262
PyObject *PyCRYPTKEY::getattro(PyObject *self, PyObject *obname)
6363
{
6464
/*
65-
char *name=PYWIN_ATTR_CONVERT(obname);
65+
const char *name = PyUnicode_AsUTF8(obname);
6666
if (name==NULL)
6767
return NULL;
6868
if (strcmp(name,"HCRYPTKEY")==0){

win32/src/win32crypt/PyCRYPTMSG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int PyCRYPTMSG::setattro(PyObject *self, PyObject *obname, PyObject *v)
5050
PyObject *PyCRYPTMSG::getattro(PyObject *self, PyObject *obname)
5151
{
5252
/*
53-
char *name=PYWIN_ATTR_CONVERT(obname);
53+
const char *name = PyUnicode_AsUTF8(obname);
5454
if (name==NULL)
5555
return NULL;
5656
if (strcmp(name,"HCRYPTMSG")==0){

win32/src/win32file_comm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ PyDCB::~PyDCB(void) {}
171171
PyObject *PyDCB::getattro(PyObject *self, PyObject *obname)
172172
{
173173
PyDCB *pydcb = (PyDCB *)self;
174-
char *name = PYWIN_ATTR_CONVERT(obname);
174+
const char *name = PyUnicode_AsUTF8(obname);
175175
if (!name)
176176
return NULL;
177177

@@ -212,7 +212,7 @@ int PyDCB::setattro(PyObject *self, PyObject *obname, PyObject *v)
212212
PyErr_SetString(PyExc_AttributeError, "can't delete DCB attributes");
213213
return -1;
214214
}
215-
char *name = PYWIN_ATTR_CONVERT(obname);
215+
const char *name = PyUnicode_AsUTF8(obname);
216216
if (!name)
217217
return -1;
218218
SET_BITFIELD_ENTRY(fBinary)
@@ -373,7 +373,7 @@ PyCOMSTAT::~PyCOMSTAT(void) {}
373373
PyObject *PyCOMSTAT::getattro(PyObject *self, PyObject *obname)
374374
{
375375
PyCOMSTAT *pyCOMSTAT = (PyCOMSTAT *)self;
376-
char *name = PYWIN_ATTR_CONVERT(obname);
376+
const char *name = PyUnicode_AsUTF8(obname);
377377
if (!name)
378378
return NULL;
379379
if (0) // boot up our macro magic (the macro starts with an 'else')
@@ -408,7 +408,7 @@ int PyCOMSTAT::setattro(PyObject *self, PyObject *obname, PyObject *v)
408408
PyErr_SetString(PyExc_AttributeError, "can't delete COMSTAT attributes");
409409
return -1;
410410
}
411-
char *name = PYWIN_ATTR_CONVERT(obname);
411+
const char *name = PyUnicode_AsUTF8(obname);
412412
if (!name)
413413
return -1;
414414
SET_BITFIELD_ENTRY(fCtsHold)

win32/src/win32gui.i

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ PyWNDCLASS::~PyWNDCLASS(void)
921921

922922
PyObject *PyWNDCLASS::getattro(PyObject *self, PyObject *obname)
923923
{
924-
char *name=PYWIN_ATTR_CONVERT(obname);
924+
const char *name = PyUnicode_AsUTF8(obname);
925925
if (name==NULL)
926926
return NULL;
927927
PyWNDCLASS *pW = (PyWNDCLASS *)self;
@@ -976,7 +976,7 @@ int PyWNDCLASS::setattro(PyObject *self, PyObject *obname, PyObject *v)
976976
PyErr_SetString(PyExc_AttributeError, "can't delete WNDCLASS attributes");
977977
return -1;
978978
}
979-
char *name=PYWIN_ATTR_CONVERT(obname);
979+
const char *name = PyUnicode_AsUTF8(obname);
980980
if (name==NULL)
981981
return -1;
982982
PyWNDCLASS *pW = (PyWNDCLASS *)self;
@@ -1128,7 +1128,7 @@ PyBITMAP::~PyBITMAP(void)
11281128

11291129
PyObject *PyBITMAP::getattro(PyObject *self, PyObject *obname)
11301130
{
1131-
char *name=PYWIN_ATTR_CONVERT(obname);
1131+
const char *name = PyUnicode_AsUTF8(obname);
11321132
if (name==NULL)
11331133
return NULL;
11341134
PyBITMAP *pB = (PyBITMAP *)self;
@@ -1144,7 +1144,7 @@ int PyBITMAP::setattro(PyObject *self, PyObject *obname, PyObject *v)
11441144
PyErr_SetString(PyExc_AttributeError, "can't delete BITMAP attributes");
11451145
return -1;
11461146
}
1147-
char *name=PYWIN_ATTR_CONVERT(obname);
1147+
const char *name = PyUnicode_AsUTF8(obname);
11481148
if (name==NULL)
11491149
return -1;
11501150
if (strcmp("bmBits", name)==0) {
@@ -1268,7 +1268,7 @@ PyLOGFONT::~PyLOGFONT(void)
12681268

12691269
PyObject *PyLOGFONT::getattro(PyObject *self, PyObject *obname)
12701270
{
1271-
char *name=PYWIN_ATTR_CONVERT(obname);
1271+
const char *name = PyUnicode_AsUTF8(obname);
12721272
if (name==NULL)
12731273
return NULL;
12741274
PyLOGFONT *pL = (PyLOGFONT *)self;
@@ -1284,7 +1284,7 @@ int PyLOGFONT::setattro(PyObject *self, PyObject *obname, PyObject *v)
12841284
PyErr_SetString(PyExc_AttributeError, "can't delete LOGFONT attributes");
12851285
return -1;
12861286
}
1287-
char *name=PYWIN_ATTR_CONVERT(obname);
1287+
const char *name = PyUnicode_AsUTF8(obname);
12881288
if (name==NULL)
12891289
return -1;
12901290
if (strcmp("lfFaceName", name)==0) {

0 commit comments

Comments
 (0)