mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-04 00:02:52 -05:00 
			
		
		
		
	Improve type conversion of SPI_processed in Python
The previous code converted SPI_processed to a Python float if it didn't fit into a Python int. But Python longs have unlimited precision, so use that instead in all cases. As in eee50a8d4c389171ad5180568a7221f7e9b28f09, we use the Python LongLong API unconditionally for simplicity. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
This commit is contained in:
		
							parent
							
								
									96102a32a3
								
							
						
					
					
						commit
						918e02a221
					
				@ -444,9 +444,7 @@ PLy_cursor_fetch(PyObject *self, PyObject *args)
 | 
				
			|||||||
		ret->status = PyInt_FromLong(SPI_OK_FETCH);
 | 
							ret->status = PyInt_FromLong(SPI_OK_FETCH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Py_DECREF(ret->nrows);
 | 
							Py_DECREF(ret->nrows);
 | 
				
			||||||
		ret->nrows = (SPI_processed > (uint64) LONG_MAX) ?
 | 
							ret->nrows = PyLong_FromUnsignedLongLong(SPI_processed);
 | 
				
			||||||
			PyFloat_FromDouble((double) SPI_processed) :
 | 
					 | 
				
			||||||
			PyInt_FromLong((long) SPI_processed);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (SPI_processed != 0)
 | 
							if (SPI_processed != 0)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
				
			|||||||
@ -371,9 +371,7 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
 | 
				
			|||||||
	if (status > 0 && tuptable == NULL)
 | 
						if (status > 0 && tuptable == NULL)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		Py_DECREF(result->nrows);
 | 
							Py_DECREF(result->nrows);
 | 
				
			||||||
		result->nrows = (rows > (uint64) LONG_MAX) ?
 | 
							result->nrows = PyLong_FromUnsignedLongLong(rows);
 | 
				
			||||||
			PyFloat_FromDouble((double) rows) :
 | 
					 | 
				
			||||||
			PyInt_FromLong((long) rows);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else if (status > 0 && tuptable != NULL)
 | 
						else if (status > 0 && tuptable != NULL)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@ -381,9 +379,7 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
 | 
				
			|||||||
		MemoryContext cxt;
 | 
							MemoryContext cxt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Py_DECREF(result->nrows);
 | 
							Py_DECREF(result->nrows);
 | 
				
			||||||
		result->nrows = (rows > (uint64) LONG_MAX) ?
 | 
							result->nrows = PyLong_FromUnsignedLongLong(rows);
 | 
				
			||||||
			PyFloat_FromDouble((double) rows) :
 | 
					 | 
				
			||||||
			PyInt_FromLong((long) rows);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		cxt = AllocSetContextCreate(CurrentMemoryContext,
 | 
							cxt = AllocSetContextCreate(CurrentMemoryContext,
 | 
				
			||||||
									"PL/Python temp context",
 | 
														"PL/Python temp context",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user