Open andrewchi opened 4 years ago
I just ran into the same issue. The SystemError might be result of returning a NULL from C to python without setting the error.
Scrolling through the Code I see at least one possible instance (picked randomly here) where this might be the case, compare how in the first return NULL is returned, in the second one the error message is set.
static PyObject *
pytricia_get(register PyTricia *obj, PyObject *args) {
PyObject *key = NULL;
PyObject *defvalue = NULL;
if (!PyArg_ParseTuple(args, "O|O:get", &key, &defvalue)) {
return NULL;
}
prefix_t *prefix = _key_object_to_prefix(key);
if (!prefix) {
PyErr_SetString(PyExc_ValueError, "Invalid prefix.");
return NULL;
}
…
documenting it here in case other people stumble upon the same issue. Not sure if I will be able to submit a pull request due to time constraints.
Currently I add a '0' in the front and end of an address as a workaround like so:
if the_ip.startswith('::'):
the_ip = f'0{the_ip}'
if the_ip.endswith('::'):
the_ip = f'{the_ip}0'
Confirming what @lithammer reported in https://github.com/jsommers/pytricia/issues/8#issuecomment-492766164_ , the following exceptions are raised for the IPv6 addresses "::", "::1", "::2", ..., "::f", which should all be valid. For some reason, the errors do not occur with "::10".
It is not clear to me at what point that this bug is triggered, perhaps somewhere in _key_object_to_prefix()?