~pythonregexp2.7/python/issue2636-22

« back to all changes in this revision

Viewing changes to PC/_msi.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:36:32 UTC
  • mfrom: (39021.1.402 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609143632-wwwkx92u1t5l7yd3
Merged in changes from the latest python source snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
339
339
}
340
340
 
341
341
static PyObject*
 
342
record_getinteger(msiobj* record, PyObject* args)
 
343
{
 
344
    unsigned int field;
 
345
    int status;
 
346
    
 
347
    if (!PyArg_ParseTuple(args, "I:GetInteger", &field))
 
348
        return NULL;
 
349
    status = MsiRecordGetInteger(record->h, field);
 
350
    if (status == MSI_NULL_INTEGER){
 
351
        PyErr_SetString(MSIError, "could not convert record field to integer");
 
352
        return NULL;
 
353
    }
 
354
    return PyInt_FromLong((long) status);
 
355
}
 
356
 
 
357
static PyObject*
 
358
record_getstring(msiobj* record, PyObject* args)
 
359
{
 
360
    unsigned int field;
 
361
    unsigned int status;
 
362
    char buf[2000];
 
363
    char *res = buf;
 
364
    DWORD size = sizeof(buf);
 
365
    PyObject* string;
 
366
    
 
367
    if (!PyArg_ParseTuple(args, "I:GetString", &field))
 
368
        return NULL;
 
369
    status = MsiRecordGetString(record->h, field, res, &size);
 
370
    if (status == ERROR_MORE_DATA) {
 
371
        res = (char*) malloc(size + 1);
 
372
        if (res == NULL)
 
373
            return PyErr_NoMemory();
 
374
        status = MsiRecordGetString(record->h, field, res, &size);
 
375
    }
 
376
    if (status != ERROR_SUCCESS)
 
377
        return msierror((int) status);
 
378
    string = PyString_FromString(res);
 
379
    if (buf != res)
 
380
        free(res);
 
381
    return string;
 
382
}
 
383
 
 
384
static PyObject*
342
385
record_cleardata(msiobj* record, PyObject *args)
343
386
{
344
387
    int status = MsiRecordClearData(record->h);
405
448
static PyMethodDef record_methods[] = {
406
449
    { "GetFieldCount", (PyCFunction)record_getfieldcount, METH_NOARGS, 
407
450
        PyDoc_STR("GetFieldCount() -> int\nWraps MsiRecordGetFieldCount")},
 
451
    { "GetInteger", (PyCFunction)record_getinteger, METH_VARARGS,
 
452
    PyDoc_STR("GetInteger(field) -> int\nWraps MsiRecordGetInteger")},
 
453
    { "GetString", (PyCFunction)record_getstring, METH_VARARGS,
 
454
    PyDoc_STR("GetString(field) -> string\nWraps MsiRecordGetString")},
408
455
    { "SetString", (PyCFunction)record_setstring, METH_VARARGS, 
409
456
        PyDoc_STR("SetString(field,str) -> None\nWraps MsiRecordSetString")},
410
457
    { "SetStream", (PyCFunction)record_setstream, METH_VARARGS,