pike.git / src / modules / Gdbm / gdbmmod.c

version» Context lines:

pike.git/src/modules/Gdbm/gdbmmod.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: gdbmmod.c,v 1.24 2003/04/07 17:25:04 nilsson Exp $ + || $Id: gdbmmod.c,v 1.25 2003/05/25 02:58:06 nilsson Exp $   */      #include "global.h" - RCSID("$Id: gdbmmod.c,v 1.24 2003/04/07 17:25:04 nilsson Exp $"); + RCSID("$Id: gdbmmod.c,v 1.25 2003/05/25 02:58:06 nilsson Exp $");   #include "gdbm_machine.h"   #include "threads.h"      /* Todo: make sure only one thread accesses the same gdbmmod */      #include "interpret.h"   #include "svalue.h"   #include "stralloc.h"   #include "array.h"   #include "object.h"
pike.git/src/modules/Gdbm/gdbmmod.c:161:    mt_lock(& gdbm_lock);    tmp=gdbm_open(tmp2->str, 512, rwmode, 00666, gdbmmod_fatal);    mt_unlock(& gdbm_lock);    THREADS_DISALLOW();       if(!Pike_fp->current_object->prog)    {    if(tmp) gdbm_close(tmp);    Pike_error("Object destructed in gdbm->open()n");    } -  THIS->dbf=tmp; +  this->dbf=tmp;       pop_n_elems(args); -  if(!THIS->dbf) +  if(!this->dbf)    Pike_error("Failed to open GDBM database.\n");    }   }      #define STRING_TO_DATUM(dat, st) dat.dptr=st->str,dat.dsize=st->len;   #define DATUM_TO_STRING(dat) make_shared_binary_string(dat.dptr, dat.dsize)      /*! @decl string fetch(string key)    *! @decl string `[](string key)    *!
pike.git/src/modules/Gdbm/gdbmmod.c:211:    pop_n_elems(args);    if(ret.dptr)    {    push_string(DATUM_TO_STRING(ret));    free(ret.dptr);    }else{    push_int(0);    }   }    - /*! @decl int delete(string key) + /*! @decl int(0..1) delete(string key)    *! -  *! Remove a key from the database. Note that no error will be generated -  *! if the key does not exist. +  *! Remove a key from the database. Returns 1 if successful, +  *! otherwise 0, e.g. when the item is not present or the +  *! database is read only.    */      static void gdbmmod_delete(INT32 args)   {    struct gdbm_glue *this=THIS;    datum key;    int ret;    if(!args)    Pike_error("Too few arguments to gdbm->delete()\n");   
pike.git/src/modules/Gdbm/gdbmmod.c:240:       STRING_TO_DATUM(key, sp[-args].u.string);       THREADS_ALLOW();    mt_lock(& gdbm_lock);    ret=gdbm_delete(this->dbf, key);    mt_unlock(& gdbm_lock);    THREADS_DISALLOW();       pop_n_elems(args); -  push_int(0); +  push_int( ret==0 );   }      /*! @decl string firstkey()    *!    *! Return the first key in the database, this can be any key in the    *! database.    */      static void gdbmmod_firstkey(INT32 args)   {
pike.git/src/modules/Gdbm/gdbmmod.c:473: Inside #if defined(HAVE_GDBM_H) && defined(HAVE_LIBGDBM)
   ADD_FUNCTION("store", gdbmmod_store,    tFunc(tStr tStr tOr(tInt01, tVoid), tInt), 0);    /* function(string, string, int(0..1)|void: int) */    ADD_FUNCTION("`[]=", gdbmmod_store,    tFunc(tStr tStr tOr(tInt01, tVoid), tInt), 0);    /* function(string:string) */    ADD_FUNCTION("fetch",gdbmmod_fetch,tFunc(tStr,tStr),0);    /* function(string:string) */    ADD_FUNCTION("`[]",gdbmmod_fetch,tFunc(tStr,tStr),0);    /* function(string:int) */ -  ADD_FUNCTION("delete",gdbmmod_delete,tFunc(tStr,tInt),0); +  ADD_FUNCTION("delete",gdbmmod_delete,tFunc(tStr,tInt01),0);    /* function(:string) */    ADD_FUNCTION("firstkey",gdbmmod_firstkey,tFunc(tNone,tStr),0);    /* function(string:string) */    ADD_FUNCTION("nextkey",gdbmmod_nextkey,tFunc(tStr,tStr),0);    /* function(:int) */    ADD_FUNCTION("reorganize",gdbmmod_reorganize,tFunc(tNone,tInt),0);    /* function(:void) */    ADD_FUNCTION("sync",gdbmmod_sync,tFunc(tNone,tVoid),0);       set_init_callback(init_gdbm_glue);    set_exit_callback(exit_gdbm_glue);    end_class("gdbm",0);   #endif   }