wrapper doesn't honour overloaded types

Bug #1075253 reported by Nick Thompson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PyBindGen
New
Undecided
Unassigned

Bug Description

I have a bunch of constructors to a class with differing types in the second argument. Here are two of them:

Construct(uint16_t id, uint8_t _uint8_t, char *description = NULL);
Construct(uint16_t id, int32_t _int32_t, char *description = NULL);

pybindgen 0.16.0 generates wrappers that look like:

static int
_wrap_PyConstruct__tp_init__2(PyConstruct *self, PyObject *args, PyObject *kwargs, PyObject **return_exception)
{
    int id;
    int _uint8_t;
    char const *description = 0l;
    const char *keywords[] = {"id", "_uint8_t", "description", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "ii|s", (char **) keywords, &id, &_uint8_t, &description)) {
        {
            PyObject *exc_type, *traceback;
            PyErr_Fetch(&exc_type, return_exception, &traceback);
            Py_XDECREF(exc_type);
            Py_XDECREF(traceback);
        }
        return -1;
    }
    if (id > 0xffff) {
        PyErr_SetString(PyExc_ValueError, "Out of range");
        {
            PyObject *exc_type, *traceback;
            PyErr_Fetch(&exc_type, return_exception, &traceback);
            Py_XDECREF(exc_type);
            Py_XDECREF(traceback);
        }
        return -1;
    }
    if (_uint8_t > 0xff) {
        PyErr_SetString(PyExc_ValueError, "Out of range");
        {
            PyObject *exc_type, *traceback;
            PyErr_Fetch(&exc_type, return_exception, &traceback);
            Py_XDECREF(exc_type);
            Py_XDECREF(traceback);
        }
        return -1;
    }
    self->obj = new Construct(id, _uint8_t, description);
    self->flags = PYBINDGEN_WRAPPER_FLAG_NONE;
    return 0;
}

Note that it uses int type for _uint8_t (which is a variable not a type), and then range checks its value, which is all well and good, but then it calls the constructor:

    self->obj = new Construct(id, _uint8_t, description);

which I think ought to be:

    self->obj = new Construct(id, (uint8_t)_uint8_t, description);

otherwise the wrong constructor is called. I would have though the cast to the original type should be present in all similar cases to ensure correct overload behaviour.

Interestingly, I also have a int32_t case and it uses int32_t as the type in the wrapper. And also a uint32_t case for which it uses unsigned int. These seem not to follow the pattern of using int above, but are basically okay for my case. None the less, the cast in the Constructor call would still seem wise.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.