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

version» Context lines:

pike.git/src/modules/Gdbm/gdbmmod.c:381:    THREADS_ALLOW();    mt_lock(& gdbm_lock);    ret=gdbm_firstkey(this->dbf);    mt_unlock(& gdbm_lock);    THREADS_DISALLOW();       if(ret.dptr)    {    push_string(DATUM_TO_STRING(ret));    free(ret.dptr); -  }else{ -  push_int(0); +  } else { +  push_undefined();    }   }      /*! @decl string(8bit) nextkey(string(8bit) key)    *!    *! This returns the key in database that follows the key 'key' key.    *! This is of course used to iterate over all keys in the database.    *!    *! @note    *! Changing (adding or removing keys) the database while iterating
pike.git/src/modules/Gdbm/gdbmmod.c:440:    mt_lock(& gdbm_lock);    ret=gdbm_nextkey(this->dbf, key);    mt_unlock(& gdbm_lock);    THREADS_DISALLOW();       pop_n_elems(args);    if(ret.dptr)    {    push_string(DATUM_TO_STRING(ret));    free(ret.dptr); -  }else{ -  push_int(0); +  } else { +  push_undefined();    }   }      /*! @decl string `[]= (string(8bit) key, string(8bit) 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.    *!
pike.git/src/modules/Gdbm/gdbmmod.c:582:    mt_lock(& gdbm_lock);    gdbm_sync(this->dbf);    mt_unlock(& gdbm_lock);    THREADS_DISALLOW();   }         static void gdbmmod_iter_first(INT32 UNUSED(args))   {    struct gdbm_glue *this=THIS; -  gdbmmod_firstkey(0); -  if( Pike_sp[-1].u.string ) -  this->iter = Pike_sp[-1].u.string; -  Pike_sp--; -  push_int( !!this->iter ); +  if (this->iter) { +  free_string(this->iter);    } -  +  this->iter = NULL; + }      static void gdbmmod_iter_next(INT32 UNUSED(args))   {    struct gdbm_glue *this=THIS; -  if(!this->iter) -  { -  push_undefined(); -  return; -  } +  +  if(!this->iter) { +  gdbmmod_firstkey(0); +  } else {    push_string( this->iter ); -  +  this->iter = NULL;    gdbmmod_nextkey(1); -  if( TYPEOF(Pike_sp[-1]) != PIKE_T_STRING ) -  { -  this->iter = 0; -  push_undefined(); -  return; +     } -  +  +  if( TYPEOF(Pike_sp[-1]) == PIKE_T_STRING ) {    this->iter = Pike_sp[-1].u.string; -  push_int(1); +  add_ref(this->iter);    return; -  +     } -  +  push_undefined(); + }      static void gdbmmod_iter_index(INT32 UNUSED(args))   {    struct gdbm_glue *this=THIS;    if( this->iter )    ref_push_string( this->iter );    else    push_undefined();   }    - static void gdbmmod_iter_no_value(INT32 UNUSED(args)) - { -  push_int( !THIS->iter ); - } -  +    static void gdbmmod_iter_value(INT32 UNUSED(args))   {    struct gdbm_glue *this=THIS;    if( this->iter )    {    ref_push_string( this->iter );    gdbmmod_fetch(1);    }    else    push_undefined();
pike.git/src/modules/Gdbm/gdbmmod.c:688:    gdbmmod_fetch(1);    gdbmmod_iter_next(0);    pop_stack();    }    push_array(aggregate_array( Pike_sp-start ));   }      static void gdbmmod_get_iterator(INT32 UNUSED(args))   {    push_object( clone_object( iterator, 0 ) ); +  THIS->iter = NULL;    *((struct gdbm_glue *)Pike_sp[-1].u.object->storage) = *THIS; -  apply(Pike_sp[-1].u.object, "first", 0); -  pop_stack(); +    }         /*! @decl void close()    *!    *! Closes the database. The object is no longer usable after this function has been called.    *!    *! This is also done automatically when the object is destructed for    *! any reason (running out of references or explicit destruct, as an    *! example)
pike.git/src/modules/Gdbm/gdbmmod.c:801: Inside #if defined(HAVE_GDBM_H) && defined(HAVE_LIBGDBM)
      start_new_program();    ADD_STORAGE(struct gdbm_glue);    ADD_FUNCTION("first", gdbmmod_iter_first,tFunc(tNone,tInt01),0);    ADD_FUNCTION("_iterator_next", gdbmmod_iter_next, tFunc(tNone,tInt01),    ID_PROTECTED);    ADD_FUNCTION("_iterator_index", gdbmmod_iter_index, tFunc(tNone,tStr8),    ID_PROTECTED);    ADD_FUNCTION("_iterator_value", gdbmmod_iter_value, tFunc(tNone,tStr8),    ID_PROTECTED); -  ADD_FUNCTION("`!", gdbmmod_iter_no_value, tFunc(tNone,tInt01), -  ID_PROTECTED); +     set_exit_callback(exit_gdbm_iterator);    iterator = end_program();    add_program_constant( "Iterator", iterator, 0 );    free_program(iterator);   #else    HIDE_MODULE();   #endif   }