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

version» Context lines:

pike.git/src/modules/Gdbm/gdbmmod.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h" - RCSID("$Id: gdbmmod.c,v 1.12 2000/12/01 08:09:56 hubbe Exp $"); + RCSID("$Id: gdbmmod.c,v 1.13 2001/01/23 13:47:31 grubba 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:245:    free(ret.dptr);    }else{    push_int(0);    }   }      static void gdbmmod_store(INT32 args)   {    struct gdbm_glue *this=THIS;    datum key,data; +  int method = GDBM_REPLACE;    int ret;    if(args<2)    Pike_error("Too few arguments to gdbm->store()\n");       if(sp[-args].type != T_STRING)    Pike_error("Bad argument 1 to gdbm->store()\n");       if(sp[1-args].type != T_STRING)    Pike_error("Bad argument 2 to gdbm->store()\n");    -  +  if (args > 2) { +  if (sp[2-args].type != T_INT) { +  Pike_error("Bad argument 3 to gdbm->store()\n"); +  } +  if (sp[2-args].u.integer) { +  method = GDBM_INSERT; +  } +  } +     if(!THIS->dbf)    Pike_error("GDBM database not open.\n");       STRING_TO_DATUM(key, sp[-args].u.string);    STRING_TO_DATUM(data, sp[1-args].u.string);       THREADS_ALLOW();    mt_lock(& gdbm_lock); -  ret=gdbm_store(this->dbf, key, data, GDBM_REPLACE); +  ret=gdbm_store(this->dbf, key, data, method);    mt_unlock(& gdbm_lock);    THREADS_DISALLOW();    -  if(ret == -1) +  if(ret == -1) {    Pike_error("GDBM database not open for writing.\n"); -  +  } else if (ret == 1) { +  Pike_error("Duplicate key.\n"); +  }    pop_n_elems(args);    push_int(ret == 0);   }      static void gdbmmod_reorganize(INT32 args)   {    struct gdbm_glue *this=THIS;    int ret;    pop_n_elems(args);   
pike.git/src/modules/Gdbm/gdbmmod.c:333:      void pike_module_exit(void) {}      void pike_module_init(void)   {   #if defined(HAVE_GDBM_H) && defined(HAVE_LIBGDBM)    start_new_program();    ADD_STORAGE(struct gdbm_glue);       /* function(void|string,void|string:void) */ -  ADD_FUNCTION("create",gdbmmod_create,tFunc(tOr(tVoid,tStr) tOr(tVoid,tStr),tVoid),0); +  ADD_FUNCTION("create", gdbmmod_create, +  tFunc(tOr(tVoid,tStr) tOr(tVoid,tStr), tVoid), ID_STATIC);       /* function(:void) */    ADD_FUNCTION("close",gdbmmod_close,tFunc(tNone,tVoid),0); -  /* function(string,string:int) */ -  ADD_FUNCTION("store",gdbmmod_store,tFunc(tStr tStr,tInt),0); -  /* function(string,string:int) */ -  ADD_FUNCTION("`[]=",gdbmmod_store,tFunc(tStr tStr,tInt),0); +  /* function(string, string, int(0..1)|void: int) */ +  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);    /* function(:string) */    ADD_FUNCTION("firstkey",gdbmmod_firstkey,tFunc(tNone,tStr),0);    /* function(string:string) */    ADD_FUNCTION("nextkey",gdbmmod_nextkey,tFunc(tStr,tStr),0);