[Python-Dev] More C API abstraction for user defined types

Petre Galan Petre.Galan at gmail.com
Mon Jul 12 19:35:09 CEST 2010


Hello,
Defining a user type which implements number protocol should be treated as a 
number (long) in PyArg_ParseTuple using "l" format.
In getargs.c:
	case 'l': {/* long int */
		long *p = va_arg(*p_va, long *);
		long ival;
		if (float_argument_error(arg))
			return converterr("integer<l>", arg, msgbuf, bufsize);
		ival = PyLong_AsLong(arg);

		if (ival == -1 && PyErr_Occurred())
			return converterr("integer<l>", arg, msgbuf, bufsize);
		else
			*p = ival;
		break;
	}
ival should not be resolved through PyLong_AsLong, but through 
functionality/interface like PyNumber_Long, thus allowing more diversity in 
accessing the PyArg_Parse interfaces.

Petre



More information about the Python-Dev mailing list