develooper Front page | perl.perl5.porters | Postings from November 2003

Re: DBI and UNIVERSAL::AUTOLOAD (was Re: [5.8.12] Proposal for changing UNIVERSAL semantics)

Thread Previous | Thread Next
From:
Tim Bunce
Date:
November 6, 2003 05:53
Subject:
Re: DBI and UNIVERSAL::AUTOLOAD (was Re: [5.8.12] Proposal for changing UNIVERSAL semantics)
Message ID:
20031106135219.GD13886@dansat.data-plan.com
On Tue, Nov 04, 2003 at 02:20:12PM -0800, Michael G Schwern wrote:
> On Tue, Nov 04, 2003 at 03:26:16PM +0000, Tim Bunce wrote:
> > I'm not convinced. Here's the code for can() that's embedded into the DBI
> > dispatcher:

Found it. The DBI was using gv_fetchmethod() where it should have
been using gv_fetchmethod_autoload(..., FALSE). I've fixed it for
DBI 1.39 which I'll release in a day or so, all being well.

The Changes file says

  Fixed DBI dispatch to not try to use AUTOLOAD for driver methods unless
    the method has been declared (as methods should be when using AUTOLOAD).
    This fixes a problem when the Attribute::Handlers module is loaded.

Thanks!

I've appended a patch. I'd be grateful if people could try it out.

Tim.


--- DBI.xs	2003/10/21 15:13:43	11.33
+++ DBI.xs	2003/11/06 13:24:42
@@ -2189,7 +2189,7 @@
 		    char *can_meth = SvPV(st1,lna);
 		    SV *dbi_msv = Nullsv;
 		    SV	*imp_msv; /* handle implementors method (GV or CV) */
-		    if ( (imp_msv = (SV*)gv_fetchmethod(DBIc_IMP_STASH(imp_xxh), can_meth)) ) {
+		    if ( (imp_msv = (SV*)gv_fetchmethod_autoload(DBIc_IMP_STASH(imp_xxh), can_meth, FALSE)) ) {
 			/* return DBI's CV, not the implementors CV (else we'd bypass dispatch) */
 			/* and anyway, we may have hit a private method not part of the DBI	*/
 			GV *gv = gv_fetchmethod_autoload(SvSTASH(SvRV(orig_h)), can_meth, FALSE);
@@ -2201,10 +2201,8 @@
 			PerlIO_printf(logfp,"    <- %s(%s) = %p (%s %p)\n", meth_name, can_meth, dbi_msv,
 				(imp_msv && isGV(imp_msv)) ? HvNAME(GvSTASH(imp_msv)) : "?", imp_msv);
 		    }
-		    if (dbi_msv) {
-			ST(0) = sv_2mortal(newRV(dbi_msv));
-			XSRETURN(1);
-		    }
+		    ST(0) = (dbi_msv) ? sv_2mortal(newRV(dbi_msv)) : &PL_sv_undef;
+		    XSRETURN(1);
 		}
 		XSRETURN(0);
 	    }
@@ -2360,7 +2364,7 @@
 	    }
 	}
 
-	imp_msv = (SV*)gv_fetchmethod(DBIc_IMP_STASH(imp_xxh), meth_name);
+	imp_msv = (SV*)gv_fetchmethod_autoload(DBIc_IMP_STASH(imp_xxh), meth_name, FALSE);
 
 	if (debug >= 2) {
 	    PerlIO *logfp = DBILOGFP;

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About