Skip to content
Snippets Groups Projects
Commit 33218c13 authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Gdbm: Update to new iterator API.

Fixes some of #10085.
parent 35863647
No related branches found
No related tags found
No related merge requests found
...@@ -389,7 +389,7 @@ static void gdbmmod_firstkey(INT32 args) ...@@ -389,7 +389,7 @@ static void gdbmmod_firstkey(INT32 args)
push_string(DATUM_TO_STRING(ret)); push_string(DATUM_TO_STRING(ret));
free(ret.dptr); free(ret.dptr);
} else { } else {
push_int(0); push_undefined();
} }
} }
...@@ -448,7 +448,7 @@ static void gdbmmod_nextkey(INT32 args) ...@@ -448,7 +448,7 @@ static void gdbmmod_nextkey(INT32 args)
push_string(DATUM_TO_STRING(ret)); push_string(DATUM_TO_STRING(ret));
free(ret.dptr); free(ret.dptr);
} else { } else {
push_int(0); push_undefined();
} }
} }
...@@ -589,33 +589,30 @@ static void gdbmmod_sync(INT32 UNUSED(args)) ...@@ -589,33 +589,30 @@ static void gdbmmod_sync(INT32 UNUSED(args))
static void gdbmmod_iter_first(INT32 UNUSED(args)) static void gdbmmod_iter_first(INT32 UNUSED(args))
{ {
struct gdbm_glue *this=THIS; struct gdbm_glue *this=THIS;
gdbmmod_firstkey(0); if (this->iter) {
if( Pike_sp[-1].u.string ) free_string(this->iter);
this->iter = Pike_sp[-1].u.string; }
Pike_sp--; this->iter = NULL;
push_int( !!this->iter );
} }
static void gdbmmod_iter_next(INT32 UNUSED(args)) static void gdbmmod_iter_next(INT32 UNUSED(args))
{ {
struct gdbm_glue *this=THIS; struct gdbm_glue *this=THIS;
if(!this->iter)
{ if(!this->iter) {
push_undefined(); gdbmmod_firstkey(0);
return; } else {
}
push_string( this->iter ); push_string( this->iter );
this->iter = NULL;
gdbmmod_nextkey(1); 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; this->iter = Pike_sp[-1].u.string;
push_int(1); add_ref(this->iter);
return; return;
}
push_undefined();
} }
static void gdbmmod_iter_index(INT32 UNUSED(args)) static void gdbmmod_iter_index(INT32 UNUSED(args))
...@@ -627,11 +624,6 @@ static void gdbmmod_iter_index(INT32 UNUSED(args)) ...@@ -627,11 +624,6 @@ static void gdbmmod_iter_index(INT32 UNUSED(args))
push_undefined(); push_undefined();
} }
static void gdbmmod_iter_no_value(INT32 UNUSED(args))
{
push_int( !THIS->iter );
}
static void gdbmmod_iter_value(INT32 UNUSED(args)) static void gdbmmod_iter_value(INT32 UNUSED(args))
{ {
struct gdbm_glue *this=THIS; struct gdbm_glue *this=THIS;
...@@ -695,9 +687,8 @@ static void gdbmmod_values(INT32 UNUSED(args)) ...@@ -695,9 +687,8 @@ static void gdbmmod_values(INT32 UNUSED(args))
static void gdbmmod_get_iterator(INT32 UNUSED(args)) static void gdbmmod_get_iterator(INT32 UNUSED(args))
{ {
push_object( clone_object( iterator, 0 ) ); push_object( clone_object( iterator, 0 ) );
THIS->iter = NULL;
*((struct gdbm_glue *)Pike_sp[-1].u.object->storage) = *THIS; *((struct gdbm_glue *)Pike_sp[-1].u.object->storage) = *THIS;
apply(Pike_sp[-1].u.object, "first", 0);
pop_stack();
} }
...@@ -808,8 +799,6 @@ PIKE_MODULE_INIT ...@@ -808,8 +799,6 @@ PIKE_MODULE_INIT
ID_PROTECTED); ID_PROTECTED);
ADD_FUNCTION("_iterator_value", gdbmmod_iter_value, tFunc(tNone,tStr8), ADD_FUNCTION("_iterator_value", gdbmmod_iter_value, tFunc(tNone,tStr8),
ID_PROTECTED); ID_PROTECTED);
ADD_FUNCTION("`!", gdbmmod_iter_no_value, tFunc(tNone,tInt01),
ID_PROTECTED);
set_exit_callback(exit_gdbm_iterator); set_exit_callback(exit_gdbm_iterator);
iterator = end_program(); iterator = end_program();
add_program_constant( "Iterator", iterator, 0 ); add_program_constant( "Iterator", iterator, 0 );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment