mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Convert from long to Py_ssize_t.
This commit is contained in:
		
							parent
							
								
									527eee2b32
								
							
						
					
					
						commit
						7f59b5cc03
					
				
					 1 changed files with 11 additions and 10 deletions
				
			
		| 
						 | 
					@ -4,10 +4,10 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
	PyObject_HEAD
 | 
						PyObject_HEAD
 | 
				
			||||||
	long      en_index;        /* current index of enumeration */
 | 
						Py_ssize_t en_index;	   /* current index of enumeration */
 | 
				
			||||||
	PyObject* en_sit;          /* secondary iterator of enumeration */
 | 
						PyObject* en_sit;          /* secondary iterator of enumeration */
 | 
				
			||||||
	PyObject* en_result;	   /* result tuple  */
 | 
						PyObject* en_result;	   /* result tuple  */
 | 
				
			||||||
	PyObject* en_longindex;	   /* index for sequences >= LONG_MAX */
 | 
						PyObject* en_longindex;	   /* index for sequences >= PY_SSIZE_T_MAX */
 | 
				
			||||||
} enumobject;
 | 
					} enumobject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
| 
						 | 
					@ -25,18 +25,19 @@ enum_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 | 
				
			||||||
	en = (enumobject *)type->tp_alloc(type, 0);
 | 
						en = (enumobject *)type->tp_alloc(type, 0);
 | 
				
			||||||
	if (en == NULL)
 | 
						if (en == NULL)
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	if (start) {
 | 
						if (start != NULL) {
 | 
				
			||||||
		start = PyNumber_Index(start);
 | 
							start = PyNumber_Index(start);
 | 
				
			||||||
		if (start == NULL) {
 | 
							if (start == NULL) {
 | 
				
			||||||
			Py_DECREF(en);
 | 
								Py_DECREF(en);
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (PyLong_Check(start)) {
 | 
							assert(PyInt_Check(start) || PyLong_Check(start));
 | 
				
			||||||
			en->en_index = LONG_MAX;
 | 
							en->en_index = PyInt_AsSsize_t(start);
 | 
				
			||||||
 | 
							if (en->en_index == -1 && PyErr_Occurred()) {
 | 
				
			||||||
 | 
								PyErr_Clear();
 | 
				
			||||||
 | 
								en->en_index = PY_SSIZE_T_MAX;
 | 
				
			||||||
			en->en_longindex = start;
 | 
								en->en_longindex = start;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			assert(PyInt_Check(start));
 | 
					 | 
				
			||||||
			en->en_index = PyInt_AsLong(start);
 | 
					 | 
				
			||||||
			en->en_longindex = NULL;
 | 
								en->en_longindex = NULL;
 | 
				
			||||||
			Py_DECREF(start);
 | 
								Py_DECREF(start);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -85,7 +86,7 @@ enum_next_long(enumobject *en, PyObject* next_item)
 | 
				
			||||||
	PyObject *stepped_up;
 | 
						PyObject *stepped_up;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (en->en_longindex == NULL) {
 | 
						if (en->en_longindex == NULL) {
 | 
				
			||||||
		en->en_longindex = PyInt_FromLong(LONG_MAX);
 | 
							en->en_longindex = PyInt_FromSsize_t(PY_SSIZE_T_MAX);
 | 
				
			||||||
		if (en->en_longindex == NULL)
 | 
							if (en->en_longindex == NULL)
 | 
				
			||||||
			return NULL;
 | 
								return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -130,10 +131,10 @@ enum_next(enumobject *en)
 | 
				
			||||||
	if (next_item == NULL)
 | 
						if (next_item == NULL)
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (en->en_index == LONG_MAX)
 | 
						if (en->en_index == PY_SSIZE_T_MAX)
 | 
				
			||||||
		return enum_next_long(en, next_item);
 | 
							return enum_next_long(en, next_item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	next_index = PyInt_FromLong(en->en_index);
 | 
						next_index = PyInt_FromSsize_t(en->en_index);
 | 
				
			||||||
	if (next_index == NULL) {
 | 
						if (next_index == NULL) {
 | 
				
			||||||
		Py_DECREF(next_item);
 | 
							Py_DECREF(next_item);
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue