Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 371bb50

Browse files
committed
Bug #3542: Support Unicode strings in _msi module.
1 parent 9abf93d commit 371bb50

2 files changed

Lines changed: 24 additions & 19 deletions

File tree

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ Library
4949
- Issue #2523: Fix quadratic behaviour when read()ing a binary file without
5050
asking for a specific length.
5151

52+
Extension Modules
53+
-----------------
54+
55+
- Bug #3542: Support Unicode strings in _msi module.
56+
5257
What's new in Python 3.0b2?
5358
===========================
5459

PC/_msi.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static PyObject*
1818
uuidcreate(PyObject* obj, PyObject*args)
1919
{
2020
UUID result;
21-
char *cresult;
21+
RPC_WSTR cresult;
2222
PyObject *oresult;
2323

2424
/* May return ok, local only, and no address.
@@ -30,13 +30,13 @@ uuidcreate(PyObject* obj, PyObject*args)
3030
return NULL;
3131
}
3232

33-
if (UuidToString(&result, &cresult) == RPC_S_OUT_OF_MEMORY) {
33+
if (UuidToStringW(&result, &cresult) == RPC_S_OUT_OF_MEMORY) {
3434
PyErr_SetString(PyExc_MemoryError, "out of memory in uuidgen");
3535
return NULL;
3636
}
3737

38-
oresult = PyBytes_FromString(cresult);
39-
RpcStringFree(&cresult);
38+
oresult = PyUnicode_FromUnicode(cresult, wcslen(cresult));
39+
RpcStringFreeW(&cresult);
4040
return oresult;
4141

4242
}
@@ -359,23 +359,23 @@ record_getstring(msiobj* record, PyObject* args)
359359
{
360360
unsigned int field;
361361
unsigned int status;
362-
char buf[2000];
363-
char *res = buf;
362+
WCHAR buf[2000];
363+
WCHAR *res = buf;
364364
DWORD size = sizeof(buf);
365365
PyObject* string;
366366

367367
if (!PyArg_ParseTuple(args, "I:GetString", &field))
368368
return NULL;
369-
status = MsiRecordGetString(record->h, field, res, &size);
369+
status = MsiRecordGetStringW(record->h, field, res, &size);
370370
if (status == ERROR_MORE_DATA) {
371-
res = (char*) malloc(size + 1);
371+
res = (WCHAR*) malloc((size + 1)*sizeof(WCHAR));
372372
if (res == NULL)
373373
return PyErr_NoMemory();
374-
status = MsiRecordGetString(record->h, field, res, &size);
374+
status = MsiRecordGetStringW(record->h, field, res, &size);
375375
}
376376
if (status != ERROR_SUCCESS)
377377
return msierror((int) status);
378-
string = PyUnicode_FromString(res);
378+
string = PyUnicode_FromUnicode(res, size);
379379
if (buf != res)
380380
free(res);
381381
return string;
@@ -397,12 +397,12 @@ record_setstring(msiobj* record, PyObject *args)
397397
{
398398
int status;
399399
int field;
400-
char *data;
400+
Py_UNICODE *data;
401401

402-
if (!PyArg_ParseTuple(args, "is:SetString", &field, &data))
402+
if (!PyArg_ParseTuple(args, "iu:SetString", &field, &data))
403403
return NULL;
404404

405-
if ((status = MsiRecordSetString(record->h, field, data)) != ERROR_SUCCESS)
405+
if ((status = MsiRecordSetStringW(record->h, field, data)) != ERROR_SUCCESS)
406406
return msierror(status);
407407

408408
Py_INCREF(Py_None);
@@ -414,12 +414,12 @@ record_setstream(msiobj* record, PyObject *args)
414414
{
415415
int status;
416416
int field;
417-
char *data;
417+
Py_UNICODE *data;
418418

419-
if (!PyArg_ParseTuple(args, "is:SetStream", &field, &data))
419+
if (!PyArg_ParseTuple(args, "iu:SetStream", &field, &data))
420420
return NULL;
421421

422-
if ((status = MsiRecordSetStream(record->h, field, data)) != ERROR_SUCCESS)
422+
if ((status = MsiRecordSetStreamW(record->h, field, data)) != ERROR_SUCCESS)
423423
return msierror(status);
424424

425425
Py_INCREF(Py_None);
@@ -586,9 +586,9 @@ summary_setproperty(msiobj* si, PyObject *args)
586586
if (!PyArg_ParseTuple(args, "iO:SetProperty", &field, &data))
587587
return NULL;
588588

589-
if (PyBytes_Check(data)) {
590-
status = MsiSummaryInfoSetProperty(si->h, field, VT_LPSTR,
591-
0, NULL, PyBytes_AsString(data));
589+
if (PyUnicode_Check(data)) {
590+
status = MsiSummaryInfoSetPropertyW(si->h, field, VT_LPSTR,
591+
0, NULL, PyUnicode_AsUnicode(data));
592592
} else if (PyLong_CheckExact(data)) {
593593
long value = PyLong_AsLong(data);
594594
if (value == -1 && PyErr_Occurred()) {

0 commit comments

Comments
 (0)