@@ -2338,8 +2338,7 @@ static bool mariadb_db_my_login(pTHX_ SV* dbh, imp_dbh_t *imp_dbh)
2338
2338
char * user ;
2339
2339
char * password ;
2340
2340
char * mysql_socket ;
2341
- I32 i ;
2342
- bool found_taken_pmysql ;
2341
+ struct mariadb_list_entry * entry ;
2343
2342
D_imp_xxh (dbh );
2344
2343
D_imp_drh_from_dbh ;
2345
2344
@@ -2349,40 +2348,29 @@ static bool mariadb_db_my_login(pTHX_ SV* dbh, imp_dbh_t *imp_dbh)
2349
2348
{
2350
2349
if (DBIc_TRACE_LEVEL (imp_xxh ) >= 2 )
2351
2350
PerlIO_printf (DBIc_LOGPIO (imp_xxh ), "mariadb_db_my_login skip connect\n" );
2351
+
2352
2352
/* tell our parent we've adopted an active child */
2353
2353
++ DBIc_ACTIVE_KIDS (DBIc_PARENT_COM (imp_dbh ));
2354
- found_taken_pmysql = FALSE;
2355
- if ( imp_drh -> taken_pmysqls )
2354
+
2355
+ for ( entry = imp_drh -> taken_pmysqls ; entry ; entry = entry -> next )
2356
2356
{
2357
- for ( i = AvFILL ( imp_drh -> taken_pmysqls ); i >= 0 ; -- i )
2357
+ if (( MYSQL * ) entry -> data == imp_dbh -> pmysql )
2358
2358
{
2359
- svp = av_fetch (imp_drh -> taken_pmysqls , i , FALSE);
2360
- if (!svp || !* svp )
2361
- continue ;
2362
- SvGETMAGIC (* svp );
2363
- if (!SvIOK (* svp ))
2364
- continue ;
2365
- if (imp_dbh -> pmysql == INT2PTR (MYSQL * , SvIVX (* svp )))
2366
- {
2367
- found_taken_pmysql = TRUE;
2368
- av_delete (imp_drh -> taken_pmysqls , i , G_DISCARD );
2369
- break ;
2370
- }
2359
+ /* Remove MYSQL* entry from taken list */
2360
+ mariadb_list_remove (imp_drh -> taken_pmysqls , entry );
2361
+
2362
+ /* Add imp_dbh entry into active_imp_dbhs list */
2363
+ mariadb_list_add (imp_drh -> active_imp_dbhs , imp_dbh -> list_entry , imp_dbh );
2364
+
2365
+ return TRUE;
2371
2366
}
2372
2367
}
2373
- if (!found_taken_pmysql )
2374
- {
2375
- /* This imp_dbh data belongs to different connection, so destructor should not touch it */
2376
- imp_dbh -> list_entry = NULL ;
2377
- imp_dbh -> pmysql = NULL ;
2378
- mariadb_dr_do_error (dbh , CR_CONNECTION_ERROR , "Connection error: dbi_imp_data is not valid" , "HY000" );
2379
- return FALSE;
2380
- }
2381
-
2382
- /* Add imp_dbh entry into active_imp_dbhs list */
2383
- mariadb_list_add (imp_drh -> active_imp_dbhs , imp_dbh -> list_entry , imp_dbh );
2384
2368
2385
- return TRUE;
2369
+ /* This imp_dbh data belongs to different connection, so destructor should not touch it */
2370
+ imp_dbh -> list_entry = NULL ;
2371
+ imp_dbh -> pmysql = NULL ;
2372
+ mariadb_dr_do_error (dbh , CR_CONNECTION_ERROR , "Connection error: dbi_imp_data is not valid" , "HY000" );
2373
+ return FALSE;
2386
2374
}
2387
2375
if (DBIc_TRACE_LEVEL (imp_xxh ) >= 2 )
2388
2376
PerlIO_printf (DBIc_LOGPIO (imp_xxh ),
@@ -2453,12 +2441,12 @@ SV *mariadb_db_take_imp_data(SV *dbh, imp_xxh_t *imp_xxh, void *foo)
2453
2441
dTHX ;
2454
2442
D_imp_dbh (dbh );
2455
2443
D_imp_drh_from_dbh ;
2444
+ struct mariadb_list_entry * entry ;
2456
2445
PERL_UNUSED_ARG (imp_xxh );
2457
2446
PERL_UNUSED_ARG (foo );
2458
2447
2459
- if (!imp_drh -> taken_pmysqls )
2460
- imp_drh -> taken_pmysqls = newAV ();
2461
- av_push (imp_drh -> taken_pmysqls , newSViv (PTR2IV (imp_dbh -> pmysql )));
2448
+ /* Add MYSQL* into taken list */
2449
+ mariadb_list_add (imp_drh -> taken_pmysqls , entry , imp_dbh -> pmysql );
2462
2450
2463
2451
/* MYSQL* was taken from imp_dbh so remove it also from active_imp_dbhs list */
2464
2452
mariadb_list_remove (imp_drh -> active_imp_dbhs , imp_dbh -> list_entry );
@@ -3096,24 +3084,13 @@ int mariadb_db_disconnect(SV* dbh, imp_dbh_t* imp_dbh)
3096
3084
int mariadb_dr_discon_all (SV * drh , imp_drh_t * imp_drh ) {
3097
3085
dTHX ;
3098
3086
int ret ;
3099
- SV * * svp ;
3100
- I32 i ;
3087
+ struct mariadb_list_entry * entry ;
3101
3088
PERL_UNUSED_ARG (drh );
3102
3089
3103
- if ( imp_drh -> taken_pmysqls )
3090
+ while (( entry = imp_drh -> taken_pmysqls ) )
3104
3091
{
3105
- for (i = AvFILL (imp_drh -> taken_pmysqls ); i >= 0 ; -- i )
3106
- {
3107
- svp = av_fetch (imp_drh -> taken_pmysqls , i , FALSE);
3108
- if (!svp || !* svp )
3109
- continue ;
3110
- SvGETMAGIC (* svp );
3111
- if (!SvIOK (* svp ))
3112
- continue ;
3113
- mariadb_dr_close_mysql (aTHX_ imp_drh , INT2PTR (MYSQL * , SvIVX (* svp )));
3114
- }
3115
- av_undef (imp_drh -> taken_pmysqls );
3116
- imp_drh -> taken_pmysqls = NULL ;
3092
+ mariadb_dr_close_mysql (aTHX_ imp_drh , (MYSQL * )entry -> data );
3093
+ mariadb_list_remove (imp_drh -> taken_pmysqls , entry );
3117
3094
}
3118
3095
3119
3096
while (imp_drh -> active_imp_dbhs )
0 commit comments