No more external leaks.

This commit is contained in:
C. Guy Yarvin 2014-10-10 22:32:58 -07:00
parent ae6aa44695
commit fb982e6dd6
19 changed files with 121 additions and 80 deletions

View File

@ -59,7 +59,7 @@ INCLUDE=include
MDEFINES=-DU2_OS_$(OS) -DU2_OS_ENDIAN_$(ENDIAN) -D U2_LIB=\"$(LIB)\"
# NOTFORCHECKIN - restore -O2
CFLAGS= $(COSFLAGS) -g -msse3 -ffast-math \
CFLAGS= $(COSFLAGS) -g -O2 -msse3 -ffast-math \
-funsigned-char \
-I/usr/local/include \
-I/opt/local/include \

49
g/a.c
View File

@ -273,11 +273,12 @@ u3_ca_walloc(c3_w len_w)
void* ptr_v = _ca_walloc(len_w);
#if 0
if ( u3_co_botox(ptr_v) == (u3_cs_box*)(void *) 0x200ce0ed4 ) {
if ( u3_co_botox(ptr_v) == (u3_cs_box*)(void *)0x2006a4b38 ) {
static int xuc_i;
printf("xuc_i %d; u3_Code %d\r\n", xuc_i, u3_Code);
if ( 4 == xuc_i ) { FOO = 1; }
printf("xuc_i %d\r\n", xuc_i);
if ( 31 == xuc_i ) { abort(); }
// if ( 9 == xuc_i ) { FOO = 1; }
xuc_i++;
}
#endif
@ -896,6 +897,17 @@ u3_ca_gain(u3_noun som)
{
c3_assert(u3_none != som);
#if 0
if ( FOO && (som == 3221949559) ) {
static int xuc_i;
printf("gain %d\r\n", xuc_i);
if ( 5 == xuc_i ) {
abort();
}
xuc_i++;
}
#endif
if ( u3_so(u3_co_is_cat(som)) ) {
return som;
}
@ -1071,8 +1083,10 @@ u3_ca_sweep(c3_c* cap_c)
c3_ws use_ws = (c3_ws)box_u->use_w;
if ( use_ws > 0 ) {
printf("leak %p %d\r\n", box_u, box_u->cod_w);
printf("leak %p\r\n", box_u);
if ( box_u->cod_w ) {
u3_cm_p(" code", box_u->cod_w);
}
leq_w += box_u->siz_w;
box_u->use_w = 0;
@ -1096,8 +1110,8 @@ u3_ca_sweep(c3_c* cap_c)
c3_assert((pos_w + leq_w) == neg_w);
_ca_print_memory("available", (tot_w - pos_w));
_ca_print_memory("allocated", pos_w);
// _ca_print_memory("available", (tot_w - pos_w));
// _ca_print_memory("allocated", pos_w);
_ca_print_memory("volatile", caf_w);
_ca_print_memory("leaked", leq_w);
}
@ -1175,23 +1189,28 @@ u3_ca_moot(c3_w* sal_w)
/* _ca_detect(): in u3_ca_detect().
*/
static c3_o
_ca_detect(u3_ch_root* har_u, u3_noun fum, u3_noun som)
static c3_d
_ca_detect(u3_ch_root* har_u, u3_noun fum, u3_noun som, c3_d axe_d)
{
while ( 1 ) {
if ( som == fum ) {
return u3_yes;
return axe_d;
}
else if ( u3_ne(u3du(fum)) || (u3_none != u3_ch_get(har_u, fum)) ) {
return u3_no;
return 0;
}
else {
c3_d eax_d;
u3_ch_put(har_u, fum, 0);
if ( u3_so(_ca_detect(har_u, u3h(fum), som)) ) {
if ( 0 != (eax_d = _ca_detect(har_u, u3h(fum), som, 2ULL * axe_d)) ) {
return u3_yes;
}
else fum = u3t(fum);
else {
fum = u3t(fum);
axe_d = (2ULL * axe_d) + 1;
}
}
}
}
@ -1200,13 +1219,13 @@ _ca_detect(u3_ch_root* har_u, u3_noun fum, u3_noun som)
**
** (som) and (fum) are both RETAINED.
*/
c3_o
c3_d
u3_ca_detect(u3_noun fum, u3_noun som)
{
u3_ch_root* har_u = u3_ch_new();
c3_o ret_o;
ret_o = _ca_detect(har_u, fum, som);
ret_o = _ca_detect(har_u, fum, som, 1);
u3_ch_free(har_u);
return ret_o;

5
g/i.c
View File

@ -215,13 +215,18 @@ u3_ci_cell(u3_noun a, u3_noun b)
nov_u->hed = a;
nov_u->tel = b;
#if 1
return u3_co_to_pom(u3_co_outa(nov_w));
#else
if ( !FOO ) return u3_co_to_pom(u3_co_outa(nov_w));
else {
u3_noun pro = u3_co_to_pom(u3_co_outa(nov_w));
u3_cm_p("leaked", pro);
printf("pro %u, %x\r\n", pro, u3_cr_mug(pro));
abort();
}
#endif
}
}

12
g/j.c
View File

@ -50,7 +50,7 @@ u3_cj_boot(void)
c3_w jax_l;
u3D.len_l =_cj_count(0, u3D.dev_u);
u3D.all_l = (2 * u3D.len_l) + 64; // horrid heuristic
u3D.all_l = (2 * u3D.len_l) + 1024; // horrid heuristic
u3D.ray_u = (u3_cs_core*) malloc(u3D.all_l * sizeof(u3_cs_core));
memset(u3D.ray_u, 0, (u3D.all_l * sizeof(u3_cs_core)));
@ -199,13 +199,7 @@ _cj_kick_b(u3_noun cor, c3_l jax_l, c3_l axe_l)
while ( 1 ) {
if ( 0 == hud_u ) { break; }
if ( mug_l != hud_u->mug_l ) { hud_u = hud_u->nex_u; continue; }
{
c3_w lab_w = u3_ca_lush(jax_l);
u3_noun pro = _cj_kick_a(cor, hud_u, axe_l);
u3_ca_lop(lab_w);
return pro;
}
return _cj_kick_a(cor, hud_u, axe_l);
}
return u3_none;
}
@ -631,7 +625,7 @@ u3_cj_mine(u3_noun clu,
u3D.ray_u[jax_l].par_u = par_u;
c3_assert(0 != jax_l);
free(nam_c);
#if 1
#if 0
fprintf(stderr, "mine: bound jet %d/%s/%s\r\n",
cop_u->jax_l,
cop_u->cos_c,

6
g/m.c
View File

@ -718,7 +718,7 @@ u3_cm_soft_top(c3_w sec_w, // timer seconds
*/
pro = u3_ca_take(why);
}
/* Clean up temporary memory.
*/
u3_cm_flog(gof_w);
@ -727,6 +727,10 @@ u3_cm_soft_top(c3_w sec_w, // timer seconds
*/
_cm_signal_done();
/* Free the argument.
*/
u3z(arg);
/* Return the product.
*/
return pro;

1
g/n.c
View File

@ -74,6 +74,7 @@ _cn_hint(u3_noun zep,
u3_noun pro = u3_cz_find_2(c3__nock, bus, nex);
if ( pro != u3_none ) {
u3z(bus); u3z(nex);
return pro;
}
pro = u3_cn_nock_on(u3k(bus), u3k(nex));

10
g/v.c
View File

@ -417,8 +417,14 @@ u3_cv_sway(u3_noun blu, c3_l tab_l, u3_noun tax)
void
u3_cv_plan(u3_noun pax, u3_noun fav)
{
u3_noun egg = u3nc(pax, fav);
u3A->roe = u3nc(u3nc(u3_nul, egg), u3A->roe);
c3_w lab_w;
lab_w = u3_ca_lush(c3__leap);
{
u3_noun egg = u3nc(pax, fav);
u3A->roe = u3nc(u3nc(u3_nul, egg), u3A->roe);
}
u3_ca_lop(lab_w);
}
/* u3_cv_plow(): queue multiple ova (external).

View File

@ -23,7 +23,7 @@
*** u3_cv_: arvo specific structures.
*** u3_cz_: memoization.
***
*** u3_cr_, u3_cx_ functions use retain conventions; the caller
*** u3_cr_, u3_cx_, u3_cz_ functions use retain conventions; the caller
*** retains ownership of passed-in nouns, the callee preserves
*** ownership of returned nouns.
***

View File

@ -926,6 +926,7 @@
# define c3__sibl c3_s4('s','i','b','l')
# define c3__sift c3_s4('s','i','f','t')
# define c3__sing c3_s4('s','i','n','g')
# define c3__sist c3_s4('s','i','s','t')
# define c3__site c3_s4('s','i','t','e')
# define c3__sith c3_s4('s','i','t','h')
# define c3__size c3_s4('s','i','z','e')

View File

@ -75,6 +75,13 @@
void
u3_ca_sane(void);
/* u3_ca_detect(): axis (som) is referenced from (fum).
**
** (som) and (fum) are both RETAINED.
*/
c3_d
u3_ca_detect(u3_noun fum, u3_noun som);
/* u3_ca_lush(): leak push.
*/
c3_w

View File

@ -9,7 +9,7 @@
u3_cqfu_gain(u3_noun van, u3_noun sut, u3_noun gen)
{
u3_noun von = u3_ci_molt(u3k(van), u3_cv_sam, u3k(sut), 0);
u3_noun gat = u3_cj_hook(u3k(von), "gain");
u3_noun gat = u3_cj_hook(von, "gain");
return u3_cn_kick_on(u3_ci_molt(gat, u3_cv_sam, u3k(gen), 0));
}

View File

@ -11,7 +11,7 @@
u3_noun gen)
{
u3_noun von = u3_ci_molt(u3k(van), u3_cv_sam, u3k(sut), 0);
u3_noun gat = u3_cj_hook(u3k(von), "lose");
u3_noun gat = u3_cj_hook(von, "lose");
return u3_cn_kick_on(u3_ci_molt(gat, u3_cv_sam, u3k(gen), 0));
}

View File

@ -927,10 +927,6 @@ int FOO;
{
u3_noun sut, gol, gen, van;
if ( FOO ) {
printf("mint: cor %x\r\n", cor);
printf("mint: core mug %x\r\n", u3_cr_mug(cor));
}
if ( (u3_no == u3_cr_mean(cor, u3_cv_sam_2, &gol,
u3_cv_sam_3, &gen,
u3_cv_con, &van,

View File

@ -12,7 +12,7 @@
u3_noun mur)
{
u3_noun von = u3_ci_molt(u3k(van), u3_cv_sam, u3k(sut), 0);
u3_noun gat = u3_cj_hook(u3k(von), "tack");
u3_noun gat = u3_cj_hook(von, "tack");
return u3_cn_kick_on
(u3_ci_molt(gat, u3_cv_sam_2, u3k(peh), u3_cv_sam_3, u3k(mur), 0));

View File

@ -167,13 +167,15 @@ u3_loop_signal_memory()
static void
_lo_init()
{
u3_unix_io_init();
u3_ames_io_init();
u3_term_io_init();
u3_http_io_init();
u3_cttp_io_init();
c3_w lab_w;
lab_w = u3_ca_lush(c3__unix); u3_unix_io_init(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__ames); u3_ames_io_init(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__term); u3_term_io_init(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__http); u3_http_io_init(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__cttp); u3_cttp_io_init(); u3_ca_lop(lab_w);
// u3_save_io_init();
u3_batz_io_init();
lab_w = u3_ca_lush(c3__batz); u3_batz_io_init(); u3_ca_lop(lab_w);
}
/* _lo_talk(): bring up listeners across the process.
@ -181,10 +183,12 @@ _lo_init()
static void
_lo_talk()
{
u3_unix_io_talk();
u3_ames_io_talk();
u3_http_io_talk();
u3_term_io_talk();
c3_w lab_w;
lab_w = u3_ca_lush(c3__unix); u3_unix_io_talk(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__ames); u3_ames_io_talk(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__http); u3_http_io_talk(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__term); u3_term_io_talk(); u3_ca_lop(lab_w);
}
/* u3_lo_exit(): terminate I/O across the process.
@ -192,13 +196,15 @@ _lo_talk()
void
u3_lo_exit(void)
{
u3_unix_io_exit();
u3_ames_io_exit();
u3_term_io_exit();
u3_http_io_exit();
u3_cttp_io_exit();
c3_w lab_w;
lab_w = u3_ca_lush(c3__unix); u3_unix_io_exit(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__ames); u3_ames_io_exit(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__term); u3_term_io_exit(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__http); u3_http_io_exit(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__cttp); u3_cttp_io_exit(); u3_ca_lop(lab_w);
// u3_save_io_exit();
u3_batz_io_exit();
lab_w = u3_ca_lush(c3__batz); u3_batz_io_exit(); u3_ca_lop(lab_w);
}
/* _lo_poll(): reset event flags across the process.
@ -206,6 +212,14 @@ u3_lo_exit(void)
static void
_lo_poll(void)
{
c3_w lab_w;
lab_w = u3_ca_lush(c3__ames); u3_ames_io_poll(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__http); u3_http_io_poll(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__term); u3_term_io_poll(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__unix); u3_unix_io_poll(); u3_ca_lop(lab_w);
lab_w = u3_ca_lush(c3__batz); u3_batz_io_poll(); u3_ca_lop(lab_w);
u3_ames_io_poll();
u3_http_io_poll();
u3_term_io_poll();
@ -341,6 +355,8 @@ _lo_time(void)
void
u3_lo_open(void)
{
u3_ce_grab("lo_open");
_lo_time();
}

View File

@ -275,7 +275,7 @@ interrupt_handler(int x)
}
#endif
// #define GRAB
#define GRAB
c3_i
main(c3_i argc,
@ -311,7 +311,7 @@ main(c3_i argc,
/* Start Arvo.
*/
#if 0
#if 1
{
struct timeval tim_tv;
u3_noun now;
@ -334,32 +334,8 @@ main(c3_i argc,
#endif
}
#ifdef GRAB
{
u3_noun fur = u3_cv_wish("(dec 199)");
u3_cm_p("fur", fur);
u3z(fur);
}
u3_ce_grab("main");
#else
#if 1
u3_lo_loop();
#else
{
u3_noun imp, num;
u3_leak_on(1);
imp = u3_ci_string(u3_Host.ops_u.imp_c);
u3_leak_on(2);
num = u3_dc("slaw", 'p', imp);
u3z(num);
u3_leak_off;
u3_ce_grab("init");
}
#endif
#endif
return 0;
}

View File

@ -340,6 +340,10 @@ _reck_kick_norm(u3_noun pox, u3_noun fav)
void
u3_reck_kick(u3_noun ovo)
{
c3_w lab_w;
lab_w = u3_ca_lush(u3h(u3t(ovo)));
if ( (u3_no == _reck_kick_spec(u3k(u3h(ovo)), u3k(u3t(ovo)))) &&
(u3_no == _reck_kick_norm(u3k(u3h(ovo)), u3k(u3t(ovo)))) )
{
@ -375,4 +379,5 @@ u3_reck_kick(u3_noun ovo)
u3z(tox);
}
u3z(ovo);
u3_ca_lop(lab_w);
}

View File

@ -636,7 +636,13 @@ _sist_make(u3_noun fav)
// Authenticate and initialize terminal.
//
u3_term_ef_bake(fav);
{
c3_w lab_w;
lab_w = u3_ca_lush(c3__lect);
u3_term_ef_bake(fav);
u3_ca_lop(lab_w);
}
// Create the ship directory.
//
@ -1201,7 +1207,11 @@ _sist_zen()
void
u3_sist_boot(void)
{
c3_w lab_w;
uL(fprintf(uH, "sist: booting\n"));
lab_w = u3_ca_lush(c3__sist);
if ( u3_yes == u3_Host.ops_u.nuu ) {
u3_noun pig = u3_none;
@ -1254,4 +1264,5 @@ u3_sist_boot(void)
else {
_sist_rest();
}
u3_ca_lop(lab_w);
}

View File

@ -1010,7 +1010,7 @@ u3_term_ef_boil(void)
/* u3_term_ef_bake(): initial effects for new terminal.
*/
void
u3_term_ef_bake(u3_noun fav)
u3_term_ef_bake(u3_noun fav)
{
u3_noun pax = u3nq(u3_blip, c3__term, '1', u3_nul);