This commit is contained in:
jl777
2019-03-06 00:16:30 -11:00
parent 8e89c783d4
commit dbb33e6949
5 changed files with 81 additions and 45 deletions

View File

@@ -19,6 +19,58 @@
int total = 0; /* total dynamic memory bytes */
#endif
/*
* discard:
* Free up an item
*/
int32_t itemcounter;
THING *thingptrs[100000];
int32_t numptrs;
int32_t thing_find(THING *ptr)
{
for (i=0; i<numptrs; i++)
if ( item == thingptrs[i] )
return(i);
return(-1);
}
void
discard(THING *item)
{
#ifdef MASTER
total--;
#endif
if ( 1 )
{
int32_t i;
for (i=0; i<numptrs; i++)
if ( item == thingptrs[i] )
{
thingptrs[i] = thingptrs[--numptrs];
thingptrs[numptrs] = 0;
break;
}
}
itemcounter--;
free((char *) item);
}
void garbage_collect()
{
return;
int32_t i;
fprintf(stderr,"numptrs.%d free them\n",numptrs);
for (i=0; i<numptrs; i++)
{
//fprintf(stderr,"%p _t_type.%d otype.%d (%c)\n",thingptrs[i],thingptrs[i]->_t._t_type,thingptrs[i]->o_type,thingptrs[i]->o_type);
free(thingptrs[i]);
}
memset(thingptrs,0,sizeof(thingptrs));
numptrs = 0;
}
/*
* detach:
* takes an item out of whatever linked list it might be in
@@ -77,49 +129,7 @@ _free_list(THING **ptr)
}
}
/*
* discard:
* Free up an item
*/
int32_t itemcounter;
THING *thingptrs[100000];
int32_t numptrs;
void
discard(THING *item)
{
#ifdef MASTER
total--;
#endif
if ( 0 )
{
int32_t i;
for (i=0; i<numptrs; i++)
if ( item == thingptrs[i] )
{
thingptrs[i] = thingptrs[--numptrs];
thingptrs[numptrs] = 0;
break;
}
}
itemcounter--;
free((char *) item);
}
void garbage_collect()
{
return;
int32_t i;
fprintf(stderr,"numptrs.%d free them\n",numptrs);
for (i=0; i<numptrs; i++)
{
//fprintf(stderr,"%p _t_type.%d otype.%d (%c)\n",thingptrs[i],thingptrs[i]->_t._t_type,thingptrs[i]->o_type,thingptrs[i]->o_type);
free(thingptrs[i]);
}
memset(thingptrs,0,sizeof(thingptrs));
numptrs = 0;
}
/*
* new_item
@@ -139,7 +149,7 @@ new_item(void)
#else
item = (THING *)calloc(1, sizeof *item);
#endif
if ( 0 )
if ( 1 )
{
thingptrs[numptrs++] = item;
if ( (++itemcounter % 100) == 0 )

View File

@@ -742,7 +742,7 @@ int32_t rogue_sendrawtransaction(char *rawtx)
void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char *keystrokes,int32_t num)
{
char cmd[16384],hexstr[16384],params[32768],*retstr,*rawtx,*pastkeys; int32_t i,numpastkeys; cJSON *retjson;
char cmd[16384],hexstr[16384],params[32768],*retstr,*rawtx,*pastkeys,*pastcmp,*keys; int32_t i,len,numpastkeys; cJSON *retjson;
//fprintf(stderr,"rogue_progress num.%d\n",num);
if ( rs->guiflag != 0 && Gametxidstr[0] != 0 )
{
@@ -767,6 +767,25 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char *
// if not matching... panic?
if ( 0 && (pastkeys= rogue_keystrokesload(&numpastkeys,seed,1)) != 0 )
{
sprintf(params,"[\"extract\",\"17\",\"[%%22%s%%22]\"]",Gametxidstr);
if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (keys= jstr(retjson,"keystrokes")) != 0 )
{
len = strlen(keys) / 2;
pastcmp = (char *)malloc(len + 1)
decode_hex(pastcmp,len,keys);
if ( len != numpastkeys || memcmp(pastcmp,pastkeys,len) != 0 )
{
fprintf(stderr,"pastcmp[%d] != pastkeys[%d]?\n",len,numpastkeys);
}
free(pastcmp);
}
free_json(retjson);
}
}
free(pastkeys);
}

View File

@@ -286,7 +286,7 @@ char *rogue_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter)
fclose(fp);
num += fsize;
counter++;
fprintf(stderr,"loaded %ld from (%s) total %d\n",fsize,fname,num);
//fprintf(stderr,"loaded %ld from (%s) total %d\n",fsize,fname,num);
}
*numkeysp = num;
return(keystrokes);

View File

@@ -824,6 +824,7 @@ void doctor(struct rogue_state *rs,int);
void playit(struct rogue_state *rs);
struct room *roomin(struct rogue_state *rs,coord *cp);
int32_t thing_find(THING *ptr);
#define MAXDAEMONS 20

View File

@@ -1429,6 +1429,11 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o)
struct rogue_packitem *item;
if (write_error)
return(WRITESTAT);
if ( thing_find(o) < 0 )
{
fprintf(stderr,"cant find thing.%p in list\n",o);
return(0);
}
if ( o->_o._o_packch != 0 )
{
item = &rs->P.roguepack[rs->P.packsize];
@@ -1478,6 +1483,7 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o)
rs_write_int(savef, o->_o._o_flags);
rs_write_int(savef, o->_o._o_group);
rs_write_string(savef, o->_o._o_label);
fprintf(stderr,"label.%p\n",o->_o._o_label);
return(WRITESTAT);
}