On Fri, Mar 25, 2005 at 04:37:29PM -0500, Stas Bekman wrote:
> 
> >>Should it be something like (and replace ??):
> >>
> >> SV *dbd_take_imp_data(SV *h, imp_xxh_t *imp_xxh, ?? ??)
> >
> >It can return a plain int as all it's doing is 'preparing' for
> >the DBIs default take_imp_data to do the actual brain surgery.
> 
> Now I've lost you, Tim, how can the DBIs default take_imp_data do the 
> surgery w/o knowing the details of the driver?

Because it removes (disconnects and returns) the whole imp_xxh structure. 
A simple and clean cut. I've appended the code. Hopefully the comments
will help explain the context.

Tim.

void
take_imp_data(h)
    SV *        h
    PREINIT:
    /* take_imp_data currently in DBD::_::db not DBD::_::common, so for dbh's 
only */
    D_imp_xxh(h);
    MAGIC *mg;
    SV *imp_xxh_sv;
    CODE:
    /*
    If the drivers imp data contains SV*'s, or other interpreter
    specific items, they should be freed by the drivers own take_imp_data
    method before it calls SUPER::take_imp_data to finalize the removal.
    The driver needs to view the take_imp_data method as being
    nearly the same as disconnect+DESTROY only not actually calling
    the database API to disconnect.
    All that needs to remain is the underlying database API connection data.
    Everything else should in a 'clean' state such that if the drivers
    own DESTROY method instead of take_imp_data, it would be able to
    properly handle the contents of the structure. This is important in case
    a new handle created using this imp_data, possibly in a new thread, might
    end up being DESTROY's before the driver has had a chance to 're-setup'
    the data. See dbih_setup_handle()
    */
    if (DBIc_TYPE(imp_xxh) <= DBIt_DB && DBIc_CACHED_KIDS((imp_dbh_t*)imp_xxh))
        clear_cached_kids(h, imp_xxh, "take_imp_data", 0);
    if (DBIc_KIDS(imp_xxh)) {   /* safety check, may be relaxed later to 
DBIc_ACTIVE_KIDS */
        set_err_char(h, imp_xxh, "1", 1, "Can't take_imp_data from handle while 
it still has kids", 0, "take_imp_data");
        XSRETURN(0);
    }
    dbih_getcom2(h, &mg);       /* get the MAGIC so we can change it    */
    imp_xxh_sv = mg->mg_obj;    /* take local copy of the imp_data pointer */
    mg->mg_obj = Nullsv;        /* sever the link from handle to imp_xxh */
    if (DBIc_TRACE_LEVEL(imp_xxh))
        sv_dump(imp_xxh_sv);
    /* --- housekeeping */
    DBIc_ACTIVE_off(imp_xxh);   /* silence warning from dbih_clearcom */
    DBIc_IMPSET_off(imp_xxh);   /* silence warning from dbih_clearcom */
    dbih_clearcom(imp_xxh);     /* free SVs like DBD::_mem::common::DESTROY */
    SvOBJECT_off(imp_xxh_sv);   /* no longer needs DESTROY via dbih_clearcom */
    DBIc_IMPSET_on(imp_xxh);    /* to mark fact imp data still present */
    /* --- tidy up the raw PV for life as a more normal string */
    SvPOK_on(imp_xxh_sv);
    SvCUR_set(imp_xxh_sv, SvLEN(imp_xxh_sv)-1); /* SvLEN(imp_xxh_sv)-1 == 
imp_size */
    *SvEND(imp_xxh_sv) = '\0';
    /* --- return the actual imp_xxh_sv on the stack */
    ST(0) = imp_xxh_sv;

Reply via email to