Skip to content

Commit 918e02a

Browse files
committed
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 eee50a8, we use the Python LongLong API unconditionally for simplicity. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
1 parent 96102a3 commit 918e02a

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/pl/plpython/plpy_cursorobject.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,7 @@ PLy_cursor_fetch(PyObject *self, PyObject *args)
444444
ret->status = PyInt_FromLong(SPI_OK_FETCH);
445445

446446
Py_DECREF(ret->nrows);
447-
ret->nrows = (SPI_processed > (uint64) LONG_MAX) ?
448-
PyFloat_FromDouble((double) SPI_processed) :
449-
PyInt_FromLong((long) SPI_processed);
447+
ret->nrows = PyLong_FromUnsignedLongLong(SPI_processed);
450448

451449
if (SPI_processed != 0)
452450
{

src/pl/plpython/plpy_spi.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,19 +371,15 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
371371
if (status > 0 && tuptable == NULL)
372372
{
373373
Py_DECREF(result->nrows);
374-
result->nrows = (rows > (uint64) LONG_MAX) ?
375-
PyFloat_FromDouble((double) rows) :
376-
PyInt_FromLong((long) rows);
374+
result->nrows = PyLong_FromUnsignedLongLong(rows);
377375
}
378376
else if (status > 0 && tuptable != NULL)
379377
{
380378
PLyDatumToOb ininfo;
381379
MemoryContext cxt;
382380

383381
Py_DECREF(result->nrows);
384-
result->nrows = (rows > (uint64) LONG_MAX) ?
385-
PyFloat_FromDouble((double) rows) :
386-
PyInt_FromLong((long) rows);
382+
result->nrows = PyLong_FromUnsignedLongLong(rows);
387383

388384
cxt = AllocSetContextCreate(CurrentMemoryContext,
389385
"PL/Python temp context",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy