cinap_lenrekadd hg and python4bb9e2215 years agoHistory
1280 lines · 30.0 KB · C
RawDownload
			PyErr_Format(PyExc_ValueError,			     "invalid literal for int() with base %d: %s",			     base, PyString_AS_STRING(srepr));			Py_DECREF(srepr);			return NULL;		}		return PyInt_FromString(string, NULL, base);	}#ifdef Py_USING_UNICODE	if (PyUnicode_Check(x))		return PyInt_FromUnicode(PyUnicode_AS_UNICODE(x),					 PyUnicode_GET_SIZE(x),					 base);#endif	PyErr_SetString(PyExc_TypeError,			"int() can't convert non-string with explicit base");	return NULL;} /* Wimpy, slow approach to tp_new calls for subtypes of int:   first create a regular int from whatever arguments we got,   then allocate a subtype instance and initialize its ob_ival   from the regular int.  The regular int is then thrown away.*/static PyObject *int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds){	PyObject *tmp, *newobj;	long ival; 	assert(PyType_IsSubtype(type, &PyInt_Type));	tmp = int_new(&PyInt_Type, args, kwds);	if (tmp == NULL)		return NULL;	if (!PyInt_Check(tmp)) {		ival = PyLong_AsLong(tmp);		if (ival == -1 && PyErr_Occurred()) {			Py_DECREF(tmp);			return NULL;		}	} else {		ival = ((PyIntObject *)tmp)->ob_ival;	} 	newobj = type->tp_alloc(type, 0);	if (newobj == NULL) {		Py_DECREF(tmp);		return NULL;	}	((PyIntObject *)newobj)->ob_ival = ival;	Py_DECREF(tmp);	return newobj;} static PyObject *int_getnewargs(PyIntObject *v){	return Py_BuildValue("(l)", v->ob_ival);} static PyMethodDef int_methods[] = {	{"__getnewargs__",	(PyCFunction)int_getnewargs,	METH_NOARGS},	{NULL,		NULL}		/* sentinel */}; PyDoc_STRVAR(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. If the argument is outside the integer range a long object\n\will be returned instead."); static PyNumberMethods int_as_number = {	(binaryfunc)int_add,	/*nb_add*/	(binaryfunc)int_sub,	/*nb_subtract*/	(binaryfunc)int_mul,	/*nb_multiply*/	(binaryfunc)int_classic_div, /*nb_divide*/	(binaryfunc)int_mod,	/*nb_remainder*/	(binaryfunc)int_divmod,	/*nb_divmod*/	(ternaryfunc)int_pow,	/*nb_power*/	(unaryfunc)int_neg,	/*nb_negative*/	(unaryfunc)int_pos,	/*nb_positive*/	(unaryfunc)int_abs,	/*nb_absolute*/	(inquiry)int_nonzero,	/*nb_nonzero*/	(unaryfunc)int_invert,	/*nb_invert*/	(binaryfunc)int_lshift,	/*nb_lshift*/	(binaryfunc)int_rshift,	/*nb_rshift*/	(binaryfunc)int_and,	/*nb_and*/	(binaryfunc)int_xor,	/*nb_xor*/	(binaryfunc)int_or,	/*nb_or*/	int_coerce,		/*nb_coerce*/	(unaryfunc)int_int,	/*nb_int*/	(unaryfunc)int_long,	/*nb_long*/	(unaryfunc)int_float,	/*nb_float*/	(unaryfunc)int_oct,	/*nb_oct*/	(unaryfunc)int_hex, 	/*nb_hex*/	0,			/*nb_inplace_add*/	0,			/*nb_inplace_subtract*/	0,			/*nb_inplace_multiply*/	0,			/*nb_inplace_divide*/	0,			/*nb_inplace_remainder*/	0,			/*nb_inplace_power*/	0,			/*nb_inplace_lshift*/	0,			/*nb_inplace_rshift*/	0,			/*nb_inplace_and*/	0,			/*nb_inplace_xor*/	0,			/*nb_inplace_or*/	(binaryfunc)int_div,	/* nb_floor_divide */	int_true_divide,	/* nb_true_divide */	0,			/* nb_inplace_floor_divide */	0,			/* nb_inplace_true_divide */	(unaryfunc)int_int,	/* nb_index */}; PyTypeObject PyInt_Type = {	PyObject_HEAD_INIT(&PyType_Type)	0,	"int",	sizeof(PyIntObject),	0,	(destructor)int_dealloc,		/* tp_dealloc */	(printfunc)int_print,			/* tp_print */	0,					/* tp_getattr */	0,					/* tp_setattr */	(cmpfunc)int_compare,			/* tp_compare */	(reprfunc)int_repr,			/* tp_repr */	&int_as_number,				/* tp_as_number */	0,					/* tp_as_sequence */	0,					/* tp_as_mapping */	(hashfunc)int_hash,			/* tp_hash */        0,					/* tp_call */        (reprfunc)int_repr,			/* tp_str */	PyObject_GenericGetAttr,		/* tp_getattro */	0,					/* tp_setattro */	0,					/* tp_as_buffer */	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |		Py_TPFLAGS_BASETYPE,		/* tp_flags */	int_doc,				/* tp_doc */	0,					/* tp_traverse */	0,					/* tp_clear */	0,					/* tp_richcompare */	0,					/* tp_weaklistoffset */	0,					/* tp_iter */	0,					/* tp_iternext */	int_methods,				/* 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 */	(freefunc)int_free,           		/* tp_free */}; int_PyInt_Init(void){	PyIntObject *v;	int ival;#if NSMALLNEGINTS + NSMALLPOSINTS > 0	for (ival = -NSMALLNEGINTS; ival < NSMALLPOSINTS; ival++) {              if (!free_list && (free_list = fill_free_list()) == NULL)			return 0;		/* PyObject_New is inlined */		v = free_list;		free_list = (PyIntObject *)v->ob_type;		PyObject_INIT(v, &PyInt_Type);		v->ob_ival = ival;		small_ints[ival + NSMALLNEGINTS] = v;	}#endif	return 1;} voidPyInt_Fini(void){	PyIntObject *p;	PyIntBlock *list, *next;	int i;	unsigned int ctr;	int bc, bf;	/* block count, number of freed blocks */	int irem, isum;	/* remaining unfreed ints per block, total */ #if NSMALLNEGINTS + NSMALLPOSINTS > 0        PyIntObject **q;         i = NSMALLNEGINTS + NSMALLPOSINTS;        q = small_ints;        while (--i >= 0) {                Py_XDECREF(*q);                *q++ = NULL;        }#endif	bc = 0;	bf = 0;	isum = 0;	list = block_list;	block_list = NULL;	free_list = NULL;	while (list != NULL) {		bc++;		irem = 0;		for (ctr = 0, p = &list->objects[0];		     ctr < N_INTOBJECTS;		     ctr++, p++) {			if (PyInt_CheckExact(p) && p->ob_refcnt != 0)				irem++;		}		next = list->next;		if (irem) {			list->next = block_list;			block_list = list;			for (ctr = 0, p = &list->objects[0];			     ctr < N_INTOBJECTS;			     ctr++, p++) {				if (!PyInt_CheckExact(p) ||				    p->ob_refcnt == 0) {					p->ob_type = (struct _typeobject *)						free_list;					free_list = p;				}#if NSMALLNEGINTS + NSMALLPOSINTS > 0				else if (-NSMALLNEGINTS <= p->ob_ival &&					 p->ob_ival < NSMALLPOSINTS &&					 small_ints[p->ob_ival +						    NSMALLNEGINTS] == NULL) {					Py_INCREF(p);					small_ints[p->ob_ival +						   NSMALLNEGINTS] = p;				}#endif			}		}		else {			PyMem_FREE(list);			bf++;		}		isum += irem;		list = next;	}	if (!Py_VerboseFlag)		return;	fprintf(stderr, "# cleanup ints");	if (!isum) {		fprintf(stderr, "\n");	}	else {		fprintf(stderr,			": %d unfreed int%s in %d out of %d block%s\n",			isum, isum == 1 ? "" : "s",			bc - bf, bc, bc == 1 ? "" : "s");	}	if (Py_VerboseFlag > 1) {		list = block_list;		while (list != NULL) {			for (ctr = 0, p = &list->objects[0];			     ctr < N_INTOBJECTS;			     ctr++, p++) {				if (PyInt_CheckExact(p) && p->ob_refcnt != 0)					/* XXX(twouters) cast refcount to					   long until %zd is universally					   available					 */					fprintf(stderr,				"#   <int at %p, refcnt=%ld, val=%ld>\n",						p, (long)p->ob_refcnt,						p->ob_ival);			}			list = list->next;		}	}}

Lines 1001–1280 of 1280. Previous lines