diff options
author | Petri Lehtinen <petri@digip.org> | 2012-02-21 11:58:40 (GMT) |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2012-02-21 12:04:46 (GMT) |
commit | 4ab701b2d30f1975bbea837234f6dfe52785c3d5 (patch) | |
tree | 24bfc442848675af9290debb7d06e737e2fb0022 /Modules | |
parent | 36b7361fe76733b3a4944ef92b49bcea4584b740 (diff) | |
download | cpython-4ab701b2d30f1975bbea837234f6dfe52785c3d5.zip cpython-4ab701b2d30f1975bbea837234f6dfe52785c3d5.tar.gz cpython-4ab701b2d30f1975bbea837234f6dfe52785c3d5.tar.bz2 |
sqlite3: Fix 64-bit integer handling in user functions on 32-bit architectures
Closes #8033.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sqlite/connection.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 7666580..26678c7 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -540,7 +540,6 @@ error: void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val) { - long longval; const char* buffer; Py_ssize_t buflen; PyObject* stringval; @@ -550,8 +549,9 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val) } else if (py_val == Py_None) { sqlite3_result_null(context); } else if (PyInt_Check(py_val)) { - longval = PyInt_AsLong(py_val); - sqlite3_result_int64(context, (PY_LONG_LONG)longval); + sqlite3_result_int64(context, (sqlite3_int64)PyInt_AsLong(py_val)); + } else if (PyLong_Check(py_val)) { + sqlite3_result_int64(context, PyLong_AsLongLong(py_val)); } else if (PyFloat_Check(py_val)) { sqlite3_result_double(context, PyFloat_AsDouble(py_val)); } else if (PyBuffer_Check(py_val)) { @@ -580,7 +580,7 @@ PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_ sqlite3_value* cur_value; PyObject* cur_py_value; const char* val_str; - PY_LONG_LONG val_int; + sqlite3_int64 val_int; Py_ssize_t buflen; void* raw_buffer; @@ -594,7 +594,10 @@ PyObject* _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_ switch (sqlite3_value_type(argv[i])) { case SQLITE_INTEGER: val_int = sqlite3_value_int64(cur_value); - cur_py_value = PyInt_FromLong((long)val_int); + if(val_int < LONG_MIN || val_int > LONG_MAX) + cur_py_value = PyLong_FromLongLong(val_int); + else + cur_py_value = PyInt_FromLong((long)val_int); break; case SQLITE_FLOAT: cur_py_value = PyFloat_FromDouble(sqlite3_value_double(cur_value)); |