summaryrefslogtreecommitdiffstats
path: root/PC/_msi.c
diff options
context:
space:
mode:
Diffstat (limited to 'PC/_msi.c')
-rw-r--r--PC/_msi.c92
1 files changed, 55 insertions, 37 deletions
diff --git a/PC/_msi.c b/PC/_msi.c
index 574ddde..d4d8483 100644
--- a/PC/_msi.c
+++ b/PC/_msi.c
@@ -1,5 +1,5 @@
/* Helper library for MSI creation with Python.
- * Copyright (C) 2005 Martin v. Löwis
+ * Copyright (C) 2005 Martin v. Löwis
* Licensed to PSF under a contributor agreement.
*/
@@ -18,7 +18,7 @@ static PyObject*
uuidcreate(PyObject* obj, PyObject*args)
{
UUID result;
- char *cresult;
+ unsigned short *cresult;
PyObject *oresult;
/* May return ok, local only, and no address.
@@ -30,13 +30,13 @@ uuidcreate(PyObject* obj, PyObject*args)
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");
return NULL;
}
- oresult = PyString_FromString(cresult);
- RpcStringFree(&cresult);
+ oresult = PyUnicode_FromUnicode(cresult, wcslen(cresult));
+ RpcStringFreeW(&cresult);
return oresult;
}
@@ -136,14 +136,14 @@ static FNFCIGETNEXTCABINET(cb_getnextcabinet)
PyObject *result = PyObject_CallMethod(pv, "getnextcabinet", "i", pccab->iCab);
if (result == NULL)
return -1;
- if (!PyString_Check(result)) {
+ if (!PyBytes_Check(result)) {
PyErr_Format(PyExc_TypeError,
"Incorrect return type %s from getnextcabinet",
result->ob_type->tp_name);
Py_DECREF(result);
return FALSE;
}
- strncpy(pccab->szCab, PyString_AsString(result), sizeof(pccab->szCab));
+ strncpy(pccab->szCab, PyBytes_AsString(result), sizeof(pccab->szCab));
return TRUE;
}
return FALSE;
@@ -335,7 +335,7 @@ msierror(int status)
static PyObject*
record_getfieldcount(msiobj* record, PyObject* args)
{
- return PyInt_FromLong(MsiRecordGetFieldCount(record->h));
+ return PyLong_FromLong(MsiRecordGetFieldCount(record->h));
}
static PyObject*
@@ -351,7 +351,7 @@ record_getinteger(msiobj* record, PyObject* args)
PyErr_SetString(MSIError, "could not convert record field to integer");
return NULL;
}
- return PyInt_FromLong((long) status);
+ return PyLong_FromLong((long) status);
}
static PyObject*
@@ -359,23 +359,23 @@ record_getstring(msiobj* record, PyObject* args)
{
unsigned int field;
unsigned int status;
- char buf[2000];
- char *res = buf;
+ WCHAR buf[2000];
+ WCHAR *res = buf;
DWORD size = sizeof(buf);
PyObject* string;
if (!PyArg_ParseTuple(args, "I:GetString", &field))
return NULL;
- status = MsiRecordGetString(record->h, field, res, &size);
+ status = MsiRecordGetStringW(record->h, field, res, &size);
if (status == ERROR_MORE_DATA) {
- res = (char*) malloc(size + 1);
+ res = (WCHAR*) malloc((size + 1)*sizeof(WCHAR));
if (res == NULL)
return PyErr_NoMemory();
- status = MsiRecordGetString(record->h, field, res, &size);
+ status = MsiRecordGetStringW(record->h, field, res, &size);
}
if (status != ERROR_SUCCESS)
return msierror((int) status);
- string = PyString_FromString(res);
+ string = PyUnicode_FromUnicode(res, size);
if (buf != res)
free(res);
return string;
@@ -397,12 +397,12 @@ record_setstring(msiobj* record, PyObject *args)
{
int status;
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;
- if ((status = MsiRecordSetString(record->h, field, data)) != ERROR_SUCCESS)
+ if ((status = MsiRecordSetStringW(record->h, field, data)) != ERROR_SUCCESS)
return msierror(status);
Py_INCREF(Py_None);
@@ -414,12 +414,12 @@ record_setstream(msiobj* record, PyObject *args)
{
int status;
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;
- if ((status = MsiRecordSetStream(record->h, field, data)) != ERROR_SUCCESS)
+ if ((status = MsiRecordSetStreamW(record->h, field, data)) != ERROR_SUCCESS)
return msierror(status);
Py_INCREF(Py_None);
@@ -473,7 +473,7 @@ static PyTypeObject record_Type = {
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- 0, /*tp_compare*/
+ 0, /*tp_reserved*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
@@ -549,12 +549,12 @@ summary_getproperty(msiobj* si, PyObject *args)
switch(type) {
case VT_I2: case VT_I4:
- return PyInt_FromLong(ival);
+ return PyLong_FromLong(ival);
case VT_FILETIME:
PyErr_SetString(PyExc_NotImplementedError, "FILETIME result");
return NULL;
case VT_LPSTR:
- result = PyString_FromStringAndSize(sval, ssize);
+ result = PyBytes_FromStringAndSize(sval, ssize);
if (sval != sbuf)
free(sval);
return result;
@@ -573,7 +573,7 @@ summary_getpropertycount(msiobj* si, PyObject *args)
if (status != ERROR_SUCCESS)
return msierror(status);
- return PyInt_FromLong(result);
+ return PyLong_FromLong(result);
}
static PyObject*
@@ -586,12 +586,16 @@ summary_setproperty(msiobj* si, PyObject *args)
if (!PyArg_ParseTuple(args, "iO:SetProperty", &field, &data))
return NULL;
- if (PyString_Check(data)) {
- status = MsiSummaryInfoSetProperty(si->h, field, VT_LPSTR,
- 0, NULL, PyString_AsString(data));
- } else if (PyInt_Check(data)) {
+ if (PyUnicode_Check(data)) {
+ status = MsiSummaryInfoSetPropertyW(si->h, field, VT_LPSTR,
+ 0, NULL, PyUnicode_AsUnicode(data));
+ } else if (PyLong_CheckExact(data)) {
+ long value = PyLong_AsLong(data);
+ if (value == -1 && PyErr_Occurred()) {
+ return NULL;
+ }
status = MsiSummaryInfoSetProperty(si->h, field, VT_I4,
- PyInt_AsLong(data), NULL, NULL);
+ value, NULL, NULL);
} else {
PyErr_SetString(PyExc_TypeError, "unsupported type");
return NULL;
@@ -639,7 +643,7 @@ static PyTypeObject summary_Type = {
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- 0, /*tp_compare*/
+ 0, /*tp_reserved*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
@@ -787,7 +791,7 @@ static PyTypeObject msiview_Type = {
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- 0, /*tp_compare*/
+ 0, /*tp_reserved*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
@@ -904,7 +908,7 @@ static PyTypeObject msidb_Type = {
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- 0, /*tp_compare*/
+ 0, /*tp_reserved*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
@@ -993,14 +997,27 @@ static PyMethodDef msi_methods[] = {
static char msi_doc[] = "Documentation";
+
+static struct PyModuleDef _msimodule = {
+ PyModuleDef_HEAD_INIT,
+ "_msi",
+ msi_doc,
+ -1,
+ msi_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
PyMODINIT_FUNC
-init_msi(void)
+PyInit__msi(void)
{
PyObject *m;
- m = Py_InitModule3("_msi", msi_methods, msi_doc);
+ m = PyModule_Create(&_msimodule);
if (m == NULL)
- return;
+ return NULL;
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATEDIRECT", (int)MSIDBOPEN_CREATEDIRECT);
PyModule_AddIntConstant(m, "MSIDBOPEN_CREATE", (int)MSIDBOPEN_CREATE);
@@ -1046,6 +1063,7 @@ init_msi(void)
MSIError = PyErr_NewException ("_msi.MSIError", NULL, NULL);
if (!MSIError)
- return;
+ return NULL;
PyModule_AddObject(m, "MSIError", MSIError);
+ return m;
}