| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 366fcba commit 4c0deb2
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -637,9 +637,11 @@ _pysqlite_func_callback(sqlite3_context *context, int argc, sqlite3_value **argv | |||
| 637 | 637 | Py_DECREF(py_retval); | |
| 638 | 638 | } | |
| 639 | 639 | if (!ok) { | |
| 640 | - if (_pysqlite_enable_callback_tracebacks) { | ||
| 640 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 641 | + if (state->enable_callback_tracebacks) { | ||
| 641 | 642 | PyErr_Print(); | |
| 642 | - } else { | ||
| 643 | + } | ||
| 644 | + else { | ||
| 643 | 645 | PyErr_Clear(); | |
| 644 | 646 | } | |
| 645 | 647 | sqlite3_result_error(context, "user-defined function raised exception", -1); | |
@@ -669,9 +671,12 @@ static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_ | |||
| 669 | 671 | ||
| 670 | 672 | if (PyErr_Occurred()) { | |
| 671 | 673 | *aggregate_instance = 0; | |
| 672 | - if (_pysqlite_enable_callback_tracebacks) { | ||
| 674 | + | ||
| 675 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 676 | + if (state->enable_callback_tracebacks) { | ||
| 673 | 677 | PyErr_Print(); | |
| 674 | - } else { | ||
| 678 | + } | ||
| 679 | + else { | ||
| 675 | 680 | PyErr_Clear(); | |
| 676 | 681 | } | |
| 677 | 682 | sqlite3_result_error(context, "user-defined aggregate's '__init__' method raised error", -1); | |
@@ -693,9 +698,11 @@ static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_ | |||
| 693 | 698 | Py_DECREF(args); | |
| 694 | 699 | ||
| 695 | 700 | if (!function_result) { | |
| 696 | - if (_pysqlite_enable_callback_tracebacks) { | ||
| 701 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 702 | + if (state->enable_callback_tracebacks) { | ||
| 697 | 703 | PyErr_Print(); | |
| 698 | - } else { | ||
| 704 | + } | ||
| 705 | + else { | ||
| 699 | 706 | PyErr_Clear(); | |
| 700 | 707 | } | |
| 701 | 708 | sqlite3_result_error(context, "user-defined aggregate's 'step' method raised error", -1); | |
@@ -746,9 +753,11 @@ _pysqlite_final_callback(sqlite3_context *context) | |||
| 746 | 753 | Py_DECREF(function_result); | |
| 747 | 754 | } | |
| 748 | 755 | if (!ok) { | |
| 749 | - if (_pysqlite_enable_callback_tracebacks) { | ||
| 756 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 757 | + if (state->enable_callback_tracebacks) { | ||
| 750 | 758 | PyErr_Print(); | |
| 751 | - } else { | ||
| 759 | + } | ||
| 760 | + else { | ||
| 752 | 761 | PyErr_Clear(); | |
| 753 | 762 | } | |
| 754 | 763 | sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1); | |
@@ -941,21 +950,27 @@ static int _authorizer_callback(void* user_arg, int action, const char* arg1, co | |||
| 941 | 950 | ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source); | |
| 942 | 951 | ||
| 943 | 952 | if (ret == NULL) { | |
| 944 | - if (_pysqlite_enable_callback_tracebacks) | ||
| 953 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 954 | + if (state->enable_callback_tracebacks) { | ||
| 945 | 955 | PyErr_Print(); | |
| 946 | - else | ||
| 956 | + } | ||
| 957 | + else { | ||
| 947 | 958 | PyErr_Clear(); | |
| 959 | + } | ||
| 948 | 960 | ||
| 949 | 961 | rc = SQLITE_DENY; | |
| 950 | 962 | } | |
| 951 | 963 | else { | |
| 952 | 964 | if (PyLong_Check(ret)) { | |
| 953 | 965 | rc = _PyLong_AsInt(ret); | |
| 954 | 966 | if (rc == -1 && PyErr_Occurred()) { | |
| 955 | - if (_pysqlite_enable_callback_tracebacks) | ||
| 967 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 968 | + if (state->enable_callback_tracebacks) { | ||
| 956 | 969 | PyErr_Print(); | |
| 957 | - else | ||
| 970 | + } | ||
| 971 | + else { | ||
| 958 | 972 | PyErr_Clear(); | |
| 973 | + } | ||
| 959 | 974 | rc = SQLITE_DENY; | |
| 960 | 975 | } | |
| 961 | 976 | } | |
@@ -979,9 +994,11 @@ static int _progress_handler(void* user_arg) | |||
| 979 | 994 | ret = _PyObject_CallNoArg((PyObject*)user_arg); | |
| 980 | 995 | ||
| 981 | 996 | if (!ret) { | |
| 982 | - if (_pysqlite_enable_callback_tracebacks) { | ||
| 997 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 998 | + if (state->enable_callback_tracebacks) { | ||
| 983 | 999 | PyErr_Print(); | |
| 984 | - } else { | ||
| 1000 | + } | ||
| 1001 | + else { | ||
| 985 | 1002 | PyErr_Clear(); | |
| 986 | 1003 | } | |
| 987 | 1004 | ||
@@ -1030,9 +1047,11 @@ static void _trace_callback(void* user_arg, const char* statement_string) | |||
| 1030 | 1047 | if (ret) { | |
| 1031 | 1048 | Py_DECREF(ret); | |
| 1032 | 1049 | } else { | |
| 1033 | - if (_pysqlite_enable_callback_tracebacks) { | ||
| 1050 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 1051 | + if (state->enable_callback_tracebacks) { | ||
| 1034 | 1052 | PyErr_Print(); | |
| 1035 | - } else { | ||
| 1053 | + } | ||
| 1054 | + else { | ||
| 1036 | 1055 | PyErr_Clear(); | |
| 1037 | 1056 | } | |
| 1038 | 1057 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,7 +147,8 @@ _pysqlite_get_converter(const char *keystr, Py_ssize_t keylen) | |||
| 147 | 147 | return NULL; | |
| 148 | 148 | } | |
| 149 | 149 | ||
| 150 | - retval = PyDict_GetItemWithError(_pysqlite_converters, upcase_key); | ||
| 150 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 151 | + retval = PyDict_GetItemWithError(state->converters, upcase_key); | ||
| 151 | 152 | Py_DECREF(upcase_key); | |
| 152 | 153 | ||
| 153 | 154 | return retval; | |
@@ -469,6 +470,7 @@ get_statement_from_cache(pysqlite_Cursor *self, PyObject *operation) | |||
| 469 | 470 | static PyObject * | |
| 470 | 471 | _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument) | |
| 471 | 472 | { | |
| 473 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 472 | 474 | PyObject* parameters_list = NULL; | |
| 473 | 475 | PyObject* parameters_iter = NULL; | |
| 474 | 476 | PyObject* parameters = NULL; | |
@@ -583,7 +585,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation | |||
| 583 | 585 | if (rc != SQLITE_DONE && rc != SQLITE_ROW) { | |
| 584 | 586 | if (PyErr_Occurred()) { | |
| 585 | 587 | /* there was an error that occurred in a user-defined callback */ | |
| 586 | - if (_pysqlite_enable_callback_tracebacks) { | ||
| 588 | + if (state->enable_callback_tracebacks) { | ||
| 587 | 589 | PyErr_Print(); | |
| 588 | 590 | } else { | |
| 589 | 591 | PyErr_Clear(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,24 +29,20 @@ | |||
| 29 | 29 | #include "microprotocols.h" | |
| 30 | 30 | #include "prepare_protocol.h" | |
| 31 | 31 | ||
| 32 | - /** the adapters registry **/ | ||
| 33 | - | ||
| 34 | - static PyObject *psyco_adapters = NULL; | ||
| 35 | 32 | ||
| 36 | 33 | /* pysqlite_microprotocols_init - initialize the adapters dictionary */ | |
| 37 | 34 | ||
| 38 | 35 | int | |
| 39 | 36 | pysqlite_microprotocols_init(PyObject *module) | |
| 40 | 37 | { | |
| 41 | 38 | /* create adapters dictionary and put it in module namespace */ | |
| 42 | - if ((psyco_adapters = PyDict_New()) == NULL) { | ||
| 39 | + pysqlite_state *state = pysqlite_get_state(module); | ||
| 40 | + state->psyco_adapters = PyDict_New(); | ||
| 41 | + if (state->psyco_adapters == NULL) { | ||
| 43 | 42 | return -1; | |
| 44 | 43 | } | |
| 45 | 44 | ||
| 46 | - int res = PyModule_AddObjectRef(module, "adapters", psyco_adapters); | ||
| 47 | - Py_DECREF(psyco_adapters); | ||
| 48 | - | ||
| 49 | - return res; | ||
| 45 | + return PyModule_AddObjectRef(module, "adapters", state->psyco_adapters); | ||
| 50 | 46 | } | |
| 51 | 47 | ||
| 52 | 48 | ||
@@ -65,7 +61,8 @@ pysqlite_microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast) | |||
| 65 | 61 | return -1; | |
| 66 | 62 | } | |
| 67 | 63 | ||
| 68 | - rc = PyDict_SetItem(psyco_adapters, key, cast); | ||
| 64 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 65 | + rc = PyDict_SetItem(state->psyco_adapters, key, cast); | ||
| 69 | 66 | Py_DECREF(key); | |
| 70 | 67 | ||
| 71 | 68 | return rc; | |
@@ -89,7 +86,8 @@ pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) | |||
| 89 | 86 | if (!key) { | |
| 90 | 87 | return NULL; | |
| 91 | 88 | } | |
| 92 | - adapter = PyDict_GetItemWithError(psyco_adapters, key); | ||
| 89 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 90 | + adapter = PyDict_GetItemWithError(state->psyco_adapters, key); | ||
| 93 | 91 | Py_DECREF(key); | |
| 94 | 92 | if (adapter) { | |
| 95 | 93 | Py_INCREF(adapter); | |
@@ -143,7 +141,6 @@ pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt) | |||
| 143 | 141 | return Py_NewRef(alt); | |
| 144 | 142 | } | |
| 145 | 143 | /* else set the right exception and return NULL */ | |
| 146 | - pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 147 | 144 | PyErr_SetString(state->ProgrammingError, "can't adapt"); | |
| 148 | 145 | return NULL; | |
| 149 | 146 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,11 +41,6 @@ module _sqlite3 | |||
| 41 | 41 | [clinic start generated code]*/ | |
| 42 | 42 | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/ | |
| 43 | 43 | ||
| 44 | - /* static objects at module-level */ | ||
| 45 | - PyObject* _pysqlite_converters = NULL; | ||
| 46 | - int _pysqlite_enable_callback_tracebacks = 0; | ||
| 47 | - int pysqlite_BaseTypeAdapted = 0; | ||
| 48 | - | ||
| 49 | 44 | pysqlite_state pysqlite_global_state; | |
| 50 | 45 | ||
| 51 | 46 | // NOTE: This must equal sqlite3.Connection.__init__ argument spec! | |
@@ -159,7 +154,8 @@ pysqlite_register_adapter_impl(PyObject *module, PyTypeObject *type, | |||
| 159 | 154 | * (99 % of all usages) */ | |
| 160 | 155 | if (type == &PyLong_Type || type == &PyFloat_Type | |
| 161 | 156 | || type == &PyUnicode_Type || type == &PyByteArray_Type) { | |
| 162 | - pysqlite_BaseTypeAdapted = 1; | ||
| 157 | + pysqlite_state *state = pysqlite_get_state(module); | ||
| 158 | + state->BaseTypeAdapted = 1; | ||
| 163 | 159 | } | |
| 164 | 160 | ||
| 165 | 161 | pysqlite_state *state = pysqlite_get_state(NULL); | |
@@ -197,7 +193,8 @@ pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name, | |||
| 197 | 193 | goto error; | |
| 198 | 194 | } | |
| 199 | 195 | ||
| 200 | - if (PyDict_SetItem(_pysqlite_converters, name, callable) != 0) { | ||
| 196 | + pysqlite_state *state = pysqlite_get_state(module); | ||
| 197 | + if (PyDict_SetItem(state->converters, name, callable) != 0) { | ||
| 201 | 198 | goto error; | |
| 202 | 199 | } | |
| 203 | 200 | ||
@@ -220,7 +217,8 @@ static PyObject * | |||
| 220 | 217 | pysqlite_enable_callback_trace_impl(PyObject *module, int enable) | |
| 221 | 218 | /*[clinic end generated code: output=4ff1d051c698f194 input=cb79d3581eb77c40]*/ | |
| 222 | 219 | { | |
| 223 | - _pysqlite_enable_callback_tracebacks = enable; | ||
| 220 | + pysqlite_state *state = pysqlite_get_state(module); | ||
| 221 | + state->enable_callback_tracebacks = enable; | ||
| 224 | 222 | ||
| 225 | 223 | Py_RETURN_NONE; | |
| 226 | 224 | } | |
@@ -246,15 +244,13 @@ pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto, | |||
| 246 | 244 | ||
| 247 | 245 | static int converters_init(PyObject* module) | |
| 248 | 246 | { | |
| 249 | - _pysqlite_converters = PyDict_New(); | ||
| 250 | - if (!_pysqlite_converters) { | ||
| 247 | + pysqlite_state *state = pysqlite_get_state(module); | ||
| 248 | + state->converters = PyDict_New(); | ||
| 249 | + if (state->converters == NULL) { | ||
| 251 | 250 | return -1; | |
| 252 | 251 | } | |
| 253 | 252 | ||
| 254 | - int res = PyModule_AddObjectRef(module, "converters", _pysqlite_converters); | ||
| 255 | - Py_DECREF(_pysqlite_converters); | ||
| 256 | - | ||
| 257 | - return res; | ||
| 253 | + return PyModule_AddObjectRef(module, "converters", state->converters); | ||
| 258 | 254 | } | |
| 259 | 255 | ||
| 260 | 256 | static int | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,17 @@ typedef struct { | |||
| 41 | 41 | PyObject *ProgrammingError; | |
| 42 | 42 | PyObject *Warning; | |
| 43 | 43 | ||
| 44 | + | ||
| 45 | + /* A dictionary, mapping column types (INTEGER, VARCHAR, etc.) to converter | ||
| 46 | + * functions, that convert the SQL value to the appropriate Python value. | ||
| 47 | + * The key is uppercase. | ||
| 48 | + */ | ||
| 49 | + PyObject *converters; | ||
| 50 | + | ||
| 44 | 51 | PyObject *lru_cache; | |
| 52 | + PyObject *psyco_adapters; // The adapters registry | ||
| 53 | + int BaseTypeAdapted; | ||
| 54 | + int enable_callback_tracebacks; | ||
| 45 | 55 | ||
| 46 | 56 | PyTypeObject *ConnectionType; | |
| 47 | 57 | PyTypeObject *CursorType; | |
@@ -58,15 +68,6 @@ pysqlite_get_state(PyObject *Py_UNUSED(module)) | |||
| 58 | 68 | return &pysqlite_global_state; | |
| 59 | 69 | } | |
| 60 | 70 | ||
| 61 | - /* A dictionary, mapping column types (INTEGER, VARCHAR, etc.) to converter | ||
| 62 | - * functions, that convert the SQL value to the appropriate Python value. | ||
| 63 | - * The key is uppercase. | ||
| 64 | - */ | ||
| 65 | - extern PyObject* _pysqlite_converters; | ||
| 66 | - | ||
| 67 | - extern int _pysqlite_enable_callback_tracebacks; | ||
| 68 | - extern int pysqlite_BaseTypeAdapted; | ||
| 69 | - | ||
| 70 | 71 | #define PARSE_DECLTYPES 1 | |
| 71 | 72 | #define PARSE_COLNAMES 2 | |
| 72 | 73 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -211,7 +211,8 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec | |||
| 211 | 211 | /* returns 0 if the object is one of Python's internal ones that don't need to be adapted */ | |
| 212 | 212 | static int _need_adapt(PyObject* obj) | |
| 213 | 213 | { | |
| 214 | - if (pysqlite_BaseTypeAdapted) { | ||
| 214 | + pysqlite_state *state = pysqlite_get_state(NULL); | ||
| 215 | + if (state->BaseTypeAdapted) { | ||
| 215 | 216 | return 1; | |
| 216 | 217 | } | |
| 217 | 218 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments