mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Issue 1742669. Now %d accepts very big float numbers.
Thanks Gabriel Genellina.
This commit is contained in:
		
							parent
							
								
									b93e7d16d5
								
							
						
					
					
						commit
						c11cecf3d0
					
				
					 4 changed files with 118 additions and 32 deletions
				
			
		|  | @ -8334,6 +8334,7 @@ PyObject *PyUnicode_Format(PyObject *format, | |||
| 	    int prec = -1; | ||||
| 	    Py_UNICODE c = '\0'; | ||||
| 	    Py_UNICODE fill; | ||||
| 	    int isnumok; | ||||
| 	    PyObject *v = NULL; | ||||
| 	    PyObject *temp = NULL; | ||||
| 	    Py_UNICODE *pbuf; | ||||
|  | @ -8546,21 +8547,49 @@ PyObject *PyUnicode_Format(PyObject *format, | |||
| 	    case 'X': | ||||
| 		if (c == 'i') | ||||
| 		    c = 'd'; | ||||
| 		if (PyLong_Check(v)) { | ||||
| 		    temp = formatlong(v, flags, prec, c); | ||||
| 		    if (!temp) | ||||
| 			goto onError; | ||||
| 		    pbuf = PyUnicode_AS_UNICODE(temp); | ||||
| 		    len = PyUnicode_GET_SIZE(temp); | ||||
| 		    sign = 1; | ||||
| 		isnumok = 0; | ||||
| 		if (PyNumber_Check(v)) { | ||||
| 			PyObject *iobj=NULL; | ||||
| 
 | ||||
| 			if (PyInt_Check(v) || (PyLong_Check(v))) { | ||||
| 				iobj = v; | ||||
| 				Py_INCREF(iobj); | ||||
| 			} | ||||
| 			else { | ||||
| 				iobj = PyNumber_Int(v); | ||||
| 				if (iobj==NULL) iobj = PyNumber_Long(v); | ||||
| 			} | ||||
| 			if (iobj!=NULL) { | ||||
| 				if (PyInt_Check(iobj)) { | ||||
| 					isnumok = 1; | ||||
| 					pbuf = formatbuf; | ||||
| 					len = formatint(pbuf, sizeof(formatbuf)/sizeof(Py_UNICODE), | ||||
| 						    flags, prec, c, iobj); | ||||
| 					Py_DECREF(iobj); | ||||
| 					if (len < 0) | ||||
| 					    goto onError; | ||||
| 					sign = 1; | ||||
| 				}  | ||||
| 				else if (PyLong_Check(iobj)) { | ||||
| 					isnumok = 1; | ||||
| 					temp = formatlong(iobj, flags, prec, c); | ||||
| 					Py_DECREF(iobj); | ||||
| 					if (!temp) | ||||
| 					    goto onError; | ||||
| 					pbuf = PyUnicode_AS_UNICODE(temp); | ||||
| 					len = PyUnicode_GET_SIZE(temp); | ||||
| 					sign = 1; | ||||
| 				} | ||||
| 				else { | ||||
| 					Py_DECREF(iobj); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		else { | ||||
| 		    pbuf = formatbuf; | ||||
| 		    len = formatint(pbuf, sizeof(formatbuf)/sizeof(Py_UNICODE), | ||||
| 				    flags, prec, c, v); | ||||
| 		    if (len < 0) | ||||
| 		if (!isnumok) { | ||||
| 			PyErr_Format(PyExc_TypeError,  | ||||
| 			    "%%%c format: a number is required, " | ||||
| 			    "not %.200s", c, Py_TYPE(v)->tp_name); | ||||
| 			goto onError; | ||||
| 		    sign = 1; | ||||
| 		} | ||||
| 		if (flags & F_ZERO) | ||||
| 		    fill = '0'; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Facundo Batista
						Facundo Batista