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.32 2006/03/18 22:34:27 grubba Exp $ + || $Id: gdbmmod.c,v 1.33 2007/04/25 15:33:22 grubba Exp $   */      #include "global.h"   #include "gdbm_machine.h"   #include "threads.h"      /* Todo: make sure only one thread accesses the same gdbmmod */      #include "interpret.h"   #include "svalue.h"
pike.git/src/modules/Gdbm/gdbmmod.c:342:    pop_n_elems(args);    if(ret.dptr)    {    push_string(DATUM_TO_STRING(ret));    free(ret.dptr);    }else{    push_int(0);    }   }    - /*! @decl int store(string key, string data) -  *! @decl int `[]= (string key, string data) + /*! @decl string `[]= (string key, string data)    *!    *! Associate the contents of 'data' with the key 'key'. If the key 'key'    *! already exists in the database the data for that key will be replaced.    *! If it does not exist it will be added. An error will be generated if    *! the database was not open for writing.    *!    *! @example    *! gdbm[key] = data; -  +  *! +  *! @returns +  *! Returns @[data] on success. +  *! +  *! @seealso +  *! @[store()]    */    -  + /*! @decl int store(string key, string data) +  *! +  *! Associate the contents of 'data' with the key 'key'. If the key 'key' +  *! already exists in the database the data for that key will be replaced. +  *! If it does not exist it will be added. An error will be generated if +  *! the database was not open for writing. +  *! +  *! @example +  *! gdbm->store(key, data); +  *! +  *! @returns +  *! Returns @expr{1@} on success. +  *! +  *! @note +  *! Note that the returned value differs from that of @[`[]=()]. +  *! +  *! @seealso +  *! @[`[]=()] +  */ +    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.git/src/modules/Gdbm/gdbmmod.c:395:    mt_lock(& gdbm_lock);    ret=gdbm_store(this->dbf, key, data, method);    mt_unlock(& gdbm_lock);    THREADS_DISALLOW();       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); +  ref_push_string(sp[1-args].u.string); +  stack_pop_n_elems_keep_top(args);   }    -  + /* Compat */ + static void gdbmmod_store_compat(INT32 args) + { +  gdbmmod_store(args); +  pop_stack(); +  push_int(1); + } +    /*! @decl int reorganize()    *!    *! Deletions and insertions into the database can cause fragmentation    *! which will make the database bigger. This routine reorganizes the    *! contents to get rid of fragmentation. Note however that this function    *! can take a LOT of time to run.    */      static void gdbmmod_reorganize(INT32 args)   {
pike.git/src/modules/Gdbm/gdbmmod.c:491: Inside #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 /*ID_STATIC*/);       /* function(:void) */    ADD_FUNCTION("close",gdbmmod_close,tFunc(tNone,tVoid),0);    /* function(string, string, int(0..1)|void: int) */ -  ADD_FUNCTION("store", gdbmmod_store, +  ADD_FUNCTION("store", gdbmmod_store_compat,    tFunc(tStr tStr tOr(tInt01, tVoid), tInt), 0); -  /* function(string, string, int(0..1)|void: int) */ +  /* function(string, string, int(0..1)|void: string) */    ADD_FUNCTION("`[]=", gdbmmod_store, -  tFunc(tStr tStr tOr(tInt01, tVoid), tInt), 0); +  tFunc(tStr tSetvar(0, tStr) tOr(tInt01, tVoid), tVar(0)), 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,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);