From aaece680c7b92fd191cc1ee047fcad7a09611915 Mon Sep 17 00:00:00 2001 From: "psyc://psyced.org/~lynX" <@> Date: Tue, 26 Apr 2011 22:00:45 +0200 Subject: [PATCH] choosing the appropriate alloc strategies --- src/pkg-psyc.c | 45 +++++++++++++++++++++++++-------------------- src/version.sh | 2 +- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/pkg-psyc.c b/src/pkg-psyc.c index 20f6660..c795bbd 100644 --- a/src/pkg-psyc.c +++ b/src/pkg-psyc.c @@ -50,13 +50,13 @@ f_psyc_render(svalue_t *sp) { /* NOTREACHED */ return sp; } - if (v->item[PSYC_METHOD]->type != T_STRING) { - errorf("Wrong type for PSYC_METHOD element in PSYC packet.\n", i); + if (v->item[PSYC_METHOD].type != T_STRING) { + errorf("Wrong type for PSYC_METHOD element in PSYC packet.\n"); /* NOTREACHED */ return sp; } - if (v->item[PSYC_BODY]->type != T_STRING) { - errorf("Wrong type for PSYC_BODY element in PSYC packet.\n", i); + if (v->item[PSYC_BODY].type != T_STRING) { + errorf("Wrong type for PSYC_BODY element in PSYC packet.\n"); /* NOTREACHED */ return sp; } @@ -68,11 +68,13 @@ f_psyc_render(svalue_t *sp) { PSYC_PACKET_CHECK_LENGTH); printf("rendering... packet.length = %d\n", packet.length); + // alloc_mstring creates an *untabled* string suitable for tmp data memsafe(out = alloc_mstring(packet.length), packet.length, "f_psyc_render"); psyc_render(&packet, get_txt(out), packet.length); free_svalue(sp); put_string(sp, out); + // stack should take care of freeing the string after use return sp; } /* f_psyc_render */ @@ -121,25 +123,30 @@ f_psyc_parse (svalue_t *sp) { puts("_failure_unsupported_state"); continue; } - // not sure if the following code is good.. TODO sv = pxalloc( sizeof( svalue_t ) ); - put_string(sv, new_n_mstring(name.ptr, name.length)); + // new_n_tabled fetches a reference of a probably existing + // shared string + put_string(sv, new_n_tabled(name.ptr, name.length)); sv = get_map_lvalue(v->item[PSYC_ROUTING].u.map, sv); - // should support int* when necessary.. TODO - put_string(sv, new_n_mstring(value.ptr, value.length)); + // strings are capable of containing 0 so we can do this + // for binary data too. let's use a tabled string even + // for values of routing variables as they repeat a lot + put_string(sv, new_n_tabled(value.ptr, value.length)); break; case PSYC_PARSE_ENTITY: if (oper != ':') { puts("_failure_unsupported_state"); continue; } - // not sure if the following code is good.. TODO sv = pxalloc( sizeof( svalue_t ) ); - put_string(sv, new_n_mstring(name.ptr, name.length)); + put_string(sv, new_n_tabled(name.ptr, name.length)); sv = get_map_lvalue(v->item[PSYC_ENTITY].u.map, sv); - // should support int* when necessary.. TODO - put_string(sv, new_n_mstring(value.ptr, value.length)); + // is it good to put entity variable values into the + // shared string table? probably yes.. but it's a guess + //t_string(sv, new_n_mstring(value.ptr, value.length)); + put_string(sv, new_n_tabled(value.ptr, value.length)); + // list parsing not supported yet.. TODO if (memcmp(name.ptr, "_list", 5) == 0) { write(1, ">>> LIST START\n", 15); @@ -171,15 +178,13 @@ f_psyc_parse (svalue_t *sp) { break; case PSYC_PARSE_BODY: if (str) errorf("Got two PSYC methods in the same packet!?\n"); - // not sure if new_n_mstring is the right thing here.. TODO - str = new_n_mstring(name.ptr, name.length); - // make_tabled gets the shared string for the method - put_string(&v->item[PSYC_METHOD], make_tabled(str)); + // new_n_tabled gets the shared string for the method + put_string(&v->item[PSYC_METHOD], + new_n_tabled(name.ptr, name.length)); - // not sure if new_n_mstring is the right thing here.. TODO - // should support int* when necessary.. TODO - str = new_n_mstring(value.ptr, value.length); - put_string(&v->item[PSYC_BODY], str); + // allocate an untabled string for the packet body + put_string(&v->item[PSYC_BODY], + new_n_mstring(value.ptr, value.length)); break; case PSYC_PARSE_COMPLETE: diff --git a/src/version.sh b/src/version.sh index 79b19ec..046fcaf 100644 --- a/src/version.sh +++ b/src/version.sh @@ -17,7 +17,7 @@ version_longtype="stable" # A timestamp, to be used by bumpversion and other scripts. # It can be used, for example, to 'touch' this file on every build, thus # forcing revision control systems to add it on every checkin automatically. -version_stamp="Tue Apr 26 09:46:14 CEST 2011" +version_stamp="Tue Apr 26 22:00:17 CEST 2011" # Okay, LDMUD is using 3.x.x so to avoid conflicts let's just use 4.x.x version_major=4