summaryrefslogtreecommitdiff
path: root/src/util.c
blob: f00416f4a9b1e573e8282ea247dddfbf7aa4f4ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "pycurl.h"

static PyObject *
create_error_object(CurlObject *self, int code)
{
    PyObject *s, *v;
    
    s = PyText_FromString_Ignore(self->error);
    if (s == NULL) {
        return NULL;
    }
    v = Py_BuildValue("(iO)", code, s);
    if (v == NULL) {
        Py_DECREF(s);
        return NULL;
    }
    return v;
}

PYCURL_INTERNAL void
create_and_set_error_object(CurlObject *self, int code)
{
    PyObject *e;
    
    self->error[sizeof(self->error) - 1] = 0;
    e = create_error_object(self, code);
    if (e != NULL) {
        PyErr_SetObject(ErrorObject, e);
        Py_DECREF(e);
    }
}