[Python-checkins] CVS: python/dist/src/Objects intobject.c,2.56.6.3,2.56.6.4

Guido van Rossum gvanrossum@users.sourceforge.net
Mon, 11 Jun 2001 14:06:05 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv14124/Objects

Modified Files:
      Tag: descr-branch
	intobject.c 
Log Message:
Another one bites the dust: built-in 'int' is now the integer type.
(Still not subtypable though.)


Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.56.6.3
retrieving revision 2.56.6.4
diff -C2 -r2.56.6.3 -r2.56.6.4
*** intobject.c	2001/06/06 14:27:54	2.56.6.3
--- intobject.c	2001/06/11 21:06:03	2.56.6.4
***************
*** 751,754 ****
--- 751,788 ----
  }
  
+ static PyObject *
+ int_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+ {
+ 	PyObject *x = NULL;
+ 	int base = -909;
+ 	static char *kwlist[] = {"x", "base", 0};
+ 
+ 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:int", kwlist,
+ 					 &x, &base))
+ 		return NULL;
+ 	if (x == NULL)
+ 		return PyInt_FromLong(0L);
+ 	if (base == -909)
+ 		return PyNumber_Int(x);
+ 	if (PyString_Check(x))
+ 		return PyInt_FromString(PyString_AS_STRING(x), NULL, base);
+ 	if (PyUnicode_Check(x))
+ 		return PyInt_FromUnicode(PyUnicode_AS_UNICODE(x),
+ 					 PyUnicode_GET_SIZE(x),
+ 					 base);
+ 	PyErr_SetString(PyExc_TypeError,
+ 			"int() can't convert non-string with explicit base");
+ 	return NULL;
+ }
+ 
+ static char int_doc[] =
+ "int(x[, base]) -> integer\n\
+ \n\
+ Convert a string or number to an integer, if possible.  A floating point\n\
+ argument will be truncated towards zero (this does not include a string\n\
+ representation of a floating point number!)  When converting a string, use\n\
+ the optional base.  It is an error to supply a base when converting a\n\
+ non-string.";
+ 
  static PyNumberMethods int_as_number = {
  	(binaryfunc)int_add,	/*nb_add*/
***************
*** 809,813 ****
  	0,					/* tp_setattro */
  	0,					/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES /* tp_flags */
  };
  
--- 843,865 ----
  	0,					/* tp_setattro */
  	0,					/* tp_as_buffer */
! 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
! 	int_doc,				/* tp_doc */
! 	0,					/* tp_traverse */
! 	0,					/* tp_clear */
! 	0,					/* tp_richcompare */
! 	0,					/* tp_weaklistoffset */
! 	0,					/* tp_iter */
! 	0,					/* tp_iternext */
! 	0,					/* tp_methods */
! 	0,					/* tp_members */
! 	0,					/* tp_getset */
! 	0,					/* tp_base */
! 	0,					/* tp_dict */
! 	0,					/* tp_descr_get */
! 	0,					/* tp_descr_set */
! 	0,					/* tp_dictoffset */
! 	0,					/* tp_init */
! 	0,					/* tp_alloc */
! 	int_new,				/* tp_new */
  };