1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00

use MY_CXT instead of a static global variable

This commit is contained in:
Kenichi Ishigaki 2015-05-02 02:29:43 +09:00
parent 4b92383fe4
commit 74e19c5161
3 changed files with 25 additions and 23 deletions

View file

@ -9,6 +9,7 @@ MODULE = DBD::SQLite PACKAGE = DBD::SQLite::db
PROTOTYPES: DISABLE PROTOTYPES: DISABLE
BOOT: BOOT:
init_cxt();
sv_setpv(get_sv("DBD::SQLite::sqlite_version", TRUE|GV_ADDMULTI), SQLITE_VERSION); sv_setpv(get_sv("DBD::SQLite::sqlite_version", TRUE|GV_ADDMULTI), SQLITE_VERSION);
sv_setiv(get_sv("DBD::SQLite::sqlite_version_number", TRUE|GV_ADDMULTI), SQLITE_VERSION_NUMBER); sv_setiv(get_sv("DBD::SQLite::sqlite_version_number", TRUE|GV_ADDMULTI), SQLITE_VERSION_NUMBER);

View file

@ -5,6 +5,8 @@
#include "SQLiteXS.h" #include "SQLiteXS.h"
START_MY_CXT;
DBISTATE_DECLARE; DBISTATE_DECLARE;
#define SvPV_nolen_undef_ok(x) (SvOK(x) ? SvPV_nolen(x) : "undef") #define SvPV_nolen_undef_ok(x) (SvOK(x) ? SvPV_nolen(x) : "undef")
@ -24,12 +26,6 @@ DBISTATE_DECLARE;
#endif #endif
/*-----------------------------------------------------*
* Globals
*-----------------------------------------------------*/
static int last_dbh_is_unicode; /* see _last_dbh_is_unicode() */
/*-----------------------------------------------------* /*-----------------------------------------------------*
* Helper Methods * Helper Methods
*-----------------------------------------------------*/ *-----------------------------------------------------*/
@ -195,14 +191,6 @@ int _sqlite_atoi64(const char *zNum, sqlite3_int64 *pNum) {
} }
} }
int _last_dbh_is_unicode() {
/* some functions need to know if the unicode flag is on, but
don't have a dbh pointer ... so unfortunately the only way is
to use a global variable */
return last_dbh_is_unicode;
}
static void static void
_sqlite_trace(pTHX_ char *file, int line, SV *h, imp_xxh_t *imp_xxh, const char *what) _sqlite_trace(pTHX_ char *file, int line, SV *h, imp_xxh_t *imp_xxh, const char *what)
{ {
@ -297,10 +285,12 @@ sqlite_type_from_odbc_type(int type)
} }
} }
void
init_cxt() {
dTHX;
MY_CXT_INIT;
MY_CXT.last_dbh_is_unicode = 0;
}
SV * SV *
stacked_sv_from_sqlite3_value(pTHX_ sqlite3_value *value, int is_unicode) stacked_sv_from_sqlite3_value(pTHX_ sqlite3_value *value, int is_unicode)
@ -856,13 +846,14 @@ int
sqlite_st_prepare_sv(SV *sth, imp_sth_t *imp_sth, SV *sv_statement, SV *attribs) sqlite_st_prepare_sv(SV *sth, imp_sth_t *imp_sth, SV *sv_statement, SV *attribs)
{ {
dTHX; dTHX;
dMY_CXT;
int rc = 0; int rc = 0;
const char *extra; const char *extra;
char *statement; char *statement;
stmt_list_s * new_stmt; stmt_list_s * new_stmt;
D_imp_dbh_from_sth; D_imp_dbh_from_sth;
last_dbh_is_unicode = imp_dbh->unicode; MY_CXT.last_dbh_is_unicode = imp_dbh->unicode;
if (!DBIc_ACTIVE(imp_dbh)) { if (!DBIc_ACTIVE(imp_dbh)) {
sqlite_error(sth, -2, "attempt to prepare on inactive database handle"); sqlite_error(sth, -2, "attempt to prepare on inactive database handle");
@ -2748,6 +2739,7 @@ static int perl_tokenizer_Open(
){ ){
dTHX; dTHX;
dSP; dSP;
dMY_CXT;
U32 flags; U32 flags;
SV *perl_string; SV *perl_string;
int n_retval; int n_retval;
@ -2764,7 +2756,7 @@ static int perl_tokenizer_Open(
flags = SVs_TEMP; /* will call sv_2mortal */ flags = SVs_TEMP; /* will call sv_2mortal */
/* special handling if working with utf8 strings */ /* special handling if working with utf8 strings */
if (_last_dbh_is_unicode()) { if (MY_CXT.last_dbh_is_unicode) {
/* data to keep track of byte offsets */ /* data to keep track of byte offsets */
c->lastByteOffset = c->pInput = pInput; c->lastByteOffset = c->pInput = pInput;
@ -3322,8 +3314,9 @@ static int perl_vt_Filter( sqlite3_vtab_cursor *pVtabCursor,
int argc, sqlite3_value **argv ){ int argc, sqlite3_value **argv ){
dTHX; dTHX;
dSP; dSP;
dMY_CXT;
int i, count; int i, count;
int is_unicode = _last_dbh_is_unicode(); int is_unicode = MY_CXT.last_dbh_is_unicode;
ENTER; ENTER;
SAVETMPS; SAVETMPS;
@ -3476,8 +3469,9 @@ static int perl_vt_Update( sqlite3_vtab *pVTab,
sqlite3_int64 *pRowid ){ sqlite3_int64 *pRowid ){
dTHX; dTHX;
dSP; dSP;
dMY_CXT;
int count, i; int count, i;
int is_unicode = _last_dbh_is_unicode(); int is_unicode = MY_CXT.last_dbh_is_unicode;
int rc = SQLITE_ERROR; int rc = SQLITE_ERROR;
SV *rowidsv; SV *rowidsv;
@ -3545,6 +3539,7 @@ static int perl_vt_FindFunction(sqlite3_vtab *pVTab,
void **ppArg){ void **ppArg){
dTHX; dTHX;
dSP; dSP;
dMY_CXT;
int count; int count;
int is_overloaded = 0; int is_overloaded = 0;
char *func_name = sqlite3_mprintf("%s\t%d", zName, nArg); char *func_name = sqlite3_mprintf("%s\t%d", zName, nArg);
@ -3592,7 +3587,7 @@ static int perl_vt_FindFunction(sqlite3_vtab *pVTab,
/* return function information for sqlite3 within *pxFunc and *ppArg */ /* return function information for sqlite3 within *pxFunc and *ppArg */
is_overloaded = coderef && SvTRUE(coderef); is_overloaded = coderef && SvTRUE(coderef);
if (is_overloaded) { if (is_overloaded) {
*pxFunc = _last_dbh_is_unicode() ? sqlite_db_func_dispatcher_unicode *pxFunc = MY_CXT.last_dbh_is_unicode ? sqlite_db_func_dispatcher_unicode
: sqlite_db_func_dispatcher_no_unicode; : sqlite_db_func_dispatcher_no_unicode;
*ppArg = coderef; *ppArg = coderef;
} }

View file

@ -5,6 +5,12 @@
#include "SQLiteXS.h" #include "SQLiteXS.h"
#include "sqlite3.h" #include "sqlite3.h"
#define MY_CXT_KEY "DBD::SQLite::_guts" XS_VERSION
typedef struct {
int last_dbh_is_unicode;
} my_cxt_t;
#define PERL_UNICODE_DOES_NOT_WORK_WELL \ #define PERL_UNICODE_DOES_NOT_WORK_WELL \
(PERL_REVISION <= 5) && ((PERL_VERSION < 8) \ (PERL_REVISION <= 5) && ((PERL_VERSION < 8) \
|| (PERL_VERSION == 8 && PERL_SUBVERSION < 5)) || (PERL_VERSION == 8 && PERL_SUBVERSION < 5))