Changeset 391 for python/trunk/Modules/_sqlite/util.c
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Modules/_sqlite/util.c
r2 r391 1 1 /* util.c - various utility functions 2 2 * 3 * Copyright (C) 2005-20 07Gerhard Häring <gh@ghaering.de>3 * Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de> 4 4 * 5 5 * This file is part of pysqlite. … … 105 105 } 106 106 107 #ifdef WORDS_BIGENDIAN 108 # define IS_LITTLE_ENDIAN 0 109 #else 110 # define IS_LITTLE_ENDIAN 1 111 #endif 112 113 PyObject * 114 _pysqlite_long_from_int64(sqlite_int64 value) 115 { 116 #ifdef HAVE_LONG_LONG 117 # if SIZEOF_LONG_LONG < 8 118 if (value > PY_LLONG_MAX || value < PY_LLONG_MIN) { 119 return _PyLong_FromByteArray(&value, sizeof(value), 120 IS_LITTLE_ENDIAN, 1 /* signed */); 121 } 122 # endif 123 # if SIZEOF_LONG < SIZEOF_LONG_LONG 124 if (value > LONG_MAX || value < LONG_MIN) 125 return PyLong_FromLongLong(value); 126 # endif 127 #else 128 # if SIZEOF_LONG < 8 129 if (value > LONG_MAX || value < LONG_MIN) { 130 return _PyLong_FromByteArray(&value, sizeof(value), 131 IS_LITTLE_ENDIAN, 1 /* signed */); 132 } 133 # endif 134 #endif 135 return PyInt_FromLong(value); 136 } 137 138 sqlite_int64 139 _pysqlite_long_as_int64(PyObject * py_val) 140 { 141 int overflow; 142 #ifdef HAVE_LONG_LONG 143 PY_LONG_LONG value = PyLong_AsLongLongAndOverflow(py_val, &overflow); 144 #else 145 long value = PyLong_AsLongAndOverflow(py_val, &overflow); 146 #endif 147 if (value == -1 && PyErr_Occurred()) 148 return -1; 149 if (!overflow) { 150 #ifdef HAVE_LONG_LONG 151 # if SIZEOF_LONG_LONG > 8 152 if (-0x8000000000000000LL <= value && value <= 0x7FFFFFFFFFFFFFFFLL) 153 # endif 154 #else 155 # if SIZEOF_LONG > 8 156 if (-0x8000000000000000L <= value && value <= 0x7FFFFFFFFFFFFFFFL) 157 # endif 158 #endif 159 return value; 160 } 161 else if (sizeof(value) < sizeof(sqlite_int64)) { 162 sqlite_int64 int64val; 163 if (_PyLong_AsByteArray((PyLongObject *)py_val, 164 (unsigned char *)&int64val, sizeof(int64val), 165 IS_LITTLE_ENDIAN, 1 /* signed */) >= 0) { 166 return int64val; 167 } 168 } 169 PyErr_SetString(PyExc_OverflowError, 170 "Python int too large to convert to SQLite INTEGER"); 171 return -1; 172 }
Note:
See TracChangeset
for help on using the changeset viewer.