⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 berkeleydb.xs

📁 linux 下的源代码分析阅读器 red hat公司新版
💻 XS
📖 第 1 页 / 共 5 页
字号:
#ifndef newSVpvn    /* As newSVpv will assume that the data pointer is a null terminated C       string if the size parameter is 0, make sure that data points to an       empty string if the length is 0    */    if (key1->size == 0)        data1 = "" ;    if (key2->size == 0)        data2 = "" ;#endif    ENTER ;    SAVETMPS;    PUSHMARK(SP) ;    EXTEND(SP,2) ;    PUSHs(sv_2mortal(newSVpvn(data1,key1->size)));    PUSHs(sv_2mortal(newSVpvn(data2,key2->size)));    PUTBACK ;    count = perl_call_sv(getCurrentDB->dup_compare, G_SCALAR);    SPAGAIN ;    if (count != 1)        softCrash ("dup_compare: expected 1 return value from compare sub, got %d", count) ;    retval = POPi ;    PUTBACK ;    FREETMPS ;    LEAVE ;    /* CurrentDB = keepDB ; */    return (retval) ;}static size_tbtree_prefix(DB_callback const DBT * key1, const DBT * key2 ){#ifdef dTHX    dTHX;#endif        dSP ;    dMY_CXT ;        char * data1, * data2 ;    int retval ;    int count ;    /* BerkeleyDB	keepDB = CurrentDB ; */    Trace(("In btree_prefix \n")) ;    data1 = (char*) key1->data ;    data2 = (char*) key2->data ;#ifndef newSVpvn    /* As newSVpv will assume that the data pointer is a null terminated C       string if the size parameter is 0, make sure that data points to an       empty string if the length is 0    */    if (key1->size == 0)        data1 = "" ;    if (key2->size == 0)        data2 = "" ;#endif    ENTER ;    SAVETMPS;    PUSHMARK(SP) ;    EXTEND(SP,2) ;    PUSHs(sv_2mortal(newSVpvn(data1,key1->size)));    PUSHs(sv_2mortal(newSVpvn(data2,key2->size)));    PUTBACK ;    count = perl_call_sv(getCurrentDB->prefix, G_SCALAR);    SPAGAIN ;    if (count != 1)        softCrash ("btree_prefix: expected 1 return value from prefix sub, got %d", count) ;    retval = POPi ;    PUTBACK ;    FREETMPS ;    LEAVE ;    /* CurrentDB = keepDB ; */    return (retval) ;}static u_int32_thash_cb(DB_callback const void * data, u_int32_t size){#ifdef dTHX    dTHX;#endif        dSP ;    dMY_CXT ;        int retval ;    int count ;    /* BerkeleyDB	keepDB = CurrentDB ; */    Trace(("In hash_cb \n")) ;#ifndef newSVpvn    if (size == 0)        data = "" ;#endif    ENTER ;    SAVETMPS;    PUSHMARK(SP) ;    XPUSHs(sv_2mortal(newSVpvn((char*)data,size)));    PUTBACK ;    count = perl_call_sv(getCurrentDB->hash, G_SCALAR);    SPAGAIN ;    if (count != 1)        softCrash ("hash_cb: expected 1 return value from hash sub, got %d", count) ;    retval = POPi ;    PUTBACK ;    FREETMPS ;    LEAVE ;    /* CurrentDB = keepDB ; */    return (retval) ;}#ifdef AT_LEAST_DB_3_3static intassociate_cb(DB_callback const DBT * pkey, const DBT * pdata, DBT * skey){#ifdef dTHX    dTHX;#endif        dSP ;    dMY_CXT ;        char * pk_dat, * pd_dat ;    /* char *sk_dat ; */    int retval ;    int count ;    SV * skey_SV ;    STRLEN skey_len;    char * skey_ptr ;    Trace(("In associate_cb \n")) ;    if (getCurrentDB->associated == NULL){        Trace(("No Callback registered\n")) ;        return EINVAL ;    }    skey_SV = newSVpv("",0);    pk_dat = (char*) pkey->data ;    pd_dat = (char*) pdata->data ;#ifndef newSVpvn    /* As newSVpv will assume that the data pointer is a null terminated C       string if the size parameter is 0, make sure that data points to an       empty string if the length is 0    */    if (pkey->size == 0)        pk_dat = "" ;    if (pdata->size == 0)        pd_dat = "" ;#endif    ENTER ;    SAVETMPS;    PUSHMARK(SP) ;    EXTEND(SP,2) ;    PUSHs(sv_2mortal(newSVpvn(pk_dat,pkey->size)));    PUSHs(sv_2mortal(newSVpvn(pd_dat,pdata->size)));    PUSHs(sv_2mortal(skey_SV));    PUTBACK ;    Trace(("calling associated cb\n"));    count = perl_call_sv(getCurrentDB->associated, G_SCALAR);    Trace(("called associated cb\n"));    SPAGAIN ;    if (count != 1)        softCrash ("associate: expected 1 return value from prefix sub, got %d", count) ;    retval = POPi ;    PUTBACK ;        /* retrieve the secondary key */    DBT_clear(*skey);    skey_ptr = SvPV(skey_SV, skey_len);    skey->flags = DB_DBT_APPMALLOC;    /* skey->size = SvCUR(skey_SV); */    /* skey->data = (char*)safemalloc(skey->size); */    skey->size = skey_len;    skey->data = (char*)safemalloc(skey_len);    memcpy(skey->data, skey_ptr, skey_len);    Trace(("key is %d -- %.*s\n", skey->size, skey->size, skey->data));    FREETMPS ;    LEAVE ;    return (retval) ;}static intassociate_cb_recno(DB_callback const DBT * pkey, const DBT * pdata, DBT * skey){#ifdef dTHX    dTHX;#endif        dSP ;    dMY_CXT ;        char * pk_dat, * pd_dat ;    /* char *sk_dat ; */    int retval ;    int count ;    SV * skey_SV ;    STRLEN skey_len;    char * skey_ptr ;    /* db_recno_t Value; */    Trace(("In associate_cb_recno \n")) ;    if (getCurrentDB->associated == NULL){        Trace(("No Callback registered\n")) ;        return EINVAL ;    }    skey_SV = newSVpv("",0);    pk_dat = (char*) pkey->data ;    pd_dat = (char*) pdata->data ;#ifndef newSVpvn    /* As newSVpv will assume that the data pointer is a null terminated C       string if the size parameter is 0, make sure that data points to an       empty string if the length is 0    */    if (pkey->size == 0)        pk_dat = "" ;    if (pdata->size == 0)        pd_dat = "" ;#endif    ENTER ;    SAVETMPS;    PUSHMARK(SP) ;    EXTEND(SP,2) ;    PUSHs(sv_2mortal(newSVpvn(pk_dat,pkey->size)));    PUSHs(sv_2mortal(newSVpvn(pd_dat,pdata->size)));    PUSHs(sv_2mortal(skey_SV));    PUTBACK ;    Trace(("calling associated cb\n"));    count = perl_call_sv(getCurrentDB->associated, G_SCALAR);    Trace(("called associated cb\n"));    SPAGAIN ;    if (count != 1)        softCrash ("associate: expected 1 return value from prefix sub, got %d", count) ;    retval = POPi ;    PUTBACK ;        /* retrieve the secondary key */    DBT_clear(*skey);    Value = GetRecnoKey(getCurrentDB, SvIV(skey_SV)) ;     skey->flags = DB_DBT_APPMALLOC;    skey->size = (int)sizeof(db_recno_t);    skey->data = (char*)safemalloc(skey->size);    memcpy(skey->data, &Value, skey->size);    FREETMPS ;    LEAVE ;    return (retval) ;}#endif /* AT_LEAST_DB_3_3 */static void#ifdef AT_LEAST_DB_4_3db_errcall_cb(const DB_ENV* dbenv, const char * db_errpfx, const char * buffer)#elsedb_errcall_cb(const char * db_errpfx, char * buffer)#endif{    Trace(("In errcall_cb \n")) ;#if 0    if (db_errpfx == NULL)	db_errpfx = "" ;    if (buffer == NULL )	buffer = "" ;    ErrBuff[0] = '\0';    if (strlen(db_errpfx) + strlen(buffer) + 3 <= 1000) {	if (*db_errpfx != '\0') {	    strcat(ErrBuff, db_errpfx) ;	    strcat(ErrBuff, ": ") ;	}	strcat(ErrBuff, buffer) ;    }#endif    SV * sv = perl_get_sv(ERR_BUFF, FALSE) ;    if (sv) {        if (db_errpfx)	    sv_setpvf(sv, "%s: %s", db_errpfx, buffer) ;        else            sv_setpv(sv, buffer) ;    }}static SV *readHash(HV * hash, char * key){    SV **       svp;    svp = hv_fetch(hash, key, strlen(key), FALSE);    if (svp && SvOK(*svp))        return *svp ;    return NULL ;}static voidhash_delete(char * hash, char * key){    HV * hv = perl_get_hv(hash, TRUE);    (void) hv_delete(hv, (char*)&key, sizeof(key), G_DISCARD);}static voidhash_store_iv(char * hash, char * key, IV value){    HV * hv = perl_get_hv(hash, TRUE);    (void)hv_store(hv, (char*)&key, sizeof(key), newSViv(value), 0);    /* printf("hv_store returned %d\n", ret) ; */}static voidhv_store_iv(HV * hash, char * key, IV value){    hv_store(hash, key, strlen(key), newSViv(value), 0);}#if 0static voidhv_store_uv(HV * hash, char * key, UV value){    hv_store(hash, key, strlen(key), newSVuv(value), 0);}#endifstatic voidGetKey(BerkeleyDB_type * db, SV * sv, DBTKEY * key){    dMY_CXT ;        if (db->recno_or_queue) {        Value = GetRecnoKey(db, SvIV(sv)) ;         key->data = & Value;         key->size = (int)sizeof(db_recno_t);    }    else {        key->data = SvPV(sv, PL_na);        key->size = (int)PL_na;    }}static BerkeleyDBmy_db_open(		BerkeleyDB	db ,		SV * 		ref,		SV *		ref_dbenv ,		BerkeleyDB__Env	dbenv ,    	    	BerkeleyDB__Txn txn, 		const char *	file,		const char *	subname,		DBTYPE		type,		int		flags,		int		mode,		DB_INFO * 	info,		char *		password,		int		enc_flags	){    DB_ENV *	env    = NULL ;    BerkeleyDB 	RETVAL = NULL ;    DB *	dbp ;    int		Status ;    DB_TXN* 	txnid = NULL ;    dMY_CXT;    Trace(("_db_open(dbenv[%p] ref_dbenv [%p] file[%s] subname [%s] type[%d] flags[%d] mode[%d]\n",		dbenv, ref_dbenv, file, subname, type, flags, mode)) ;        if (dbenv)	env = dbenv->Env ;    if (txn)        txnid = txn->txn;    Trace(("_db_open(dbenv[%p] ref_dbenv [%p] txn [%p] file[%s] subname [%s] type[%d] flags[%d] mode[%d]\n",		dbenv, ref_dbenv, txn, file, subname, type, flags, mode)) ;#if DB_VERSION_MAJOR == 2    if (subname)        softCrash("Subname needs Berkeley DB 3 or better") ;#endif#ifndef AT_LEAST_DB_4_1	    if (password)	        softCrash("-Encrypt needs Berkeley DB 4.x or better") ;#endif /* ! AT_LEAST_DB_4_1 */#ifndef AT_LEAST_DB_3_2    CurrentDB = db ;#endif#if DB_VERSION_MAJOR > 2    Trace(("creating\n"));    Status = db_create(&dbp, env, 0) ;    Trace(("db_create returned %s\n", my_db_strerror(Status))) ;    if (Status)        return RETVAL ;#ifdef AT_LEAST_DB_3_2	dbp->BackRef = db;#endif#ifdef AT_LEAST_DB_3_3    if (! env) {	dbp->set_alloc(dbp, safemalloc, MyRealloc, safefree) ;	dbp->set_errcall(dbp, db_errcall_cb) ;    }#endif#ifdef AT_LEAST_DB_4_1    /* set encryption */    if (password)    {        Status = dbp->set_encrypt(dbp, password, enc_flags);        Trace(("DB->set_encrypt passwd = %s, flags %d returned %s\n", 			      		password, enc_flags,  					my_db_strerror(Status))) ;         if (Status)              return RETVAL ;    }#endif	      if (info->re_source) {        Status = dbp->set_re_source(dbp, info->re_source) ;	Trace(("set_re_source [%s] returned %s\n",		info->re_source, my_db_strerror(Status)));        if (Status)            return RETVAL ;    }    if (info->db_cachesize) {        Status = dbp->set_cachesize(dbp, 0, info->db_cachesize, 0) ;	Trace(("set_cachesize [%d] returned %s\n",		info->db_cachesize, my_db_strerror(Status)));        if (Status)            return RETVAL ;    }    if (info->db_lorder) {        Status = dbp->set_lorder(dbp, info->db_lorder) ;	Trace(("set_lorder [%d] returned %s\n",		info->db_lorder, my_db_strerror(Status)));        if (Status)            return RETVAL ;    }    if (info->db_pagesize) {        Status = dbp->set_pagesize(dbp, info->db_pagesize) ;	Trace(("set_pagesize [%d] returned %s\n",		info->db_pagesize, my_db_strerror(Status)));        if (Status)            return RETVAL ;    }    if (info->h_ffactor) {        Status = dbp->set_h_ffactor(dbp, info->h_ffactor) ;	Trace(("set_h_ffactor [%d] returned %s\n",		info->h_ffactor, my_db_strerror(Status)));        if (Status)            return RETVAL ;    }    if (info->h_nelem) {        Status = dbp->set_h_nelem(dbp, info->h_nelem) ;	Trace(("set_h_nelem [%d] returned %s\n",		info->h_nelem, my_db_strerror(Status)));        if (Status)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -