FIRSTKEY and NEXTKEY on perl interface for namedvars fixed (NEO-373 NEO-375 and NEO-372)

This commit is contained in:
Fish 2007-07-23 04:04:54 +00:00
parent 62f2d1ff78
commit 13691332f4
4 changed files with 35 additions and 27 deletions

View file

@ -110,6 +110,7 @@ typedef struct nv_list {
struct hscan_t hscan; struct hscan_t hscan;
struct lnode_t *node; struct lnode_t *node;
} iter; } iter;
int itercount;
} nv_list; } nv_list;
extern hash_t *namedvars; extern hash_t *namedvars;

View file

@ -117,15 +117,23 @@ sub event_pong {
# NeoStats::debug("$key => $value"); # NeoStats::debug("$key => $value");
# } # }
# #
my $hostserv = new NeoStats::NV("HostServ"); my $servers = new NeoStats::NV("Servers");
# my $hashtest = $hostserv->{1}; while ( my ($key, $value) = each(%$servers)) {
# Dump($hostserv); NeoStats::debug("Hostserv Key => $value, $key");
while ( my ($key, $value) = each(%$hostserv)) { while ( my ($key1, $value1) = each(%$value)) {
NeoStats::debug("Hostserv Key => $value");
while ( my ($key1, $value1) = each(%$key)) {
NeoStats::debug("HS: $key: $key1 => $value1"); NeoStats::debug("HS: $key: $key1 => $value1");
} }
} }
my $hostserv = new NeoStats::NV("HostServ");
# my $hashtest = $hostserv->{1};
while ( my ($key, $value) = each(%$hostserv)) {
NeoStats::debug("Hostserv Key => $value, $key");
while ( my ($key1, $value1) = each(%$value)) {
NeoStats::debug("HS: $key: $key1 => $value1");
}
}
# Dump($hostserv);
# NeoStats::debug("Debug HostServ: ".$hostserv." Ok"); # NeoStats::debug("Debug HostServ: ".$hostserv." Ok");
# Dump($hostserv); # Dump($hostserv);
# NeoStats::debug("Var: HostServ".$hostserv->{0}."Fin"); # NeoStats::debug("Var: HostServ".$hostserv->{0}."Fin");

View file

@ -174,9 +174,7 @@ CODE:
lnode = list_first((list_t *)nv->data);; lnode = list_first((list_t *)nv->data);;
for (i = 0; i == pos; i++) { for (i = 0; i == pos; i++) {
lnode = list_next((list_t *)nv->data, lnode); lnode = list_next((list_t *)nv->data, lnode);
printf("iter\n");
} }
printf("%d %d\n", i, pos);
if (lnode) { if (lnode) {
RETVAL = perl_encode_namedvars(nv, lnode_get(lnode)); RETVAL = perl_encode_namedvars(nv, lnode_get(lnode));
} else } else
@ -212,7 +210,7 @@ CODE:
/* make sure its a hash, not a list */ /* make sure its a hash, not a list */
if (nv->type == NV_TYPE_HASH) { if (nv->type == NV_TYPE_HASH) {
nlog(LOG_WARNING, "NamedVars is not a hash?!?!"); nlog(LOG_WARNING, "NamedVars is not a hash?!?!");
} else { } else if (nv->type == NV_TYPE_LIST) {
k = SvPV(key, klen); k = SvPV(key, klen);
perl_store_namedvars(nv, k, value); perl_store_namedvars(nv, k, value);
} }
@ -263,7 +261,7 @@ OUTPUT:
#/* get the first entry from a hash */ #/* get the first entry from a hash */
HV* SV*
FIRSTKEY(self) FIRSTKEY(self)
SV *self; SV *self;
PREINIT: PREINIT:
@ -272,7 +270,7 @@ PREINIT:
nv_list *nv; nv_list *nv;
hnode_t *node; hnode_t *node;
CODE: CODE:
RETVAL = (HV *)-1; RETVAL = &PL_sv_undef;
hash = (HV*)SvRV(self); hash = (HV*)SvRV(self);
mg = mg_find(SvRV(self),'~'); mg = mg_find(SvRV(self),'~');
if(!mg) { croak("lost ~ magic"); } if(!mg) { croak("lost ~ magic"); }
@ -281,14 +279,16 @@ CODE:
if (nv->type == NV_TYPE_HASH) { if (nv->type == NV_TYPE_HASH) {
hash_scan_begin( &nv->iter.hscan, (hash_t *)nv->data); hash_scan_begin( &nv->iter.hscan, (hash_t *)nv->data);
node = hash_scan_next(&nv->iter.hscan); node = hash_scan_next(&nv->iter.hscan);
nv->itercount = 0;
if (!node) { if (!node) {
RETVAL = (HV *)-1; RETVAL = &PL_sv_undef;
} else { } else {
RETVAL = perl_encode_namedvars(nv, hnode_get(node)); RETVAL = newSVpv(hnode_getkey(node), 0);
} }
} else if (nv->type == NV_TYPE_LIST) { } else if (nv->type == NV_TYPE_LIST) {
nv->iter.node = list_first((list_t *)nv->data); nv->iter.node = list_first((list_t *)nv->data);
RETVAL = perl_encode_namedvars(nv, lnode_get(nv->iter.node)); nv->itercount = 0;
RETVAL = newSVpv("0", 0);
} }
POSTCALL: POSTCALL:
RETURN_UNDEF_IF_FAIL; RETURN_UNDEF_IF_FAIL;
@ -297,7 +297,7 @@ OUTPUT:
#/* get the next entry from a cache */ #/* get the next entry from a cache */
HV* SV*
NEXTKEY(self, lastkey) NEXTKEY(self, lastkey)
SV *self; SV *self;
PREINIT: PREINIT:
@ -305,8 +305,9 @@ PREINIT:
MAGIC *mg; MAGIC *mg;
hnode_t *node; hnode_t *node;
nv_list *nv; nv_list *nv;
char tmpstr[BUFSIZE];
CODE: CODE:
RETVAL = (HV *)-1; RETVAL = &PL_sv_undef;
hash = (HV*)SvRV(self); hash = (HV*)SvRV(self);
mg = mg_find(SvRV(self),'~'); mg = mg_find(SvRV(self),'~');
if(!mg) { croak("lost ~ magic"); } if(!mg) { croak("lost ~ magic"); }
@ -314,20 +315,19 @@ CODE:
/* make sure its a hash, not a list */ /* make sure its a hash, not a list */
if (nv->type == NV_TYPE_HASH) { if (nv->type == NV_TYPE_HASH) {
node = hash_scan_next(&nv->iter.hscan); node = hash_scan_next(&nv->iter.hscan);
nv->itercount++;
if (!node) { if (!node) {
RETVAL = (HV *)-1; RETVAL = &PL_sv_undef;
} else { } else {
RETVAL = perl_encode_namedvars(nv, hnode_get(node)); RETVAL = newSVpv(hnode_getkey(node), 0);
} }
} else if (nv->type == NV_TYPE_LIST) { } else if (nv->type == NV_TYPE_LIST) {
if (nv->iter.node) { nv->itercount++;
nv->iter.node = list_next((list_t *)nv->data, nv->iter.node); if (nv->itercount >= list_count((list_t *)nv->data)) {
if (nv->iter.node) RETVAL = &PL_sv_undef;
RETVAL = perl_encode_namedvars(nv, lnode_get(nv->iter.node));
else
RETVAL = (HV *)-1;
} else { } else {
RETVAL = (HV *)-1; ircsnprintf(tmpstr, BUFSIZE, "%d", nv->itercount);
RETVAL =newSVpv(tmpstr,0);
} }
} }
POSTCALL: POSTCALL:

View file

@ -301,7 +301,6 @@ void nv_printstruct(void *data, nv_list *item) {
} }
} }
int nv_update_structure (nv_list *data, nv_item *item, nv_write_action action) { int nv_update_structure (nv_list *data, nv_item *item, nv_write_action action) {
int i, j; int i, j;
/* first, determine if the structure allows updates */ /* first, determine if the structure allows updates */