[Cython] negative integer -> unsigned integer, TypeError or OverflowError?

Lisandro Dalcin dalcinl at gmail.com
Fri Feb 6 16:46:37 CET 2009


Core CPython is not consistent about this. What should we do in
Cython? Should we report this to Python-Dev?

Long story:

In core CPython (svn trunk), at Objects/longobjects.c, you should see
that in almost all cases OverflowError is raise. But see this one:

int
_PyLong_AsByteArray(PyLongObject* v,
		    unsigned char* bytes, size_t n,
		    int little_endian, int is_signed)
{
<...>
		if (!is_signed) {
			PyErr_SetString(PyExc_TypeError,
				"can't convert negative long to unsigned");
			return -1;
		}
<...>
}


-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594


More information about the Cython-dev mailing list