Bug #3542: Support Unicode strings in _msi module.
This commit is contained in:
parent
9abf93d6c9
commit
371bb50b87
|
@ -49,6 +49,11 @@ Library
|
||||||
- Issue #2523: Fix quadratic behaviour when read()ing a binary file without
|
- Issue #2523: Fix quadratic behaviour when read()ing a binary file without
|
||||||
asking for a specific length.
|
asking for a specific length.
|
||||||
|
|
||||||
|
Extension Modules
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
- Bug #3542: Support Unicode strings in _msi module.
|
||||||
|
|
||||||
What's new in Python 3.0b2?
|
What's new in Python 3.0b2?
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
|
38
PC/_msi.c
38
PC/_msi.c
|
@ -18,7 +18,7 @@ static PyObject*
|
||||||
uuidcreate(PyObject* obj, PyObject*args)
|
uuidcreate(PyObject* obj, PyObject*args)
|
||||||
{
|
{
|
||||||
UUID result;
|
UUID result;
|
||||||
char *cresult;
|
RPC_WSTR cresult;
|
||||||
PyObject *oresult;
|
PyObject *oresult;
|
||||||
|
|
||||||
/* May return ok, local only, and no address.
|
/* May return ok, local only, and no address.
|
||||||
|
@ -30,13 +30,13 @@ uuidcreate(PyObject* obj, PyObject*args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UuidToString(&result, &cresult) == RPC_S_OUT_OF_MEMORY) {
|
if (UuidToStringW(&result, &cresult) == RPC_S_OUT_OF_MEMORY) {
|
||||||
PyErr_SetString(PyExc_MemoryError, "out of memory in uuidgen");
|
PyErr_SetString(PyExc_MemoryError, "out of memory in uuidgen");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
oresult = PyBytes_FromString(cresult);
|
oresult = PyUnicode_FromUnicode(cresult, wcslen(cresult));
|
||||||
RpcStringFree(&cresult);
|
RpcStringFreeW(&cresult);
|
||||||
return oresult;
|
return oresult;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -359,23 +359,23 @@ record_getstring(msiobj* record, PyObject* args)
|
||||||
{
|
{
|
||||||
unsigned int field;
|
unsigned int field;
|
||||||
unsigned int status;
|
unsigned int status;
|
||||||
char buf[2000];
|
WCHAR buf[2000];
|
||||||
char *res = buf;
|
WCHAR *res = buf;
|
||||||
DWORD size = sizeof(buf);
|
DWORD size = sizeof(buf);
|
||||||
PyObject* string;
|
PyObject* string;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "I:GetString", &field))
|
if (!PyArg_ParseTuple(args, "I:GetString", &field))
|
||||||
return NULL;
|
return NULL;
|
||||||
status = MsiRecordGetString(record->h, field, res, &size);
|
status = MsiRecordGetStringW(record->h, field, res, &size);
|
||||||
if (status == ERROR_MORE_DATA) {
|
if (status == ERROR_MORE_DATA) {
|
||||||
res = (char*) malloc(size + 1);
|
res = (WCHAR*) malloc((size + 1)*sizeof(WCHAR));
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
status = MsiRecordGetString(record->h, field, res, &size);
|
status = MsiRecordGetStringW(record->h, field, res, &size);
|
||||||
}
|
}
|
||||||
if (status != ERROR_SUCCESS)
|
if (status != ERROR_SUCCESS)
|
||||||
return msierror((int) status);
|
return msierror((int) status);
|
||||||
string = PyUnicode_FromString(res);
|
string = PyUnicode_FromUnicode(res, size);
|
||||||
if (buf != res)
|
if (buf != res)
|
||||||
free(res);
|
free(res);
|
||||||
return string;
|
return string;
|
||||||
|
@ -397,12 +397,12 @@ record_setstring(msiobj* record, PyObject *args)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
int field;
|
int field;
|
||||||
char *data;
|
Py_UNICODE *data;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "is:SetString", &field, &data))
|
if (!PyArg_ParseTuple(args, "iu:SetString", &field, &data))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((status = MsiRecordSetString(record->h, field, data)) != ERROR_SUCCESS)
|
if ((status = MsiRecordSetStringW(record->h, field, data)) != ERROR_SUCCESS)
|
||||||
return msierror(status);
|
return msierror(status);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
|
@ -414,12 +414,12 @@ record_setstream(msiobj* record, PyObject *args)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
int field;
|
int field;
|
||||||
char *data;
|
Py_UNICODE *data;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "is:SetStream", &field, &data))
|
if (!PyArg_ParseTuple(args, "iu:SetStream", &field, &data))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((status = MsiRecordSetStream(record->h, field, data)) != ERROR_SUCCESS)
|
if ((status = MsiRecordSetStreamW(record->h, field, data)) != ERROR_SUCCESS)
|
||||||
return msierror(status);
|
return msierror(status);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
|
@ -586,9 +586,9 @@ summary_setproperty(msiobj* si, PyObject *args)
|
||||||
if (!PyArg_ParseTuple(args, "iO:SetProperty", &field, &data))
|
if (!PyArg_ParseTuple(args, "iO:SetProperty", &field, &data))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (PyBytes_Check(data)) {
|
if (PyUnicode_Check(data)) {
|
||||||
status = MsiSummaryInfoSetProperty(si->h, field, VT_LPSTR,
|
status = MsiSummaryInfoSetPropertyW(si->h, field, VT_LPSTR,
|
||||||
0, NULL, PyBytes_AsString(data));
|
0, NULL, PyUnicode_AsUnicode(data));
|
||||||
} else if (PyLong_CheckExact(data)) {
|
} else if (PyLong_CheckExact(data)) {
|
||||||
long value = PyLong_AsLong(data);
|
long value = PyLong_AsLong(data);
|
||||||
if (value == -1 && PyErr_Occurred()) {
|
if (value == -1 && PyErr_Occurred()) {
|
||||||
|
|
Loading…
Reference in New Issue