From 1c50bae61b3a18122a53009622f54842c3c77bdc Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Fri, 21 May 2010 03:58:11 +0000 Subject: [PATCH] returning an array should be better --- SQLite.xs | 15 ++++++++++++--- dbdimp.c | 17 +++++++---------- lib/DBD/SQLite.pm | 2 +- t/01_compile.t | 4 ++-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/SQLite.xs b/SQLite.xs index 5ed928e..32b452f 100644 --- a/SQLite.xs +++ b/SQLite.xs @@ -205,11 +205,20 @@ MODULE = DBD::SQLite PACKAGE = DBD::SQLite PROTOTYPES: ENABLE -SV * +static int compile_options() CODE: - ST(0) = (SV*)sqlite_compile_options(); - XSRETURN(1); + int n = 0; + AV* av = (AV*)sqlite_compile_options(); + if (av) { + int i; + n = AvFILL(av) + 1; + EXTEND(sp, n); + for (i = 0; i < n; i++) { + PUSHs(AvARRAY(av)[i]); + } + } + XSRETURN(n); static int OK() diff --git a/dbdimp.c b/dbdimp.c index 6d8b4f4..64e8ed6 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -990,26 +990,23 @@ sqlite_bind_col(SV *sth, imp_sth_t *imp_sth, SV *col, SV *ref, IV sql_type, SV * * Driver Private Methods *-----------------------------------------------------*/ -SV * +AV * sqlite_compile_options() { dTHX; int i = 0; const char *option; - -#if SQLITE_VERSION_NUMBER < 3006023 - return &PL_sv_undef; -#endif -#ifdef SQLITE_OMIT_COMPILEOPTION_DIAGS - return &PL_sv_undef; -#endif - AV *av = newAV(); + +#if SQLITE_VERSION_NUMBER >= 3006023 +#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS while(option = sqlite3_compileoption_get(i++)) { av_push(av, newSVpv(option, 0)); } +#endif +#endif - return sv_2mortal(newRV_noinc((SV*)av)); + return (AV*)sv_2mortal((SV*)av); } int diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index 279afae..a262040 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -1442,7 +1442,7 @@ sqlite3 extensions. After the call, you can load extensions like this: =head2 DBD::SQLite::compile_options() -Returns an array reference of compile options (available since sqlite 3.6.23, +Returns an array of compile options (available since sqlite 3.6.23, bundled in DBD::SQLite 1.30_01), or undef if the bundled library is old or compiled with SQLITE_OMIT_COMPILEOPTION_DIAGS. diff --git a/t/01_compile.t b/t/01_compile.t index 7c6e35d..eab165c 100644 --- a/t/01_compile.t +++ b/t/01_compile.t @@ -17,7 +17,7 @@ use_ok('t::lib::Test'); diag("\$DBI::VERSION=$DBI::VERSION"); -if (my $compile_options = DBD::SQLite::compile_options()) { +if (my @compile_options = DBD::SQLite::compile_options()) { diag("Compile Options:"); - diag(join "", map { " $_\n" } @$compile_options); + diag(join "", map { " $_\n" } @compile_options); }