From ab455736e93b610371c96a014162a55fc08f039a Mon Sep 17 00:00:00 2001 From: joshuareagan Date: Thu, 29 Nov 2018 12:42:47 -0600 Subject: [PATCH 01/90] variance fix: calling lead, zinc gates --- jets/f/ut_find.c | 9 +-------- jets/f/ut_fire.c | 9 +++++++-- jets/f/ut_peek.c | 22 +++++++++++++++++++++- jets/tree.c | 9 +++------ 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/jets/f/ut_find.c b/jets/f/ut_find.c index 610e4a46f8..7de284836b 100644 --- a/jets/f/ut_find.c +++ b/jets/f/ut_find.c @@ -190,15 +190,8 @@ u3_noun pu_zem = u3h(u_zem); u3_noun qu_zem = u3t(u_zem); u3_noun zut; - u3_noun mut; u3_noun pro; - mut = u3nt(c3__core, - u3k(p_sut), - u3nt(u3nt(u3k(ppq_sut), u3k(qpq_sut), c3__gold), - u3k(qq_sut), - u3k(rq_sut))); - #if 1 if ( qpq_sut == c3__wet ) { zut = u3nc(c3__wet, u3k(qu_zem)); @@ -214,7 +207,7 @@ u3nc(u3nc(u3_nul, u3k(axe)), u3k(lon)), u3nt(c3n, u3qc_peg(2, pu_zem), - u3nt(u3nc(mut, zut), u3_nul, u3_nul))); + u3nt(u3nc(u3k(sut), zut), u3_nul, u3_nul))); u3z(zem); return pro; diff --git a/jets/f/ut_fire.c b/jets/f/ut_fire.c index 7ca02bccbc..873d4524be 100644 --- a/jets/f/ut_fire.c +++ b/jets/f/ut_fire.c @@ -62,6 +62,7 @@ u3_noun gat) { u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ; + u3_noun ppq_typ, qpq_typ, rpq_typ; u3_noun h_gat, t_gat; if ( (c3n == u3du(typ)) || (c3__core != u3h(typ)) ) { @@ -69,12 +70,16 @@ } else if ( (c3n == u3r_cell(u3t(typ), &p_typ, &q_typ)) || (c3n == u3r_trel(q_typ, &pq_typ, &qq_typ, &rq_typ)) || + (c3n == u3r_trel(pq_typ, &ppq_typ, &qpq_typ, &rpq_typ)) || (c3n == u3r_cell(gat, &h_gat, &t_gat)) ) { return u3m_bail(c3__fail); } else { - u3_noun dox = u3nt - (c3__core, u3k(qq_typ), u3k(q_typ)); + u3_noun dox = u3nt(c3__core, + u3k(qq_typ), + u3nt(u3nt(u3k(ppq_typ), u3k(qpq_typ), c3__gold), + u3k(qq_typ), + u3k(rq_typ))); if ( (c3__ash == u3h(gat)) || (c3__dry == u3h(gat)) ) { if ( (c3y == vet) && diff --git a/jets/f/ut_peek.c b/jets/f/ut_peek.c index 96c99414c6..8b59d8f884 100644 --- a/jets/f/ut_peek.c +++ b/jets/f/ut_peek.c @@ -88,11 +88,30 @@ u3_noun pec = u3qfu_peel(van, sut, way, rpq_sut); u3_noun sam = u3h(pec); u3_noun con = u3t(pec); + u3_atom tow; - if ( c3y == c3a(sam, con) ) { + if ( 1 == lat ) { + tow = 1; + } else { + tow = u3qc_cap(lat); + } + + if ( (c3y == c3a(sam, con)) || + ((c3y == sam) && (tow == 2)) || + ((c3y == con) && (tow == 3)) ) + { pro = _cqfu_peek(van, p_sut, way, lat); } else { + + if ( way != c3__read ) { + u3z(lat); + u3z(now); + u3z(pec); + u3z(tow); + return u3m_error("payload-block"); + } + u3_noun typ; { @@ -120,6 +139,7 @@ } u3z(pec); + u3z(tow); } else { pro = c3__noun; diff --git a/jets/tree.c b/jets/tree.c index 4facf4fa09..a96baadedc 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -233,11 +233,8 @@ static c3_c* _141_pen_loot_ha[] = {0}; static u3j_harm _141_pen__ut_crop_a[] = {{".2", u3wfu_crop}, {}}; static c3_c* _141_pen__ut_crop_ha[] = {0}; - - // XX figure out why this is disabled - // static u3j_harm _141_pen__ut_fire_a[] = {{".2", u3wfu_fire}, {}}; - // static c3_c* _141_pen__ut_fire_ha[] = {0}; - + static u3j_harm _141_pen__ut_fire_a[] = {{".2", u3wfu_fire}, {}}; + static c3_c* _141_pen__ut_fire_ha[] = {0}; static u3j_harm _141_pen__ut_fond_a[] = {{".2", u3wfu_fond}, {}}; static c3_c* _141_pen__ut_fond_ha[] = {0}; static u3j_harm _141_pen__ut_fish_a[] = {{".2", u3wfu_fish}, {}}; @@ -265,7 +262,7 @@ static u3j_core _141_pen__ut_d[] = { { "crop", 7, _141_pen__ut_crop_a, 0, _141_pen__ut_crop_ha }, { "fond", 7, _141_pen__ut_fond_a, 0, _141_pen__ut_fond_ha }, - // { "fire", 7, _141_pen__ut_fire_a, 0, _141_pen__ut_fire_ha }, + { "fire", 7, _141_pen__ut_fire_a, 0, _141_pen__ut_fire_ha }, { "fish", 7, _141_pen__ut_fish_a, 0, _141_pen__ut_fish_ha }, { "fuse", 7, _141_pen__ut_fuse_a, 0, _141_pen__ut_fuse_ha }, { "mint", 7, _141_pen__ut_mint_a, 0, _141_pen__ut_mint_ha }, From cb96aed4c7f25c011296d9dda41aad32bbb91067 Mon Sep 17 00:00:00 2001 From: Joshua Reagan Date: Thu, 29 Nov 2018 13:05:15 -0600 Subject: [PATCH 02/90] arvo commit hash --- .travis/pin-arvo-commit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/pin-arvo-commit.txt b/.travis/pin-arvo-commit.txt index 4e689c4c5d..372a31df76 100644 --- a/.travis/pin-arvo-commit.txt +++ b/.travis/pin-arvo-commit.txt @@ -1 +1 @@ -806c604c2f0f9ee7eea2999e6bb15ed5a8abaa99 +f583936e8e092a133644d184387e8bb7d30c9299 From 1e2a8bdb12befd193b4e5a62412e18bcc3395008 Mon Sep 17 00:00:00 2001 From: Joshua Reagan Date: Thu, 29 Nov 2018 14:10:45 -0600 Subject: [PATCH 03/90] Update pin-arvo-commit.txt --- .travis/pin-arvo-commit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/pin-arvo-commit.txt b/.travis/pin-arvo-commit.txt index 372a31df76..92c82b8d06 100644 --- a/.travis/pin-arvo-commit.txt +++ b/.travis/pin-arvo-commit.txt @@ -1 +1 @@ -f583936e8e092a133644d184387e8bb7d30c9299 +e71c57b4455c84062230b4277f95eb7047a26146 From e62acfa1bcca372872bc835872a77d638ca3cfea Mon Sep 17 00:00:00 2001 From: Joshua Reagan Date: Thu, 29 Nov 2018 18:52:47 -0600 Subject: [PATCH 04/90] remove superfluous reference decrements --- jets/f/ut_peek.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/jets/f/ut_peek.c b/jets/f/ut_peek.c index 8b59d8f884..dc9a5887c9 100644 --- a/jets/f/ut_peek.c +++ b/jets/f/ut_peek.c @@ -105,10 +105,6 @@ else { if ( way != c3__read ) { - u3z(lat); - u3z(now); - u3z(pec); - u3z(tow); return u3m_error("payload-block"); } From 2f8d0d6d34963ea00284c4cd69a5ae8bbc33b061 Mon Sep 17 00:00:00 2001 From: Joshua Reagan Date: Fri, 30 Nov 2018 22:11:08 -0600 Subject: [PATCH 05/90] fix core nest mismatch There is a variance bug such that the following cast is allowed to go through: ``` > =a 12 > =core1 ^? |=(b=@ a) > =a "hello" > =core2 ^? |=(b=@ a) > ^+(core1 core2) ``` This should not be! The code in `hoon.hoon` is correct -- it turns out that the jet is wrong however. It falsely returns "yes" for a nest in which two cores have identical code. Obviously that's not enough to guarantee sameness of type. So I've removed the offending lines. --- jets/f/ut_nest.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/jets/f/ut_nest.c b/jets/f/ut_nest.c index a6bd87deb4..f36c1385cb 100644 --- a/jets/f/ut_nest.c +++ b/jets/f/ut_nest.c @@ -150,9 +150,6 @@ else if ( c3__wet == qpq_sut ) { return u3r_sing(qrq_sut, qrq_ref); } - else if ( c3y == u3r_sing(qrq_sut, qrq_ref) ) { - return c3y; - } else { u3_noun hud = u3nc(u3k(sut), u3k(ref)); From 8b9680072a6c2e38be5ae1f87e531c222cdc4b81 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Wed, 28 Nov 2018 16:34:32 -0800 Subject: [PATCH 06/90] Add support for trace_event files. This adds a -j parameter which writes traces of your Urbit's function call stack to a json file, readable by Chrome's about://tracing or the standalone trace-viewer webapp. --- include/noun/allocate.h | 1 + include/noun/options.h | 3 +- include/noun/trace.h | 21 +++++ include/vere/vere.h | 2 + noun/jets.c | 55 +++++++++--- noun/manage.c | 3 + noun/trace.c | 181 +++++++++++++++++++++++++++++++++++++++- noun/vortex.c | 3 + vere/main.c | 14 +++- vere/raft.c | 5 ++ vere/reck.c | 2 + 11 files changed, 275 insertions(+), 15 deletions(-) diff --git a/include/noun/allocate.h b/include/noun/allocate.h index 11199014d1..32a8e8d37a 100644 --- a/include/noun/allocate.h +++ b/include/noun/allocate.h @@ -146,6 +146,7 @@ c3_d nox_d; // nock steps c3_d cel_d; // cell allocations u3_noun don; // (list batt) + u3_noun trace; // (list trace) u3_noun day; // doss, only in u3H (moveme) } pro; diff --git a/include/noun/options.h b/include/noun/options.h index 7eb5d540b8..9ac90512ea 100644 --- a/include/noun/options.h +++ b/include/noun/options.h @@ -25,7 +25,8 @@ u3o_verbose = 0x10, // be remarkably wordy u3o_dryrun = 0x20, // don't touch checkpoint u3o_quiet = 0x40, // disable ~& - u3o_hashless = 0x80 // disable hashboard + u3o_hashless = 0x80, // disable hashboard + u3o_trace = 0x100 // enables trace dumping }; /** Globals. diff --git a/include/noun/trace.h b/include/noun/trace.h index 838ce835f3..049c552181 100644 --- a/include/noun/trace.h +++ b/include/noun/trace.h @@ -83,6 +83,27 @@ void u3t_flee(void); + /* u3t_trace_open(): opens the path for writing tracing information. + */ + void + u3t_trace_open(c3_c*); + + /* u3t_nock_trace_push(): pushes a frame ont o the trace stack; + * return yes if active push. + */ + c3_o + u3t_nock_trace_push(u3_noun lab); + + /* u3t_nock_trace_pop(): pop off trace stack. + */ + void + u3t_nock_trace_pop(); + + /* u3t_even_trace(): record a lifecycle event. + */ + void + u3t_event_trace(const char* name, char type); + /* u3t_damp(): print and clear profile data. */ void diff --git a/include/vere/vere.h b/include/vere/vere.h index 4e59a01e83..79cc76b7ec 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -591,6 +591,7 @@ c3_c* gen_c; // -G, czar generator c3_o gab; // -g, test garbage collection c3_c* dns_c; // -H, ames bootstrap domain + c3_c* json_file_c; // -j, json trace c3_w kno_w; // -K, kernel version c3_c* key_c; // -k, private key file c3_o net; // -L, local-only networking @@ -631,6 +632,7 @@ c3_o liv; // if u3_no, shut down c3_i xit_i; // exit code for shutdown void* tls_u; // server SSL_CTX* + FILE* trace_file; // trace file to write to } u3_host; // host == computer == process # define u3L u3_Host.lup_u // global event loop diff --git a/noun/jets.c b/noun/jets.c index 8e37f8d4e7..3fb353f707 100644 --- a/noun/jets.c +++ b/noun/jets.c @@ -1243,18 +1243,27 @@ u3j_kick(u3_noun cor, u3_noun axe) u3x_qual(act, &jax_l, &hap, &bal, &jit); if ( u3_none == (inx = u3kdb_get(u3k(hap), u3k(axe))) ) { - u3t_off(glu_o); + u3t_off(glu_o); { c3_o pof_o = __(u3C.wag_w & u3o_debug_cpu); + c3_o trc_o = __(u3C.wag_w & u3o_trace); if ( _(pof_o) ) { pof_o = u3t_come(bal); } + if ( _(trc_o) ) { + trc_o = u3t_nock_trace_push(bal); + } u3z(act); - if ( _(pof_o) ) { + if ( _(pof_o) || _(trc_o) ) { u3_noun pro = _cj_sink(cor, u3k(axe)); - u3t_flee(); + if (_(pof_o)) { + u3t_flee(); + } + if ( _(trc_o) ) { + u3t_nock_trace_pop(); + } return pro; } else { @@ -1267,28 +1276,39 @@ u3j_kick(u3_noun cor, u3_noun axe) c3_l inx_l = inx; u3j_harm* ham_u = &cop_u->arm_u[inx_l]; c3_o pof_o = __(u3C.wag_w & u3o_debug_cpu); + c3_o trc_o = __(u3C.wag_w & u3o_trace); u3_noun pro; if ( _(pof_o) ) { pof_o = u3t_come(bal); } + if ( _(trc_o) ) { + trc_o = u3t_nock_trace_push(bal); + } u3z(act); u3t_off(glu_o); pro = _cj_kick_z(cor, cop_u, ham_u, axe); - + if ( u3_none == pro ) { - if ( _(pof_o) ) { + if ( _(pof_o) || _(trc_o) ) { pro = _cj_sink(cor, u3k(axe)); - u3t_flee(); - return pro; - } - else return u3_none; + if (_(pof_o)) { + u3t_flee(); + } + if ( _(trc_o) ) { + u3t_nock_trace_pop(); + } + } + return pro; } else { if ( _(pof_o) ) { u3t_flee(); } + if ( _(trc_o) ) { + u3t_nock_trace_pop(); + } return pro; } } @@ -1470,7 +1490,9 @@ _cj_site_kick_hot(u3_noun loc, u3_noun cor, u3j_site* sit_u, c3_o lok_o) u3_weak pro = u3_none; c3_o jet_o = sit_u->jet_o; c3_o pof_o = __(u3C.wag_w & u3o_debug_cpu); - if ( c3n == pof_o ) { + c3_o trc_o = __(u3C.wag_w & u3o_trace); + + if ( c3n == pof_o && c3n == trc_o ) { if ( c3y == jet_o ) { u3t_off(glu_o); pro = _cj_kick_z(cor, sit_u->cop_u, sit_u->ham_u, sit_u->axe); @@ -1483,7 +1505,13 @@ _cj_site_kick_hot(u3_noun loc, u3_noun cor, u3j_site* sit_u, c3_o lok_o) } } else { - pof_o = u3t_come(sit_u->lab); + if ( _(pof_o) ) { + pof_o = u3t_come(sit_u->lab); + } + if ( _(trc_o) ) { + trc_o = u3t_nock_trace_push(sit_u->lab); + } + if ( c3y == jet_o ) { u3t_off(glu_o); pro = _cj_kick_z(cor, sit_u->cop_u, sit_u->ham_u, sit_u->axe); @@ -1495,10 +1523,15 @@ _cj_site_kick_hot(u3_noun loc, u3_noun cor, u3j_site* sit_u, c3_o lok_o) } pro = _cj_burn(sit_u->pog_p, cor); } + if ( c3y == pof_o ) { u3t_flee(); } + if ( c3y == trc_o ) { + u3t_nock_trace_pop(); + } } + return pro; } diff --git a/noun/manage.c b/noun/manage.c index 3e30b75be4..efe295e127 100644 --- a/noun/manage.c +++ b/noun/manage.c @@ -500,6 +500,7 @@ u3m_mark(void) tot_w += u3a_mark_noun(u3R->bug.tax); tot_w += u3a_mark_noun(u3R->bug.mer); tot_w += u3a_mark_noun(u3R->pro.don); + tot_w += u3a_mark_noun(u3R->pro.trace); tot_w += u3a_mark_noun(u3R->pro.day); tot_w += u3h_mark(u3R->cax.har_p); return tot_w; @@ -1014,6 +1015,7 @@ u3m_soft_run(u3_noun gul, { u3R->ski.gul = u3nc(gul, u3to(u3_road, u3R->par_p)->ski.gul); u3R->pro.don = u3to(u3_road, u3R->par_p)->pro.don; + u3R->pro.trace = u3to(u3_road, u3R->par_p)->pro.trace; u3R->bug.tax = 0; } u3t_on(coy_o); @@ -1107,6 +1109,7 @@ u3m_soft_esc(u3_noun ref, u3_noun sam) { u3R->ski.gul = u3t(u3to(u3_road, u3R->par_p)->ski.gul); u3R->pro.don = u3to(u3_road, u3R->par_p)->pro.don; + u3R->pro.trace = u3to(u3_road, u3R->par_p)->pro.trace; u3R->bug.tax = 0; } diff --git a/noun/trace.c b/noun/trace.c index 0fbe833243..6d4d2f4a7e 100644 --- a/noun/trace.c +++ b/noun/trace.c @@ -210,7 +210,10 @@ u3t_samp(void) // it can cause memory errors. return; } + + c3_w old_wag = u3C.wag_w; u3C.wag_w &= ~u3o_debug_cpu; + u3C.wag_w &= ~u3o_trace; static int home = 0; static int away = 0; @@ -265,7 +268,7 @@ u3t_samp(void) away++; // fprintf(stderr,"home: %06d away: %06d\r\n", home, away); } - u3C.wag_w |= u3o_debug_cpu; + u3C.wag_w = old_wag; } /* u3t_come(): push on profile stack; return yes if active push. RETAIN. @@ -279,7 +282,7 @@ u3t_come(u3_noun lab) u3R->pro.don = u3nc(lab, u3R->pro.don); _ct_lop_o = c3n; return c3y; - } + } else return c3n; } @@ -295,6 +298,180 @@ u3t_flee(void) u3z(don); } +static FILE* trace_file = NULL; +static int nock_pid = 0; + +/* u3t_trace_open(): opens a trace file and writes the preamble. +*/ +void +u3t_trace_open(c3_c* trace_file_name) +{ + printf("trace: tracing to %s\n", trace_file_name); + trace_file = fopen(trace_file_name, "w"); + nock_pid = (int)getpid(); + fprintf(trace_file, "[ "); + + // We have two "threads", the event processing and the nock stuff. + // tid 1 = event processing + // tid 2 = nock processing + fprintf( + trace_file, + "{\"name\": \"process_name\", \"ph\": \"M\", \"pid\": %d, \"args\": " + "{\"name\": \"urbit\"}},\n", + nock_pid); + fprintf(trace_file, + "{\"name\": \"thread_name\", \"ph\": \"M\", \"pid\": %d, \"tid\": 1, " + "\"args\": {\"name\": \"Event Processing\"}},\n", + nock_pid); + fprintf(trace_file, + "{\"name\": \"thread_sort_index\", \"ph\": \"M\", \"pid\": %d, " + "\"tid\": 1, \"args\": {\"sort_index\": 1}},\n", + nock_pid); + fprintf(trace_file, + "{\"name\": \"thread_name\", \"ph\": \"M\", \"pid\": %d, \"tid\": 2, " + "\"args\": {\"name\": \"Nock\"}},\n", + nock_pid); + fprintf(trace_file, + "{\"name\": \"thread_sort_index\", \"ph\": \"M\", \"pid\": %d, " + "\"tid\": 2, \"args\": {\"sort_index\": 2}},\n", + nock_pid); +} + +/* u3t_trace_time(): microsecond clock +*/ +uint64_t u3t_trace_time() +{ + struct timeval tim_tv; + gettimeofday(&tim_tv, 0); + return 1000000ULL * tim_tv.tv_sec + tim_tv.tv_usec; +} + +/* u3t_nock_trace_push(): push a trace onto the trace stack; returns yes if pushed. + * + * The trace stack is a stack of [path time-entered]. + */ +c3_o +u3t_nock_trace_push(u3_noun lab) +{ + if (!trace_file) + return c3n; + + if ( (u3_nul == u3R->pro.trace) || + !_(u3r_sing(lab, u3h(u3h(u3R->pro.trace)))) ) { + u3a_gain(lab); + c3_d time = u3t_trace_time(); + u3R->pro.trace = u3nc(u3nc(lab, u3i_chubs(1, &time)), u3R->pro.trace); + return c3y; + } + else { + return c3n; + } +} + +/* _in_trace_pretty: measure/cut prettyprint. + * + * Modeled after _cm_in_pretty(), the backend to u3m_p(), but with the + * assumption that we're always displaying a path. + */ +static c3_w +_in_trace_pretty(u3_noun som, c3_c* str_c) +{ + if ( _(u3du(som)) ) { + c3_w sel_w, one_w, two_w; + if ( str_c ) { + *(str_c++) = '/'; + } + sel_w = 1; + + one_w = _in_trace_pretty(u3h(som), str_c); + if ( str_c ) { + str_c += one_w; + } + + two_w = _in_trace_pretty(u3t(som), str_c); + if ( str_c ) { + str_c += two_w; + } + + return sel_w + one_w + two_w; + } + else { + c3_w len_w = u3r_met(3, som); + if ( str_c && len_w ) { + u3r_bytes(0, len_w, (c3_y *)str_c, som); + str_c += len_w; + } + return len_w; + } +} + +static c3_c* +trace_pretty(u3_noun som) +{ + c3_w len_w = _in_trace_pretty(som, NULL); + c3_c* pre_c = malloc(len_w + 1); + + _in_trace_pretty(som, pre_c); + pre_c[len_w] = 0; + return pre_c; +} + +/* u3t_nock_trace_pop(): pops a trace from the trace stack. + * + * When we remove the trace from the stack, we check to see if the sample is + * large enough to process, as we'll otherwise keep track of individual +add + * calls. If it is, we write it out to the tracefile. + */ +void +u3t_nock_trace_pop() +{ + if (!trace_file) + return; + + u3_noun trace = u3R->pro.trace; + u3R->pro.trace = u3k(u3t(trace)); + + u3_noun item = u3h(trace); + u3_noun lab = u3h(item); + c3_d start_time = u3r_chub(0, u3t(item)); + + // 33microseconds (a 30th of a millisecond). + uint64_t duration = u3t_trace_time() - start_time; + if (duration > 33) { + c3_c* name = trace_pretty(lab); + + fprintf(trace_file, + "{\"cat\": \"nock\", \"name\": \"%s\", \"ph\":\"%c\", \"pid\": %d, " + "\"tid\": 2, \"ts\": %" PRIu64 ", \"dur\": %" PRIu64 "}, \n", + name, + 'X', + nock_pid, + start_time, + duration); + + free(name); + } + + u3z(trace); +} + +/* u3t_event_trace(): dumps a simple event from outside nock. +*/ +void +u3t_event_trace(const char* name, char type) +{ + if (!trace_file) + return; + + fprintf(trace_file, + "{\"cat\": \"event\", \"name\": \"%s\", \"ph\":\"%c\", \"pid\": %d, " + "\"tid\": 1, \"ts\": %" PRIu64 ", \"id\": \"0x100\"}, \n", + name, + type, + nock_pid, + u3t_trace_time()); +} + extern FILE* u3_term_io_hija(void); diff --git a/noun/vortex.c b/noun/vortex.c index 46538a5d33..bcbaf3d4f1 100644 --- a/noun/vortex.c +++ b/noun/vortex.c @@ -93,6 +93,7 @@ u3v_start(u3_noun now) u3_noun u3v_wish(const c3_c* str_c) { + u3t_event_trace("u3v_wish", 'b'); u3_noun txt = u3i_string(str_c); u3_weak exp = u3kdb_get(u3k(u3A->yot), u3k(txt)); @@ -107,6 +108,8 @@ u3v_wish(const c3_c* str_c) } } + u3t_event_trace("u3v_wish", 'e'); + u3z(txt); return exp; } diff --git a/vere/main.c b/vere/main.c index 0ae11fca2c..1768136ae8 100644 --- a/vere/main.c +++ b/vere/main.c @@ -94,7 +94,7 @@ _main_getopt(c3_i argc, c3_c** argv) u3_Host.ops_u.raf_c = 0; u3_Host.ops_u.nam_c = 0; - while ( (ch_i=getopt(argc, argv,"G:B:K:A:H:w:u:e:E:f:F:k:p:LabcdgqstvxPDRS")) != -1 ) { + while ( (ch_i=getopt(argc, argv,"G:B:K:A:H:w:u:j:e:E:f:F:k:p:LabcdgqstvxPDRS")) != -1 ) { switch ( ch_i ) { case 'B': { u3_Host.ops_u.pil_c = strdup(optarg); @@ -133,6 +133,10 @@ _main_getopt(c3_i argc, c3_c** argv) u3_Host.ops_u.url_c = strdup(optarg); break; } + case 'j': { + u3_Host.ops_u.json_file_c = strdup(optarg); + break; + } case 'x': { u3_Host.ops_u.tex = c3y; break; @@ -335,6 +339,7 @@ u3_ve_usage(c3_i argc, c3_c** argv) "-F ship Fake keys; also disables networking\n", "-f Fuzz testing\n", "-g Set GC flag\n", + "-j file Create json trace file\n", "-K stage Start at Hoon kernel version stage\n", "-k keys Private key file\n", "-L local networking only\n", @@ -598,6 +603,13 @@ main(c3_i argc, if ( _(u3_Host.ops_u.has) ) { u3C.wag_w |= u3o_hashless; } + + /* Set tracing flag + */ + if ( u3_Host.ops_u.json_file_c ) { + u3C.wag_w |= u3o_trace; + u3t_trace_open(u3_Host.ops_u.json_file_c); + } } u3m_boot(u3_Host.ops_u.nuu, u3_Host.ops_u.gab, diff --git a/vere/raft.c b/vere/raft.c index 8452102a8f..e14e065233 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1567,7 +1567,10 @@ _raft_punk(u3_noun ovo) } #endif + // TODO: Embed event number here? + u3t_event_trace("Running", 'b'); gon = u3m_soft(sec_w, u3v_poke, u3k(ovo)); + u3t_event_trace("Running", 'e'); #ifdef GHETTO c3_w ms_w; @@ -1656,7 +1659,9 @@ _raft_push(u3_raft* raf_u, c3_w* bob_w, c3_w len_w) if ( 1 == raf_u->pop_w ) { c3_assert(u3_raty_lead == raf_u->typ_e); + u3t_event_trace("Recording", 'b'); raf_u->ent_d = u3_sist_pack(raf_u->tem_w, c3__ov, bob_w, len_w); + u3t_event_trace("Recording", 'e'); raf_u->lat_w = raf_u->tem_w; // XX if ( !uv_is_active((uv_handle_t*)&raf_u->tim_u) ) { diff --git a/vere/reck.c b/vere/reck.c index 4a47270810..0a98887f80 100644 --- a/vere/reck.c +++ b/vere/reck.c @@ -365,6 +365,7 @@ _reck_kick_norm(u3_noun pox, u3_noun fav) void u3_reck_kick(u3_noun ovo) { + u3t_event_trace("Effect", 'b'); if ( (c3n == _reck_kick_spec(u3k(u3h(ovo)), u3k(u3t(ovo)))) && (c3n == _reck_kick_norm(u3k(u3h(ovo)), u3k(u3t(ovo)))) ) { @@ -399,4 +400,5 @@ u3_reck_kick(u3_noun ovo) #endif } u3z(ovo); + u3t_event_trace("Effect", 'e'); } From 46dc173bf6877e2f7ffaaf77c14f645b5ba02e7f Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 3 Dec 2018 17:09:56 -0500 Subject: [PATCH 07/90] update old %behn declarations in vere.h --- include/vere/vere.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/vere/vere.h b/include/vere/vere.h index 4e59a01e83..b0b54bb066 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -1024,15 +1024,15 @@ /** behn, just a timer. **/ - /* u2_behn_io_init(): initialize behn timer. + /* u3_behn_io_init(): initialize behn timer. */ void - u2_behn_io_init(void); + u3_behn_io_init(void); /* u2_behn_io_exit(): terminate timer. */ void - u2_behn_io_exit(void); + u3_behn_io_exit(void); /* u3_behn_ef_bake(): notify %behn that we're live */ From 7b475e7caa76fd8e8f5dd655ec7ea217e855afc8 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Mon, 3 Dec 2018 16:10:07 -0800 Subject: [PATCH 08/90] Remove 30ms per dill-blit. --- vere/reck.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/vere/reck.c b/vere/reck.c index 4a47270810..8c29c5f94e 100644 --- a/vere/reck.c +++ b/vere/reck.c @@ -66,6 +66,27 @@ _reck_lily(u3_noun fot, u3_noun txt, c3_l* tid_l) } } +/* _reck_orchid(): parses only a number as text + * + * Parses a text string which contains a decimal number. In practice, this + * number is always '1'. + */ +static u3_noun +_reck_orchid(u3_noun fot, u3_noun txt, c3_l* tid_l) +{ + c3_c* str = u3r_string(txt); + c3_d ato_d = strtol(str, NULL, 10); + free(str); + + if ( ato_d >= 0x80000000ULL ) { + return c3n; + } else { + *tid_l = (c3_l) ato_d; + + return c3y; + } +} + /* _reck_kick_term(): apply terminal outputs. */ static u3_noun @@ -314,7 +335,7 @@ _reck_kick_spec(u3_noun pox, u3_noun fav) if ( (c3n == u3r_cell(pud, &p_pud, &q_pud)) || (u3_nul != q_pud) || - (c3n == _reck_lily(c3__ud, u3k(p_pud), &tid_l)) ) + (c3n == _reck_orchid(c3__ud, u3k(p_pud), &tid_l)) ) { uL(fprintf(uH, "term: bad tire\n")); u3z(pox); u3z(fav); return c3n; From 2ed422e11f4399287d5af701fcd35aac31e69cd9 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 4 Dec 2018 00:53:56 -0500 Subject: [PATCH 09/90] boots with lifecycle formula, without persistent kernel formula removes now-unused vortex functions --- include/noun/vortex.h | 15 ++------------ noun/manage.c | 12 ++++++++--- noun/trace.c | 2 +- noun/vortex.c | 48 +++++++++++++------------------------------ 4 files changed, 26 insertions(+), 51 deletions(-) diff --git a/include/noun/vortex.h b/include/noun/vortex.h index 345f312e5e..d84dbf2c60 100644 --- a/include/noun/vortex.h +++ b/include/noun/vortex.h @@ -33,7 +33,6 @@ u3_noun roe; // temporary unsaved events u3_noun key; // log key, or 0 - u3_noun ken; // kernel formula u3_noun roc; // kernel core struct { // ova waiting to process @@ -65,15 +64,10 @@ u3_noun u3v_do(const c3_c* txt_c, u3_noun arg); - /* u3v_make(): make a new pier by loading a pill. + /* u3v_boot(): evaluate boot sequence, making a kernel */ void - u3v_make(c3_c* pas_c); - - /* u3v_jack(): execute kernel formula to bind jets. - */ - void - u3v_jack(void); + u3v_boot(u3_noun eve); /* u3v_start(): start time. */ @@ -160,11 +154,6 @@ void u3v_hose(void); - /* u3v_louse(): last-minute deviltry upon a bail. - */ - void - u3v_louse(c3_m how_m); - /* u3v_mark(): mark arvo kernel. */ c3_w diff --git a/noun/manage.c b/noun/manage.c index 3e30b75be4..94579b1db1 100644 --- a/noun/manage.c +++ b/noun/manage.c @@ -1707,11 +1707,17 @@ u3m_boot(c3_o nuu_o, c3_o bug_o, c3_c* dir_c, _boot_home(dir_c, pil_c, url_c, arv_c); snprintf(ful_c, 2048, "%s/.urb/urbit.pill", dir_c); - printf("boot: loading %s\r\n", ful_c); - u3v_make(ful_c); - u3v_jack(); + { + u3_noun sys = u3ke_cue(u3m_file(ful_c)); + u3_noun bot; + + u3x_trel(sys, &bot, 0, 0); + u3v_boot(u3k(bot)); + + u3z(sys); + } } else { u3v_hose(); diff --git a/noun/trace.c b/noun/trace.c index 0fbe833243..bb3a228488 100644 --- a/noun/trace.c +++ b/noun/trace.c @@ -66,7 +66,7 @@ u3t_slog(u3_noun hod) old = 1; #endif - if ( c3y == u3du(hod) ) { + if ( (0 != u3A->roc) && (c3y == u3du(hod)) ) { u3_noun pri = u3h(hod); switch ( pri ) { diff --git a/noun/vortex.c b/noun/vortex.c index 46538a5d33..7ca632efb3 100644 --- a/noun/vortex.c +++ b/noun/vortex.c @@ -24,29 +24,26 @@ _cv_nock_wish(u3_noun txt) return pro; } -/* u3v_make(): make a new pier and instantiate pill. +/* u3v_boot(): evaluate boot sequence, making a kernel */ void -u3v_make(c3_c* pas_c) +u3v_boot(u3_noun eve) { - u3_noun sys = u3ke_cue(u3m_file(pas_c)); + // ensure zero-initialized kernel + // + // So that u3t_slog won't try to print tanks. + // + u3A->roc = 0; - u3A->ken = u3k(u3h(sys)); - u3A->roc = u3k(u3t(sys)); + // lifecycle formula + // + u3_noun lyf = u3nt(2, u3nc(0, 3), u3nc(0, 2)); + u3_noun cor = u3n_nock_on(eve, lyf); - u3z(sys); -} + // save the Arvo core (at +7 of the Arvo gate) + // + u3A->roc = u3k(u3x_at(7, cor)); -/* u3v_jack(): execute kernel formula to bind jets. -*/ -void -u3v_jack(void) -{ - u3_noun cor; - - fprintf(stderr, "jack: kernel %x\r\n", u3r_mug(u3A->ken)); - cor = u3n_nock_on(0, u3k(u3A->ken)); - fprintf(stderr, "jacked\r\n"); u3z(cor); } @@ -450,22 +447,6 @@ u3v_plow(u3_noun ova) u3z(ova); } -/* u3v_louse(): last-minute deviltry upon a bail. -*/ -void -u3v_louse(c3_m how_m) -{ -#if 0 - if ( c3__exit == how_m ) { - printf("louse: nocks: %d\n", NOX); - printf("louse: washing kernel %x %d\n", u3A->ken, u3a_is_dog(u3A->ken)); - u3m_wash(u3A->ken); - - printf("kernel %x; washed mug %x\n", u3A->ken, u3r_mug(u3A->ken)); - } -#endif -} - /* _cv_mark_ova(): mark ova queue. */ c3_w @@ -503,7 +484,6 @@ u3v_mark(void) tot_w += u3a_mark_noun(arv_u->roe); tot_w += u3a_mark_noun(arv_u->key); - tot_w += u3a_mark_noun(arv_u->ken); tot_w += u3a_mark_noun(arv_u->roc); tot_w += _cv_mark_ova(arv_u->ova.egg_p); From bf4e7910dcdaf1cd2314848477f03dea15a70829 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 4 Dec 2018 00:54:56 -0500 Subject: [PATCH 10/90] loads initial filesystem from pill, -A optional for all ships --- vere/main.c | 11 ----------- vere/sist.c | 26 +++++++++++++++++++------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/vere/main.c b/vere/main.c index 0ae11fca2c..ebcd0c2a23 100644 --- a/vere/main.c +++ b/vere/main.c @@ -196,11 +196,6 @@ _main_getopt(c3_i argc, c3_c** argv) c3_t imp_t = ( (0 != u3_Host.ops_u.who_c) && (4 == strlen(u3_Host.ops_u.who_c)) ); - if ( u3_Host.ops_u.arv_c != 0 && !imp_t ) { - fprintf(stderr, "-A only makes sense when creating a new galaxy\n"); - return c3n; - } - if ( u3_Host.ops_u.ets_c == 0 && c3y == u3_Host.ops_u.etn ) { fprintf(stderr, "can't trust Ethereum snapshot without specifying " "snapshot with -E\n"); @@ -213,12 +208,6 @@ _main_getopt(c3_i argc, c3_c** argv) return c3n; } - if ( u3_Host.ops_u.arv_c == 0 && imp_t ) { - fprintf(stderr, "can't create a new galaxy without specifying " - "the initial sync path with -A\n"); - return c3n; - } - if ( u3_Host.ops_u.gen_c != 0 && u3_Host.ops_u.nuu == c3n ) { fprintf(stderr, "-G only makes sense when bootstrapping a new instance\n"); return c3n; diff --git a/vere/sist.c b/vere/sist.c index 4644ea551b..620ead285f 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -1696,15 +1696,27 @@ u3_sist_boot(void) // Authenticate and initialize terminal. u3_term_ef_bake(pig); - // queue initial galaxy sync - { - u3_noun rac = u3do("clan:title", u3k(u3A->own)); + // queue initial filesystem sync + // + // from the Arvo directory if specified + if ( 0 != u3_Host.ops_u.arv_c ) { + u3_unix_ef_initial_into(); + } + // otherwise from the pill + else { + c3_c ful_c[2048]; - if ( c3__czar == rac ) { - u3_unix_ef_initial_into(); + snprintf(ful_c, 2048, "%s/.urb/urbit.pill", u3_Host.dir_c); + + { + u3_noun sys = u3ke_cue(u3m_file(ful_c)); + u3_noun fil; + + u3x_trel(sys, 0, 0, &fil); + u3v_plow(u3k(fil)); + + u3z(sys); } - - u3z(rac); } // Create the event log From 6b3956dda0b2fa78553289170e16c2c393ede55f Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 4 Dec 2018 02:27:17 -0500 Subject: [PATCH 11/90] [CI] updates pinned arvo commit --- .travis/pin-arvo-commit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/pin-arvo-commit.txt b/.travis/pin-arvo-commit.txt index 92c82b8d06..dfd8a1c12e 100644 --- a/.travis/pin-arvo-commit.txt +++ b/.travis/pin-arvo-commit.txt @@ -1 +1 @@ -e71c57b4455c84062230b4277f95eb7047a26146 +cae4b03c5c95722fb0e5f1947ba988f72703816d From 6ea1248f9424a919c6157e68046e7d0f2382fcfe Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 4 Dec 2018 03:12:05 -0500 Subject: [PATCH 12/90] [CI] skip arvo download, retrieve pill directly --- .travis.yml | 4 ---- .travis/test.js | 6 +++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index d3170289dc..a957eb3154 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,10 +15,6 @@ before_install: install: # pwd: ~/urbit - pip3 install --user -I meson==0.44.1 - - git clone https://github.com/urbit/arvo - - cd ./arvo - - git checkout $(cat ../.travis/pin-arvo-commit.txt) - - cd .. script: - meson . ./build --buildtype=debugoptimized -Dgc=true -Dprof=true diff --git a/.travis/test.js b/.travis/test.js index 4afc094170..4efa960081 100644 --- a/.travis/test.js +++ b/.travis/test.js @@ -1,11 +1,15 @@ 'use strict'; +var fs = require('fs') var runner = require('urbit-runner') var Urbit = runner.Urbit; var ERROR = runner.ERROR; var actions = runner.actions -var args = ['-A', '../arvo', '-csgPSF', 'zod', 'zod']; +var hash = fs.readFileSync('./pin-arvo-commit.txt', 'utf-8').slice(0, 10) +var pill = 'https://bootstrap.urbit.org/git-' + hash + '.pill' + +var args = ['-u', pill, '-cgPSF', 'zod', 'zod']; var urbit = new Urbit(args); // vere hangs (always?) with run in travis-ci with -P From 4a53ebc6c5bdf3026dac93b99a33f393649a5b14 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Tue, 4 Dec 2018 14:46:25 -0800 Subject: [PATCH 13/90] Cleanup --- include/noun/trace.h | 9 +++++-- include/vere/vere.h | 2 +- noun/trace.c | 56 +++++++++++++++++++++++++++----------------- vere/loop.c | 5 ++++ 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/include/noun/trace.h b/include/noun/trace.h index 049c552181..e8ba7348a4 100644 --- a/include/noun/trace.h +++ b/include/noun/trace.h @@ -88,7 +88,12 @@ void u3t_trace_open(c3_c*); - /* u3t_nock_trace_push(): pushes a frame ont o the trace stack; + /* u3t_trace_close(): closes the trace file. optional. + */ + void + u3t_trace_close(); + + /* u3t_nock_trace_push(): pushes a frame onto the trace stack; * return yes if active push. */ c3_o @@ -99,7 +104,7 @@ void u3t_nock_trace_pop(); - /* u3t_even_trace(): record a lifecycle event. + /* u3t_event_trace(): record a lifecycle event. */ void u3t_event_trace(const char* name, char type); diff --git a/include/vere/vere.h b/include/vere/vere.h index 79cc76b7ec..972f0aedf6 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -632,7 +632,7 @@ c3_o liv; // if u3_no, shut down c3_i xit_i; // exit code for shutdown void* tls_u; // server SSL_CTX* - FILE* trace_file; // trace file to write to + FILE* trace_file_u; // trace file to write to } u3_host; // host == computer == process # define u3L u3_Host.lup_u // global event loop diff --git a/noun/trace.c b/noun/trace.c index 6d4d2f4a7e..51dfd0f667 100644 --- a/noun/trace.c +++ b/noun/trace.c @@ -298,8 +298,8 @@ u3t_flee(void) u3z(don); } -static FILE* trace_file = NULL; -static int nock_pid = 0; +static FILE* trace_file_u = NULL; +static int nock_pid_i = 0; /* u3t_trace_open(): opens a trace file and writes the preamble. */ @@ -307,34 +307,46 @@ void u3t_trace_open(c3_c* trace_file_name) { printf("trace: tracing to %s\n", trace_file_name); - trace_file = fopen(trace_file_name, "w"); - nock_pid = (int)getpid(); - fprintf(trace_file, "[ "); + trace_file_u = fopen(trace_file_name, "w"); + nock_pid_i = (int)getpid(); + fprintf(trace_file_u, "[ "); // We have two "threads", the event processing and the nock stuff. // tid 1 = event processing // tid 2 = nock processing fprintf( - trace_file, + trace_file_u, "{\"name\": \"process_name\", \"ph\": \"M\", \"pid\": %d, \"args\": " "{\"name\": \"urbit\"}},\n", - nock_pid); - fprintf(trace_file, + nock_pid_i); + fprintf(trace_file_u, "{\"name\": \"thread_name\", \"ph\": \"M\", \"pid\": %d, \"tid\": 1, " "\"args\": {\"name\": \"Event Processing\"}},\n", - nock_pid); - fprintf(trace_file, + nock_pid_i); + fprintf(trace_file_u, "{\"name\": \"thread_sort_index\", \"ph\": \"M\", \"pid\": %d, " "\"tid\": 1, \"args\": {\"sort_index\": 1}},\n", - nock_pid); - fprintf(trace_file, + nock_pid_i); + fprintf(trace_file_u, "{\"name\": \"thread_name\", \"ph\": \"M\", \"pid\": %d, \"tid\": 2, " "\"args\": {\"name\": \"Nock\"}},\n", - nock_pid); - fprintf(trace_file, + nock_pid_i); + fprintf(trace_file_u, "{\"name\": \"thread_sort_index\", \"ph\": \"M\", \"pid\": %d, " "\"tid\": 2, \"args\": {\"sort_index\": 2}},\n", - nock_pid); + nock_pid_i); +} + +/* u3t_trace_close(): closes a trace file. optional. +*/ +void +u3t_trace_close() +{ + if (!trace_file_u) + return; + + // We don't terminate the JSON because of the file format. + fclose(trace_file_u); } /* u3t_trace_time(): microsecond clock @@ -353,7 +365,7 @@ uint64_t u3t_trace_time() c3_o u3t_nock_trace_push(u3_noun lab) { - if (!trace_file) + if (!trace_file_u) return c3n; if ( (u3_nul == u3R->pro.trace) || @@ -425,7 +437,7 @@ trace_pretty(u3_noun som) void u3t_nock_trace_pop() { - if (!trace_file) + if (!trace_file_u) return; u3_noun trace = u3R->pro.trace; @@ -440,12 +452,12 @@ u3t_nock_trace_pop() if (duration > 33) { c3_c* name = trace_pretty(lab); - fprintf(trace_file, + fprintf(trace_file_u, "{\"cat\": \"nock\", \"name\": \"%s\", \"ph\":\"%c\", \"pid\": %d, " "\"tid\": 2, \"ts\": %" PRIu64 ", \"dur\": %" PRIu64 "}, \n", name, 'X', - nock_pid, + nock_pid_i, start_time, duration); @@ -460,15 +472,15 @@ u3t_nock_trace_pop() void u3t_event_trace(const char* name, char type) { - if (!trace_file) + if (!trace_file_u) return; - fprintf(trace_file, + fprintf(trace_file_u, "{\"cat\": \"event\", \"name\": \"%s\", \"ph\":\"%c\", \"pid\": %d, " "\"tid\": 1, \"ts\": %" PRIu64 ", \"id\": \"0x100\"}, \n", name, type, - nock_pid, + nock_pid_i, u3t_trace_time()); } diff --git a/vere/loop.c b/vere/loop.c index 84b582edce..59cc76f70a 100644 --- a/vere/loop.c +++ b/vere/loop.c @@ -252,6 +252,11 @@ u3_lo_exit(void) cod_l = u3a_lush(c3__behn); u3_behn_io_exit(); u3a_lop(cod_l); + + if ( c3y == __(u3C.wag_w & u3o_trace) ) { + printf("saving trace file.\r\n"); + u3t_trace_close(); + } } #if 0 From ee38b881887b4238b21c1859f308fc92ef2654d9 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Tue, 4 Dec 2018 15:59:33 -0800 Subject: [PATCH 14/90] Cleanup --- noun/trace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noun/trace.c b/noun/trace.c index 51dfd0f667..4ef31bb5e6 100644 --- a/noun/trace.c +++ b/noun/trace.c @@ -351,7 +351,7 @@ u3t_trace_close() /* u3t_trace_time(): microsecond clock */ -uint64_t u3t_trace_time() +c3_d u3t_trace_time() { struct timeval tim_tv; gettimeofday(&tim_tv, 0); @@ -448,7 +448,7 @@ u3t_nock_trace_pop() c3_d start_time = u3r_chub(0, u3t(item)); // 33microseconds (a 30th of a millisecond). - uint64_t duration = u3t_trace_time() - start_time; + c3_d duration = u3t_trace_time() - start_time; if (duration > 33) { c3_c* name = trace_pretty(lab); From 36f2152e614d415edb771767556095ac993a957e Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Tue, 4 Dec 2018 16:20:22 -0800 Subject: [PATCH 15/90] Move more chars. --- include/noun/trace.h | 2 +- noun/trace.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/noun/trace.h b/include/noun/trace.h index e8ba7348a4..0654862d0a 100644 --- a/include/noun/trace.h +++ b/include/noun/trace.h @@ -107,7 +107,7 @@ /* u3t_event_trace(): record a lifecycle event. */ void - u3t_event_trace(const char* name, char type); + u3t_event_trace(const c3_c* name, c3_c type); /* u3t_damp(): print and clear profile data. */ diff --git a/noun/trace.c b/noun/trace.c index 4ef31bb5e6..30c3a31a93 100644 --- a/noun/trace.c +++ b/noun/trace.c @@ -470,7 +470,7 @@ u3t_nock_trace_pop() /* u3t_event_trace(): dumps a simple event from outside nock. */ void -u3t_event_trace(const char* name, char type) +u3t_event_trace(const c3_c* name, c3_c type) { if (!trace_file_u) return; From e611cc34c46923f2b612ac496bc7e2fac40658a1 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Tue, 4 Dec 2018 15:58:52 -0800 Subject: [PATCH 16/90] Use +slaw instead of +slay. --- vere/reck.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/vere/reck.c b/vere/reck.c index 8c29c5f94e..2df3284881 100644 --- a/vere/reck.c +++ b/vere/reck.c @@ -27,20 +27,18 @@ _reck_mole(u3_noun fot, u3_noun san, c3_d* ato_d) { - u3_noun uco = u3do("slay", san); - u3_noun p_uco, q_uco, r_uco, s_uco; + u3_noun uco = u3dc("slaw", fot, san); + u3_noun p_uco, q_uco; - if ( (c3n == u3r_qual(uco, &p_uco, &q_uco, &r_uco, &s_uco)) || - (0 != p_uco) || - (0 != q_uco) || - (c3n == u3r_sing(fot, r_uco)) ) + if ( (c3n == u3r_cell(uco, &p_uco, &q_uco)) || + (0 != p_uco) ) { uL(fprintf(uH, "strange mole %s\n", u3r_string(san))); u3z(fot); u3z(uco); return c3n; } else { - *ato_d = u3r_chub(0, s_uco); + *ato_d = u3r_chub(0, q_uco); u3z(fot); u3z(uco); return c3y; } From 39eb89d66b5ee60f15179652c91c28622a862b26 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Tue, 4 Dec 2018 16:40:19 -0800 Subject: [PATCH 17/90] Use u3_nul --- vere/reck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vere/reck.c b/vere/reck.c index 2df3284881..d8bb694c15 100644 --- a/vere/reck.c +++ b/vere/reck.c @@ -31,7 +31,7 @@ _reck_mole(u3_noun fot, u3_noun p_uco, q_uco; if ( (c3n == u3r_cell(uco, &p_uco, &q_uco)) || - (0 != p_uco) ) + (u3_nul != p_uco) ) { uL(fprintf(uH, "strange mole %s\n", u3r_string(san))); From 384a2a15550e972418beeda4be85b509b01feba3 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 3 Dec 2018 14:18:41 -0500 Subject: [PATCH 18/90] moves ethereum-integrated pre-boot validation to vere/dawn --- include/vere/vere.h | 11 ++ meson.build | 1 + vere/dawn.c | 444 ++++++++++++++++++++++++++++++++++++++++++++ vere/sist.c | 423 +---------------------------------------- 4 files changed, 458 insertions(+), 421 deletions(-) create mode 100644 vere/dawn.c diff --git a/include/vere/vere.h b/include/vere/vere.h index c1f6935e95..9d81e4e830 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -1197,3 +1197,14 @@ */ void u3_cttp_io_exit(void); + + + /* u3_dawn_come(): mine a comet under star (unit) + */ + u3_noun + u3_dawn_come(u3_noun star); + + /* u3_dawn_vent(): validatated boot event + */ + u3_noun + u3_dawn_vent(u3_noun seed); diff --git a/meson.build b/meson.build index 405bd0d506..a4925d434f 100644 --- a/meson.build +++ b/meson.build @@ -213,6 +213,7 @@ vere_sans_main = [ 'vere/ames.c', 'vere/behn.c', 'vere/cttp.c', + 'vere/dawn.c', 'vere/http.c', 'vere/loop.c', 'vere/raft.c', diff --git a/vere/dawn.c b/vere/dawn.c new file mode 100644 index 0000000000..45252861b9 --- /dev/null +++ b/vere/dawn.c @@ -0,0 +1,444 @@ +/* vere/dawn.c +** +** ethereum-integrated pre-boot validation +*/ +#include +#include +#include +#include "all.h" +#include "vere/vere.h" + +/* _dawn_curl_alloc(): allocate a response buffer for curl +*/ +static size_t +_dawn_curl_alloc(void* dat_v, size_t uni_t, size_t mem_t, uv_buf_t* buf_u) +{ + size_t siz_t = uni_t * mem_t; + buf_u->base = realloc(buf_u->base, 1 + siz_t + buf_u->len); + + if ( 0 == buf_u->base ) { + fprintf(stderr, "out of memory\n"); + u3_lo_bail(); + } + + memcpy(buf_u->base + buf_u->len, dat_v, siz_t); + buf_u->len += siz_t; + buf_u->base[buf_u->len] = 0; + + return siz_t; +} + +/* _dawn_post_json(): POST JSON to url_c +*/ +static uv_buf_t +_dawn_post_json(c3_c* url_c, uv_buf_t lod_u) +{ + CURL *curl; + CURLcode result; + long cod_l; + struct curl_slist* hed_u = 0; + + uv_buf_t buf_u = uv_buf_init(c3_malloc(1), 0); + + if ( !(curl = curl_easy_init()) ) { + fprintf(stderr, "failed to initialize libcurl\n"); + u3_lo_bail(); + } + + hed_u = curl_slist_append(hed_u, "Accept: application/json"); + hed_u = curl_slist_append(hed_u, "Content-Type: application/json"); + hed_u = curl_slist_append(hed_u, "charsets: utf-8"); + + // XX require TLS, pin default cert? + + curl_easy_setopt(curl, CURLOPT_URL, url_c); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _dawn_curl_alloc); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&buf_u); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hed_u); + + // note: must be terminated! + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, lod_u.base); + + result = curl_easy_perform(curl); + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &cod_l); + + // XX retry? + if ( CURLE_OK != result ) { + fprintf(stderr, "failed to fetch %s: %s\n", + url_c, curl_easy_strerror(result)); + u3_lo_bail(); + } + if ( 300 <= cod_l ) { + fprintf(stderr, "error fetching %s: HTTP %ld\n", url_c, cod_l); + u3_lo_bail(); + } + + curl_easy_cleanup(curl); + curl_slist_free_all(hed_u); + + return buf_u; +} + +/* _dawn_oct_to_buf(): +octs to uv_buf_t +*/ +static uv_buf_t +_dawn_oct_to_buf(u3_noun oct) +{ + if ( c3n == u3a_is_cat(u3h(oct)) ) { + u3_lo_bail(); + } + + c3_w len_w = u3h(oct); + c3_y* buf_y = c3_malloc(1 + len_w); + buf_y[len_w] = 0; + + u3r_bytes(0, len_w, buf_y, u3t(oct)); + + u3z(oct); + return uv_buf_init((void*)buf_y, len_w); +} + +/* _dawn_buf_to_oct(): uv_buf_t to +octs +*/ +static u3_noun +_dawn_buf_to_oct(uv_buf_t buf_u) +{ + u3_noun len = u3i_words(1, (c3_w*)&buf_u.len); + + if ( c3n == u3a_is_cat(len) ) { + u3_lo_bail(); + } + + return u3nc(len, u3i_bytes(buf_u.len, (const c3_y*)buf_u.base)); +} + +/* _dawn_eth_rpc(): ethereum JSON RPC with request/response as +octs +*/ +static u3_noun +_dawn_eth_rpc(c3_c* url_c, u3_noun oct) +{ + return _dawn_buf_to_oct(_dawn_post_json(url_c, _dawn_oct_to_buf(oct))); +} + +/* _dawn_fail(): pre-boot validation failed +*/ +static void +_dawn_fail(u3_noun who, u3_noun rac, u3_noun sas) +{ + u3_noun how = u3dc("scot", 'p', u3k(who)); + c3_c* how_c = u3r_string(u3k(how)); + + c3_c* rac_c; + + switch (rac) { + default: c3_assert(0); + case c3__czar: { + rac_c = "galaxy"; + break; + } + case c3__king: { + rac_c = "star"; + break; + } + case c3__duke: { + rac_c = "planet"; + break; + } + case c3__earl: { + rac_c = "moon"; + break; + } + case c3__pawn: { + rac_c = "comet"; + break; + } + } + + fprintf(stderr, "dawn: invalid keys for %s '%s'\r\n", rac_c, how_c); + + // XX deconstruct sas, print helpful error messages + u3m_p("pre-boot error", u3t(sas)); + + u3z(how); + free(how_c); + u3_lo_bail(); +} + +/* _dawn_purl(): ethereum gateway url as (unit purl) +*/ +static u3_noun +_dawn_purl(u3_noun rac) +{ + u3_noun url; + + if ( 0 == u3_Host.ops_u.eth_c ) { + if ( c3__czar == rac ) { + fprintf(stderr, "boot: galaxy requires ethereum gateway via -e\r\n"); + u3_lo_bail(); + } + + url = u3_nul; + } + else { + // XX call de-purl directly + // + u3_noun par = u3v_wish("auru:de-purl:html"); + u3_noun lur = u3i_string(u3_Host.ops_u.eth_c); + u3_noun rul = u3dc("rush", u3k(lur), u3k(par)); + + if ( u3_nul == rul ) { + if ( c3__czar == rac ) { + fprintf(stderr, "boot: galaxy requires ethereum gateway via -e\r\n"); + u3_lo_bail(); + } + + url = u3_nul; + } + else { + // XX revise for de-purl + // auru:de-purl:html parses to (pair user purl) + // we need (unit purl) + // + url = u3nc(u3_nul, u3k(u3t(u3t(rul)))); + } + + u3z(par); u3z(lur); u3z(rul); + } + + return url; +} + +/* _dawn_turf(): override contract domains with -H +*/ +static u3_noun +_dawn_turf(c3_c* dns_c) +{ + u3_noun tuf; + + u3_noun par = u3v_wish("thos:de-purl:html"); + u3_noun dns = u3i_string(dns_c); + u3_noun rul = u3dc("rush", u3k(dns), u3k(par)); + + if ( (u3_nul == rul) || (c3n == u3h(u3t(rul))) ) { + fprintf(stderr, "boot: invalid domain specified with -H %s\r\n", dns_c); + // bails, won't return + u3_lo_bail(); + return u3_none; + } + else { + fprintf(stderr, "boot: overriding network domains with %s\r\n", dns_c); + u3_noun dom = u3t(u3t(rul)); + tuf = u3nc(u3k(dom), u3_nul); + } + + u3z(par); u3z(dns); u3z(rul); + + return tuf; +} + +/* u3_dawn_vent(): validatated boot event +*/ +u3_noun +u3_dawn_vent(u3_noun seed) +{ + u3_noun url, bok, pon, zar, tuf, sap; + + u3_noun ship = u3h(seed); + u3_noun rank = u3do("clan:title", u3k(ship)); + + // load snapshot if exists + // + if ( 0 != u3_Host.ops_u.ets_c ) { + fprintf(stderr, "boot: loading ethereum snapshot\r\n"); + u3_noun raw_snap = u3ke_cue(u3m_file(u3_Host.ops_u.ets_c)); + sap = u3nc(u3_nul, raw_snap); + } + else { + sap = u3_nul; + } + + url = _dawn_purl(rank); + + // XX require https? + // + c3_c* url_c = ( 0 != u3_Host.ops_u.eth_c ) ? + u3_Host.ops_u.eth_c : + "https://ropsten.infura.io/v3/196a7f37c7d54211b4a07904ec73ad87"; + + // pin block number + // + if ( c3y == u3_Host.ops_u.etn ) { + fprintf(stderr, "boot: extracting block from snapshot\r\n"); + bok = u3do("bloq:snap:dawn", u3k(u3t(sap))); + } + else { + fprintf(stderr, "boot: retrieving latest block\r\n"); + + u3_noun oct = u3v_wish("bloq:give:dawn"); + u3_noun kob = _dawn_eth_rpc(url_c, u3k(oct)); + bok = u3do("bloq:take:dawn", u3k(kob)); + + u3z(oct); u3z(kob); + } + + { + // +hull:constitution:ethe: on-chain state + // + u3_noun hul; + + if ( c3y == u3_Host.ops_u.etn ) { + hul = u3dc("hull:snap:dawn", u3k(ship), u3k(u3t(sap))); + } + else if ( c3__pawn == rank ) { + // irrelevant, just bunt +hull + // + hul = u3v_wish("*hull:constitution:ethe"); + } + else { + u3_noun oct; + + if ( c3__earl == rank ) { + u3_noun seg = u3do("^sein:title", u3k(ship)); + u3_noun ges = u3dc("scot", 'p', u3k(seg)); + c3_c* seg_c = u3r_string(ges); + + fprintf(stderr, "boot: retrieving %s's public keys (for %s)\r\n", + seg_c, u3_Host.ops_u.who_c); + oct = u3dc("hull:give:dawn", u3k(bok), u3k(seg)); + + free(seg_c); + u3z(seg); u3z(ges); + } + else { + fprintf(stderr, "boot: retrieving %s's public keys\r\n", + u3_Host.ops_u.who_c); + oct = u3dc("hull:give:dawn", u3k(bok), u3k(ship)); + } + + u3_noun luh = _dawn_eth_rpc(url_c, u3k(oct)); + hul = u3dc("hull:take:dawn", u3k(ship), u3k(luh)); + + u3z(oct); u3z(luh); + } + + // +live:dawn: network state + // XX actually make request + // + u3_noun liv = u3_nul; + // u3_noun liv = _dawn_get_json(parent, /some/url) + + fprintf(stderr, "boot: verifying keys\r\n"); + + // (each sponsor=(unit ship) error=@tas) + // + u3_noun sas = u3dt("veri:dawn", u3k(seed), u3k(hul), u3k(liv)); + + if ( c3n == u3h(sas) ) { + // bails, won't return + _dawn_fail(ship, rank, sas); + return u3_none; + } + + // (unit ship): sponsor + // produced by +veri:dawn to avoid coupling to +hull structure + // XX reconsider + // + pon = u3k(u3t(sas)); + + u3z(hul); u3z(liv); u3z(sas); + } + + // (map ship [=life =pass]): galaxy table + // + if ( c3y == u3_Host.ops_u.etn ) { + zar = u3do("czar:snap:dawn", u3k(u3t(sap))); + } + else { + fprintf(stderr, "boot: retrieving galaxy table\r\n"); + + u3_noun oct = u3do("czar:give:dawn", u3k(bok)); + u3_noun raz = _dawn_eth_rpc(url_c, u3k(oct)); + zar = u3do("czar:take:dawn", u3k(raz)); + + u3z(oct); u3z(raz); + } + + // (list turf): ames domains + // + if ( 0 != u3_Host.ops_u.dns_c ) { + tuf = _dawn_turf(u3_Host.ops_u.dns_c); + } + else if ( c3y == u3_Host.ops_u.etn ) { + tuf = u3do("turf:snap:dawn", u3k(u3t(sap))); + } + else { + fprintf(stderr, "boot: retrieving network domains\r\n"); + + u3_noun oct = u3do("turf:give:dawn", u3k(bok)); + u3_noun fut = _dawn_eth_rpc(url_c, u3k(oct)); + tuf = u3do("turf:take:dawn", u3k(fut)); + + u3z(oct); u3z(fut); + } + + u3z(rank); + + // [%dawn seed sponsor galaxies domains block eth-url snap] + // + return u3nc(c3__dawn, u3nq(seed, pon, zar, u3nq(tuf, bok, url, sap))); +} + +/* u3_dawn_come(): mine a comet under star (unit) +*/ +u3_noun +u3_dawn_come(u3_noun star) +{ + u3_noun seed; + + if ( u3_nul == star ) { + // XX ~marzod hardcoded + // choose from list, at random, &c + // + star = 256; + } + else { + // XX parse and validate + // + u3_noun tar = u3k(u3t(star)); + u3z(star); + star = tar; + } + + { + u3_noun sar = u3dc("scot", 'p', u3k(star)); + c3_c* tar_c = u3r_string(sar); + + fprintf(stderr, "boot: mining a comet under %s\r\n", tar_c); + free(tar_c); + u3z(sar); + } + + { + c3_w eny_w[16]; + u3_noun eny; + + c3_rand(eny_w); + eny = u3i_words(16, eny_w); + + seed = u3dc("come:dawn", u3k(star), u3k(eny)); + u3z(eny); + } + + { + u3_noun who = u3dc("scot", 'p', u3k(u3h(seed))); + c3_c* who_c = u3r_string(who); + + fprintf(stderr, "boot: found comet %s\r\n", who_c); + free(who_c); + u3z(who); + } + + u3z(star); + + return seed; +} diff --git a/vere/sist.c b/vere/sist.c index 4644ea551b..965c6e402c 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "all.h" @@ -21,7 +20,6 @@ #define DEVRANDOM "/dev/random" #endif - /* u3_sist_pack(): write a blob to disk, transferring. */ c3_d @@ -1136,423 +1134,6 @@ _sist_rest() } } -/* _sist_curl_alloc(): allocate a response buffer for curl -*/ -static size_t -_sist_curl_alloc(void* dat_v, size_t uni_t, size_t mem_t, uv_buf_t* buf_u) -{ - size_t siz_t = uni_t * mem_t; - buf_u->base = realloc(buf_u->base, 1 + siz_t + buf_u->len); - - if ( 0 == buf_u->base ) { - fprintf(stderr, "out of memory\n"); - u3_lo_bail(); - } - - memcpy(buf_u->base + buf_u->len, dat_v, siz_t); - buf_u->len += siz_t; - buf_u->base[buf_u->len] = 0; - - return siz_t; -} - -/* _sist_post_json(): POST JSON to url_c -*/ -static uv_buf_t -_sist_post_json(c3_c* url_c, uv_buf_t lod_u) -{ - CURL *curl; - CURLcode result; - long cod_l; - struct curl_slist* hed_u = 0; - - uv_buf_t buf_u = uv_buf_init(c3_malloc(1), 0); - - if ( !(curl = curl_easy_init()) ) { - fprintf(stderr, "failed to initialize libcurl\n"); - u3_lo_bail(); - } - - hed_u = curl_slist_append(hed_u, "Accept: application/json"); - hed_u = curl_slist_append(hed_u, "Content-Type: application/json"); - hed_u = curl_slist_append(hed_u, "charsets: utf-8"); - - // XX require TLS, pin default cert? - - curl_easy_setopt(curl, CURLOPT_URL, url_c); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _sist_curl_alloc); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&buf_u); - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, hed_u); - - // note: must be terminated! - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, lod_u.base); - - result = curl_easy_perform(curl); - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &cod_l); - - // XX retry? - if ( CURLE_OK != result ) { - fprintf(stderr, "failed to fetch %s: %s\n", - url_c, curl_easy_strerror(result)); - u3_lo_bail(); - } - if ( 300 <= cod_l ) { - fprintf(stderr, "error fetching %s: HTTP %ld\n", url_c, cod_l); - u3_lo_bail(); - } - - curl_easy_cleanup(curl); - curl_slist_free_all(hed_u); - - return buf_u; -} - -/* _sist_oct_to_buf(): +octs to uv_buf_t -*/ -static uv_buf_t -_sist_oct_to_buf(u3_noun oct) -{ - if ( c3n == u3a_is_cat(u3h(oct)) ) { - u3_lo_bail(); - } - - c3_w len_w = u3h(oct); - c3_y* buf_y = c3_malloc(1 + len_w); - buf_y[len_w] = 0; - - u3r_bytes(0, len_w, buf_y, u3t(oct)); - - u3z(oct); - return uv_buf_init((void*)buf_y, len_w); -} - -/* _sist_buf_to_oct(): uv_buf_t to +octs -*/ -static u3_noun -_sist_buf_to_oct(uv_buf_t buf_u) -{ - u3_noun len = u3i_words(1, (c3_w*)&buf_u.len); - - if ( c3n == u3a_is_cat(len) ) { - u3_lo_bail(); - } - - return u3nc(len, u3i_bytes(buf_u.len, (const c3_y*)buf_u.base)); -} - -/* _sist_eth_rpc(): ethereum JSON RPC with request/response as +octs -*/ -static u3_noun -_sist_eth_rpc(c3_c* url_c, u3_noun oct) -{ - return _sist_buf_to_oct(_sist_post_json(url_c, _sist_oct_to_buf(oct))); -} - -/* _sist_dawn_fail(): pre-boot validation failed -*/ -static void -_sist_dawn_fail(u3_noun who, u3_noun rac, u3_noun sas) -{ - u3_noun how = u3dc("scot", 'p', u3k(who)); - c3_c* how_c = u3r_string(u3k(how)); - - c3_c* rac_c; - - switch (rac) { - default: c3_assert(0); - case c3__czar: { - rac_c = "galaxy"; - break; - } - case c3__king: { - rac_c = "star"; - break; - } - case c3__duke: { - rac_c = "planet"; - break; - } - case c3__earl: { - rac_c = "moon"; - break; - } - case c3__pawn: { - rac_c = "comet"; - break; - } - } - - fprintf(stderr, "dawn: invalid keys for %s '%s'\r\n", rac_c, how_c); - - // XX deconstruct sas, print helpful error messages - u3m_p("pre-boot error", u3t(sas)); - - u3z(how); - free(how_c); - u3_lo_bail(); -} - -/* _sist_dawn_turf(): override contract domains with -H -*/ -static u3_noun -_sist_dawn_turf(c3_c* dns_c) -{ - u3_noun tuf; - - u3_noun par = u3v_wish("thos:de-purl:html"); - u3_noun dns = u3i_string(dns_c); - u3_noun rul = u3dc("rush", u3k(dns), u3k(par)); - - if ( (u3_nul == rul) || (c3n == u3h(u3t(rul))) ) { - fprintf(stderr, "boot: invalid domain specified with -H %s\r\n", dns_c); - // bails, won't return - u3_lo_bail(); - return u3_none; - } - else { - fprintf(stderr, "boot: overriding network domains with %s\r\n", dns_c); - u3_noun dom = u3t(u3t(rul)); - tuf = u3nc(u3k(dom), u3_nul); - } - - u3z(par); u3z(dns); u3z(rul); - - return tuf; -} - -/* _sist_dawn(): produce %dawn boot card - validate keys and query contract -*/ -static u3_noun -_sist_dawn(u3_noun sed) -{ - u3_noun url, bok, pon, zar, tuf, sap; - - u3_noun who = u3h(sed); - u3_noun rac = u3do("clan:title", u3k(who)); - - // load snapshot if exists - if ( 0 != u3_Host.ops_u.ets_c ) { - fprintf(stderr, "boot: loading ethereum snapshot\r\n"); - u3_noun raw_snap = u3ke_cue(u3m_file(u3_Host.ops_u.ets_c)); - sap = u3nc(u3_nul, raw_snap); - } - else { - sap = u3_nul; - } - - // ethereum gateway as (unit purl) - if ( 0 == u3_Host.ops_u.eth_c ) { - if ( c3__czar == rac ) { - fprintf(stderr, "boot: galaxy requires ethereum gateway via -e\r\n"); - // bails, won't return - u3_lo_bail(); - return u3_none; - } - - url = u3_nul; - } - else { - u3_noun par = u3v_wish("auru:de-purl:html"); - u3_noun lur = u3i_string(u3_Host.ops_u.eth_c); - u3_noun rul = u3dc("rush", u3k(lur), u3k(par)); - - if ( u3_nul == rul ) { - if ( c3__czar == rac ) { - fprintf(stderr, "boot: galaxy requires ethereum gateway via -e\r\n"); - // bails, won't return - u3_lo_bail(); - return u3_none; - } - - url = u3_nul; - } - else { - // auru:de-purl:html parses to (pair user purl) - // we need (unit purl) - // (we're using it to avoid the +hoke weirdness) - // XX revisit upon merging with release-candidate - url = u3nc(u3_nul, u3k(u3t(u3t(rul)))); - } - - u3z(par); u3z(lur); u3z(rul); - } - - // XX require https? - c3_c* url_c = ( 0 != u3_Host.ops_u.eth_c ) ? - u3_Host.ops_u.eth_c : - "https://ropsten.infura.io/v3/196a7f37c7d54211b4a07904ec73ad87"; - - { - fprintf(stderr, "boot: retrieving latest block\r\n"); - - if ( c3y == u3_Host.ops_u.etn ) { - bok = u3do("bloq:snap:dawn", u3k(u3t(sap))); - } - else { - // @ud: block number - u3_noun oct = u3v_wish("bloq:give:dawn"); - u3_noun kob = _sist_eth_rpc(url_c, u3k(oct)); - bok = u3do("bloq:take:dawn", u3k(kob)); - - u3z(oct); u3z(kob); - } - } - - { - // +hull:constitution:ethe: on-chain state - u3_noun hul; - - if ( c3y == u3_Host.ops_u.etn ) { - hul = u3dc("hull:snap:dawn", u3k(who), u3k(u3t(sap))); - } - else { - if ( c3__pawn == rac ) { - // irrelevant, just bunt +hull - hul = u3v_wish("*hull:constitution:ethe"); - } - else { - u3_noun oct; - - if ( c3__earl == rac ) { - u3_noun seg = u3do("^sein:title", u3k(who)); - u3_noun ges = u3dc("scot", 'p', u3k(seg)); - c3_c* seg_c = u3r_string(ges); - - fprintf(stderr, "boot: retrieving %s's public keys (for %s)\r\n", - seg_c, u3_Host.ops_u.who_c); - oct = u3dc("hull:give:dawn", u3k(bok), u3k(seg)); - - free(seg_c); - u3z(seg); u3z(ges); - } - else { - fprintf(stderr, "boot: retrieving %s's public keys\r\n", - u3_Host.ops_u.who_c); - oct = u3dc("hull:give:dawn", u3k(bok), u3k(who)); - } - - u3_noun luh = _sist_eth_rpc(url_c, u3k(oct)); - hul = u3dc("hull:take:dawn", u3k(who), u3k(luh)); - - u3z(oct); u3z(luh); - } - } - - // +live:dawn: network state - // XX actually make request - // u3_noun liv = _sist_get_json(parent, /some/url) - u3_noun liv = u3_nul; - - fprintf(stderr, "boot: verifying keys\r\n"); - - // (each sponsor=(unit ship) error=@tas) - u3_noun sas = u3dt("veri:dawn", u3k(sed), u3k(hul), u3k(liv)); - - if ( c3n == u3h(sas) ) { - // bails, won't return - _sist_dawn_fail(who, rac, sas); - return u3_none; - } - - // (unit ship): sponsor - // produced by +veri:dawn to avoid coupling to +hull structure - pon = u3k(u3t(sas)); - - u3z(hul); u3z(liv); u3z(sas); - } - - { - if ( c3y == u3_Host.ops_u.etn ) { - zar = u3do("czar:snap:dawn", u3k(u3t(sap))); - - if ( 0 != u3_Host.ops_u.dns_c ) { - tuf = _sist_dawn_turf(u3_Host.ops_u.dns_c); - } - else { - tuf = u3do("turf:snap:dawn", u3k(u3t(sap))); - } - } - else { - { - fprintf(stderr, "boot: retrieving galaxy table\r\n"); - - // (map ship [=life =pass]): galaxy table - u3_noun oct = u3do("czar:give:dawn", u3k(bok)); - u3_noun raz = _sist_eth_rpc(url_c, u3k(oct)); - zar = u3do("czar:take:dawn", u3k(raz)); - - u3z(oct); u3z(raz); - } - - if ( 0 != u3_Host.ops_u.dns_c ) { - tuf = _sist_dawn_turf(u3_Host.ops_u.dns_c); - } - else { - fprintf(stderr, "boot: retrieving network domains\r\n"); - - // (list turf): ames domains - u3_noun oct = u3do("turf:give:dawn", u3k(bok)); - u3_noun fut = _sist_eth_rpc(url_c, u3k(oct)); - tuf = u3do("turf:take:dawn", u3k(fut)); - - u3z(oct); u3z(fut); - } - } - } - - u3z(rac); - - // [%dawn seed sponsor galaxies domains block eth-url snap] - return u3nc(c3__dawn, u3nq(sed, pon, zar, u3nq(tuf, bok, url, sap))); -} - -/* _sist_zen(): get OS entropy. -*/ -static u3_noun -_sist_zen(void) -{ - c3_w rad_w[16]; - - c3_rand(rad_w); - return u3i_words(16, rad_w); -} - -/* _sist_come(): mine a comet. -*/ -static u3_noun -_sist_come(void) -{ - u3_noun tar, eny, sed; - - // XX choose from list, at random, &c - tar = u3dc("slav", 'p', u3i_string("~marzod")); - eny = _sist_zen(); - - { - u3_noun sar = u3dc("scot", 'p', u3k(tar)); - c3_c* tar_c = u3r_string(sar); - - fprintf(stderr, "boot: mining a comet under %s\r\n", tar_c); - free(tar_c); - u3z(sar); - } - - sed = u3dc("come:dawn", u3k(tar), u3k(eny)); - - { - u3_noun who = u3dc("scot", 'p', u3k(u3h(sed))); - c3_c* who_c = u3r_string(who); - - fprintf(stderr, "boot: found comet %s\r\n", who_c); - free(who_c); - u3z(who); - } - - u3z(tar); u3z(eny); - - return sed; -} - /* sist_key(): parse a private key-file. */ static u3_noun @@ -1669,11 +1250,11 @@ u3_sist_boot(void) sed = sist_key(des); } else { - sed = _sist_come(); + sed = u3_dawn_come(u3_nul); } u3A->fak = c3n; - pig = _sist_dawn(u3k(sed)); + pig = u3_dawn_vent(u3k(sed)); who = u3k(u3h(u3h(u3t(pig)))); u3z(sed); From 511ff89f808dc04a15367185047a984fb67a34db Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 5 Dec 2018 15:52:16 -0500 Subject: [PATCH 19/90] add entropy to arvo with %wack --- include/c/motes.h | 1 + vere/sist.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/c/motes.h b/include/c/motes.h index f05f716bab..d833c94ea8 100644 --- a/include/c/motes.h +++ b/include/c/motes.h @@ -1187,6 +1187,7 @@ # define c3__void c3_s4('v','o','i','d') # define c3__vorp c3_s4('v','o','r','p') # define c3__way c3_s3('w','a','y') +# define c3__wack c3_s4('w','a','c','k') # define c3__wail c3_s4('w','a','i','l') # define c3__wake c3_s4('w','a','k','e') # define c3__wamp c3_s4('w','a','m','p') diff --git a/vere/sist.c b/vere/sist.c index 620ead285f..8bafa3d8f5 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -1608,6 +1608,19 @@ sist_key(u3_noun des) void u3_sist_boot(void) { + // iterate entropy + // + { + c3_w eny_w[16]; + u3_noun eny; + + c3_rand(eny_w); + eny = u3i_words(16, eny_w); + + u3v_plan(u3nt(u3_blip, c3__arvo, u3_nul), u3nc(c3__wack, u3k(eny))); + u3z(eny); + } + if ( c3n == u3_Host.ops_u.nuu ) { _sist_rest(); From 591995934a8dd45735ee759142910bc966614224 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 5 Dec 2018 16:02:43 -0500 Subject: [PATCH 20/90] single-home arvo with %whom --- include/c/motes.h | 1 + vere/sist.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/c/motes.h b/include/c/motes.h index d833c94ea8..78bd52e380 100644 --- a/include/c/motes.h +++ b/include/c/motes.h @@ -1202,6 +1202,7 @@ # define c3__werp c3_s4('w','e','r','p') # define c3__west c3_s4('w','e','s','t') # define c3__what c3_s4('w','h','a','t') +# define c3__whom c3_s4('w','h','o','m') # define c3__wing c3_s4('w','i','n','g') # define c3__wild c3_s4('w','i','l','d') # define c3__win c3_s3('w','i','n') diff --git a/vere/sist.c b/vere/sist.c index 8bafa3d8f5..f78c395439 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -1694,6 +1694,10 @@ u3_sist_boot(void) u3A->own = who; + // set single-home + // + u3v_plan(u3nt(u3_blip, c3__arvo, u3_nul), u3nc(c3__whom, u3k(who))); + // initialize ames { u3_noun tuf = (c3y == u3A->fak) ? u3_nul : u3h(u3t(u3t(u3t(u3t(pig))))); From cfca39542f64c9dbdd45468a4ae96e602d6be989 Mon Sep 17 00:00:00 2001 From: joshuareagan Date: Wed, 5 Dec 2018 22:24:44 -0600 Subject: [PATCH 21/90] type variance bug fix --- jets/f/ut_find.c | 76 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 10 deletions(-) diff --git a/jets/f/ut_find.c b/jets/f/ut_find.c index 7de284836b..10a81529f9 100644 --- a/jets/f/ut_find.c +++ b/jets/f/ut_find.c @@ -13,18 +13,74 @@ u3_noun lon, u3_noun gil); +/* `u3qfu_felt_arm` is a helper function for + * u3qfu_felt. It handles the case in which the + * opal is for an arm, and hence which needs a + * list of `hold`s. These will be converted to + * a `fork` type. +*/ static u3_noun - u3qfu_felt(u3_noun van, - u3_noun sut, - u3_noun lap) + u3qfu_felt_arm(u3_noun lis) { - u3_noun von = u3i_molt(u3k(van), u3x_sam, u3k(sut), 0); - u3_noun gat = u3j_cook("u3qfu_felt-felt", von, "felt"); + if ( lis == u3_nul ) { + return u3_nul; + } else { + + u3_noun i_lis = u3h(lis); + u3_noun t_lis = u3t(lis); + u3_noun typ = u3h(i_lis); - return u3n_kick_on(u3i_molt(gat, - u3x_sam, - u3k(lap), - 0)); + u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ; + + if ( (c3n == u3du(typ)) || + (u3h(typ) != c3__core) ) { + return u3m_error("felt-core"); + } else if + ( (c3n == u3r_cell(u3t(typ), &p_typ, &q_typ)) || + (c3n == u3r_trel(q_typ, &pq_typ, &qq_typ, &rq_typ)) ) + { + return u3m_bail(c3__fail); + } else { + + u3_noun dox = u3nt(c3__core, u3k(qq_typ), u3k(q_typ)); + u3_noun par = u3nt(c3__hold, dox, u3nc(u3_nul, 1)); + u3_noun pro = u3nc(par, u3qfu_felt_arm(t_lis)); + + return pro; + } + } + } + +/* `u3qfu_felt` takes an opal, lap, and converts + * it to a type. The opal comes from the last + * limb of the wing processed by `+fond`. The + * type is used in +fond as the subject type of + * the next limb in the wing. +*/ + static u3_noun + u3qfu_felt(u3_noun lap) + { + u3_noun pro; + u3_noun lim = u3h(lap); + + if ( lim == c3y ) { + + u3_noun p_lap = u3t(lap); + pro = u3k(p_lap); + + } else if ( lim == c3n ) { + + u3_noun q_lap = u3t(u3t(lap)); + u3_noun lis = u3qdi_tap(q_lap); + u3_noun hos = u3qfu_felt_arm(lis); + + pro = u3kf_fork(hos); + u3z(lis); + + } else u3m_bail(c3__fail); + + u3z(lim); + return pro; } static u3_noun @@ -658,7 +714,7 @@ u3_noun qp_mor = u3t(p_mor); // opal { - u3_noun ref = u3qfu_felt(van, sut, qp_mor); + u3_noun ref = u3qfu_felt(qp_mor); u3_noun lon = u3k(pp_mor); u3_noun heg = (c3y == u3du(i_hyp)) ? u3k(i_hyp) From 4e244b92a843f0f6cd06230fc8b4996db8cb75f7 Mon Sep 17 00:00:00 2001 From: Joshua Reagan Date: Wed, 5 Dec 2018 22:32:22 -0600 Subject: [PATCH 22/90] Update pin-arvo-commit.txt --- .travis/pin-arvo-commit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/pin-arvo-commit.txt b/.travis/pin-arvo-commit.txt index dfd8a1c12e..1214a0f18a 100644 --- a/.travis/pin-arvo-commit.txt +++ b/.travis/pin-arvo-commit.txt @@ -1 +1 @@ -cae4b03c5c95722fb0e5f1947ba988f72703816d +37de11cb061409968e587e96e28cbbe9067da236 From ec84e0abc2302dabd674d9712ed43e72cdac2296 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 5 Dec 2018 23:32:45 -0500 Subject: [PATCH 23/90] [CI] updates pinned arvo commit --- .travis/pin-arvo-commit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/pin-arvo-commit.txt b/.travis/pin-arvo-commit.txt index dfd8a1c12e..9f80a20e23 100644 --- a/.travis/pin-arvo-commit.txt +++ b/.travis/pin-arvo-commit.txt @@ -1 +1 @@ -cae4b03c5c95722fb0e5f1947ba988f72703816d +1a4462123804e168d11e278f44af03cd2e0b8d7d From 56d26f486a53f82e4e69fd43bbe841c847e15c41 Mon Sep 17 00:00:00 2001 From: Joshua Reagan Date: Wed, 5 Dec 2018 22:51:01 -0600 Subject: [PATCH 24/90] Update pin-arvo-commit.txt --- .travis/pin-arvo-commit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/pin-arvo-commit.txt b/.travis/pin-arvo-commit.txt index 1214a0f18a..3c8e052bd9 100644 --- a/.travis/pin-arvo-commit.txt +++ b/.travis/pin-arvo-commit.txt @@ -1 +1 @@ -37de11cb061409968e587e96e28cbbe9067da236 +b8a4ab3f10c1039970901e56f5abe24301f38406 From 3c4e85fcee37b9765c3aaff4c98bb6933b007c7b Mon Sep 17 00:00:00 2001 From: joshuareagan Date: Wed, 5 Dec 2018 23:37:23 -0600 Subject: [PATCH 25/90] added shape checks --- jets/f/ut_find.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/jets/f/ut_find.c b/jets/f/ut_find.c index 10a81529f9..209d1503bb 100644 --- a/jets/f/ut_find.c +++ b/jets/f/ut_find.c @@ -24,10 +24,18 @@ { if ( lis == u3_nul ) { return u3_nul; - } else { + } + else if ( u3du(lis) != c3y ) { + return u3m_bail(c3__exit); + } + else + { u3_noun i_lis = u3h(lis); u3_noun t_lis = u3t(lis); + + if (u3du(i_lis) != c3y) u3m_bail(c3__exit); + u3_noun typ = u3h(i_lis); u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ; @@ -39,8 +47,9 @@ ( (c3n == u3r_cell(u3t(typ), &p_typ, &q_typ)) || (c3n == u3r_trel(q_typ, &pq_typ, &qq_typ, &rq_typ)) ) { - return u3m_bail(c3__fail); - } else { + return u3m_bail(c3__exit); + } else + { u3_noun dox = u3nt(c3__core, u3k(qq_typ), u3k(q_typ)); u3_noun par = u3nt(c3__hold, dox, u3nc(u3_nul, 1)); @@ -61,6 +70,9 @@ u3qfu_felt(u3_noun lap) { u3_noun pro; + + if (u3du(lap) != c3y) u3m_bail(c3__exit); + u3_noun lim = u3h(lap); if ( lim == c3y ) { @@ -70,16 +82,19 @@ } else if ( lim == c3n ) { - u3_noun q_lap = u3t(u3t(lap)); + u3_noun tal_lap = u3t(lap); + + if (u3du(tal_lap) != c3y) u3m_bail(c3__exit); + + u3_noun q_lap = u3t(tal_lap); u3_noun lis = u3qdi_tap(q_lap); u3_noun hos = u3qfu_felt_arm(lis); pro = u3kf_fork(hos); u3z(lis); - } else u3m_bail(c3__fail); + } else u3m_bail(c3__exit); - u3z(lim); return pro; } From def6538c08d4828fd2c6a8c7d8c503c86eec030c Mon Sep 17 00:00:00 2001 From: Joshua Reagan Date: Wed, 5 Dec 2018 23:48:09 -0600 Subject: [PATCH 26/90] braces constants --- jets/f/ut_find.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/jets/f/ut_find.c b/jets/f/ut_find.c index 209d1503bb..5f3c9a65a8 100644 --- a/jets/f/ut_find.c +++ b/jets/f/ut_find.c @@ -22,10 +22,10 @@ static u3_noun u3qfu_felt_arm(u3_noun lis) { - if ( lis == u3_nul ) { + if ( u3_nul == lis ) { return u3_nul; } - else if ( u3du(lis) != c3y ) { + else if ( c3y != u3du(lis) ) { return u3m_bail(c3__exit); } else @@ -34,21 +34,23 @@ u3_noun i_lis = u3h(lis); u3_noun t_lis = u3t(lis); - if (u3du(i_lis) != c3y) u3m_bail(c3__exit); + if (c3y != u3du(i_lis)) { u3m_bail(c3__exit); } u3_noun typ = u3h(i_lis); u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ; if ( (c3n == u3du(typ)) || - (u3h(typ) != c3__core) ) { + (c3__core != u3h(typ)) ) { return u3m_error("felt-core"); - } else if + } + else if ( (c3n == u3r_cell(u3t(typ), &p_typ, &q_typ)) || (c3n == u3r_trel(q_typ, &pq_typ, &qq_typ, &rq_typ)) ) { return u3m_bail(c3__exit); - } else + } + else { u3_noun dox = u3nt(c3__core, u3k(qq_typ), u3k(q_typ)); @@ -71,20 +73,21 @@ { u3_noun pro; - if (u3du(lap) != c3y) u3m_bail(c3__exit); + if (c3y != u3du(lap)) { u3m_bail(c3__exit); } u3_noun lim = u3h(lap); - if ( lim == c3y ) { + if ( c3y == lim ) { u3_noun p_lap = u3t(lap); pro = u3k(p_lap); - } else if ( lim == c3n ) { + } + else if ( c3n == lim ) { u3_noun tal_lap = u3t(lap); - if (u3du(tal_lap) != c3y) u3m_bail(c3__exit); + if (u3du(tal_lap) != c3y) { u3m_bail(c3__exit); } u3_noun q_lap = u3t(tal_lap); u3_noun lis = u3qdi_tap(q_lap); @@ -93,7 +96,8 @@ pro = u3kf_fork(hos); u3z(lis); - } else u3m_bail(c3__exit); + } + else { u3m_bail(c3__exit); } return pro; } From 2769cb2ac9f9e5976fe1d58b72d378a2ed99f2da Mon Sep 17 00:00:00 2001 From: joshuareagan Date: Thu, 6 Dec 2018 01:01:27 -0600 Subject: [PATCH 27/90] using u3x functions --- jets/f/ut_find.c | 104 +++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 62 deletions(-) diff --git a/jets/f/ut_find.c b/jets/f/ut_find.c index 5f3c9a65a8..f86b399d8f 100644 --- a/jets/f/ut_find.c +++ b/jets/f/ut_find.c @@ -22,44 +22,34 @@ static u3_noun u3qfu_felt_arm(u3_noun lis) { - if ( u3_nul == lis ) { - return u3_nul; + if ( u3_nul == lis ) { + return u3_nul; + } + else if ( c3y != u3du(lis) ) { + return u3m_bail(c3__exit); + } + else + { + u3_noun i_lis, t_lis, fot, typ; + u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ; + + u3x_cell(lis, &i_lis, &t_lis); + u3x_cell(i_lis, &typ, &fot); + + if ( (c3n == u3du(typ)) || + (c3__core != u3h(typ)) ) { + return u3m_error("felt-core"); } - else if ( c3y != u3du(lis) ) { - return u3m_bail(c3__exit); - } - else - { - - u3_noun i_lis = u3h(lis); - u3_noun t_lis = u3t(lis); - - if (c3y != u3du(i_lis)) { u3m_bail(c3__exit); } - - u3_noun typ = u3h(i_lis); - - u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ; - - if ( (c3n == u3du(typ)) || - (c3__core != u3h(typ)) ) { - return u3m_error("felt-core"); - } - else if - ( (c3n == u3r_cell(u3t(typ), &p_typ, &q_typ)) || - (c3n == u3r_trel(q_typ, &pq_typ, &qq_typ, &rq_typ)) ) - { - return u3m_bail(c3__exit); - } - else - { - - u3_noun dox = u3nt(c3__core, u3k(qq_typ), u3k(q_typ)); - u3_noun par = u3nt(c3__hold, dox, u3nc(u3_nul, 1)); - u3_noun pro = u3nc(par, u3qfu_felt_arm(t_lis)); - - return pro; - } + else { + u3x_cell(u3t(typ), &p_typ, &q_typ); + u3x_trel(q_typ, &pq_typ, &qq_typ, &rq_typ); + + u3_noun dox = u3nt(c3__core, u3k(qq_typ), u3k(q_typ)); + u3_noun par = u3nt(c3__hold, dox, u3nc(u3_nul, 1)); + u3_noun pro = u3nc(par, u3qfu_felt_arm(t_lis)); + return pro; } + } } /* `u3qfu_felt` takes an opal, lap, and converts @@ -71,35 +61,25 @@ static u3_noun u3qfu_felt(u3_noun lap) { - u3_noun pro; + u3_noun pro, lim, mil; + u3x_cell(lap, &lim, &mil); - if (c3y != u3du(lap)) { u3m_bail(c3__exit); } - - u3_noun lim = u3h(lap); - - if ( c3y == lim ) { - - u3_noun p_lap = u3t(lap); - pro = u3k(p_lap); + if ( c3y == lim ) { + pro = u3k(mil); + } + else if ( c3n == lim ) { + u3_noun p_lap, q_lap; + u3x_cell(mil, &p_lap, &q_lap); + u3_noun lis = u3qdi_tap(q_lap); + u3_noun hos = u3qfu_felt_arm(lis); + pro = u3kf_fork(hos); + u3z(lis); } - else if ( c3n == lim ) { - - u3_noun tal_lap = u3t(lap); - - if (u3du(tal_lap) != c3y) { u3m_bail(c3__exit); } - - u3_noun q_lap = u3t(tal_lap); - u3_noun lis = u3qdi_tap(q_lap); - u3_noun hos = u3qfu_felt_arm(lis); - - pro = u3kf_fork(hos); - u3z(lis); - - } - else { u3m_bail(c3__exit); } - - return pro; + else { + u3m_bail(c3__exit); + } + return pro; } static u3_noun From 85ed15775b6fc10993001929d20c0a3ecbb36acb Mon Sep 17 00:00:00 2001 From: Joshua Reagan Date: Thu, 6 Dec 2018 01:11:14 -0600 Subject: [PATCH 28/90] moving one brace --- jets/f/ut_find.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jets/f/ut_find.c b/jets/f/ut_find.c index f86b399d8f..916fbf9983 100644 --- a/jets/f/ut_find.c +++ b/jets/f/ut_find.c @@ -75,7 +75,7 @@ pro = u3kf_fork(hos); u3z(lis); - } + } else { u3m_bail(c3__exit); } From a9e760edb5e33cdfc0addd5781419968c11b3552 Mon Sep 17 00:00:00 2001 From: joshuareagan Date: Thu, 6 Dec 2018 02:00:35 -0600 Subject: [PATCH 29/90] removed superfluous lines --- jets/f/ut_find.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/jets/f/ut_find.c b/jets/f/ut_find.c index f86b399d8f..e5300d8617 100644 --- a/jets/f/ut_find.c +++ b/jets/f/ut_find.c @@ -25,11 +25,7 @@ if ( u3_nul == lis ) { return u3_nul; } - else if ( c3y != u3du(lis) ) { - return u3m_bail(c3__exit); - } - else - { + else { u3_noun i_lis, t_lis, fot, typ; u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ; @@ -38,7 +34,7 @@ if ( (c3n == u3du(typ)) || (c3__core != u3h(typ)) ) { - return u3m_error("felt-core"); + return u3m_error("felt-core"); } else { u3x_cell(u3t(typ), &p_typ, &q_typ); @@ -46,8 +42,7 @@ u3_noun dox = u3nt(c3__core, u3k(qq_typ), u3k(q_typ)); u3_noun par = u3nt(c3__hold, dox, u3nc(u3_nul, 1)); - u3_noun pro = u3nc(par, u3qfu_felt_arm(t_lis)); - return pro; + return u3nc(par, u3qfu_felt_arm(t_lis)); } } } @@ -75,7 +70,7 @@ pro = u3kf_fork(hos); u3z(lis); - } + } else { u3m_bail(c3__exit); } From ee483875bc37f5c9167d2c1e02dd030d23bca466 Mon Sep 17 00:00:00 2001 From: joshuareagan Date: Thu, 6 Dec 2018 02:15:18 -0600 Subject: [PATCH 30/90] removed more superfluous lines --- jets/f/ut_find.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jets/f/ut_find.c b/jets/f/ut_find.c index e5300d8617..a5312ef8c7 100644 --- a/jets/f/ut_find.c +++ b/jets/f/ut_find.c @@ -56,11 +56,11 @@ static u3_noun u3qfu_felt(u3_noun lap) { - u3_noun pro, lim, mil; + u3_noun lim, mil; u3x_cell(lap, &lim, &mil); if ( c3y == lim ) { - pro = u3k(mil); + return u3k(mil); } else if ( c3n == lim ) { u3_noun p_lap, q_lap; @@ -68,13 +68,12 @@ u3_noun lis = u3qdi_tap(q_lap); u3_noun hos = u3qfu_felt_arm(lis); - pro = u3kf_fork(hos); u3z(lis); + return u3kf_fork(hos); } else { u3m_bail(c3__exit); } - return pro; } static u3_noun From a36b2a010e68d58f4f7d56dff9eab1c5ad48c276 Mon Sep 17 00:00:00 2001 From: joshuareagan Date: Thu, 6 Dec 2018 13:38:33 -0600 Subject: [PATCH 31/90] remove hold --- jets/f/ut_find.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/jets/f/ut_find.c b/jets/f/ut_find.c index a5312ef8c7..bde859ee90 100644 --- a/jets/f/ut_find.c +++ b/jets/f/ut_find.c @@ -15,9 +15,9 @@ /* `u3qfu_felt_arm` is a helper function for * u3qfu_felt. It handles the case in which the - * opal is for an arm, and hence which needs a - * list of `hold`s. These will be converted to - * a `fork` type. + * opal is for an arm, by creating a list of + * parent core types. These will be converted to + * a single `fork` type. */ static u3_noun u3qfu_felt_arm(u3_noun lis) @@ -27,8 +27,6 @@ } else { u3_noun i_lis, t_lis, fot, typ; - u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ; - u3x_cell(lis, &i_lis, &t_lis); u3x_cell(i_lis, &typ, &fot); @@ -37,12 +35,12 @@ return u3m_error("felt-core"); } else { + u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ; u3x_cell(u3t(typ), &p_typ, &q_typ); u3x_trel(q_typ, &pq_typ, &qq_typ, &rq_typ); u3_noun dox = u3nt(c3__core, u3k(qq_typ), u3k(q_typ)); - u3_noun par = u3nt(c3__hold, dox, u3nc(u3_nul, 1)); - return u3nc(par, u3qfu_felt_arm(t_lis)); + return u3nc(dox, u3qfu_felt_arm(t_lis)); } } } @@ -63,10 +61,10 @@ return u3k(mil); } else if ( c3n == lim ) { - u3_noun p_lap, q_lap; + u3_noun p_lap, q_lap, lis, hos; u3x_cell(mil, &p_lap, &q_lap); - u3_noun lis = u3qdi_tap(q_lap); - u3_noun hos = u3qfu_felt_arm(lis); + lis = u3qdi_tap(q_lap); + hos = u3qfu_felt_arm(lis); u3z(lis); return u3kf_fork(hos); From 3fc14073e0ea99f2f3931ac4201357b53eb29b5e Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Wed, 5 Dec 2018 16:36:03 -0800 Subject: [PATCH 32/90] Write a jet for +sort Closes #387 --- jets/b/sort.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++--- jets/tree.c | 9 +++---- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/jets/b/sort.c b/jets/b/sort.c index df08279e8d..51d02c05a1 100644 --- a/jets/b/sort.c +++ b/jets/b/sort.c @@ -6,13 +6,73 @@ /* functions */ + // like skid, except its callback is $-([* *] ?) and it takes the second + // argument so that it calls its callback with [i.list, second] + // + // all args are RETAINED + static u3_noun + _split_in(u3j_site* sit_u, + u3_noun a, + u3_noun second) + { + if ( 0 == a ) { + return u3nc(u3_nul, u3_nul); + } + else if ( c3n == u3du(a) ) { + return u3m_bail(c3__exit); + } else { + u3_noun acc = _split_in(sit_u, u3t(a), second); + u3_noun hoz = u3j_gate_slam(sit_u, u3nc(u3k(u3h(a)), u3k(second))); + u3_noun nex; + + if ( c3y == hoz ) { + nex = u3nc(u3nc(u3k(u3h(a)), u3k(u3h(acc))), u3k(u3t(acc))); + } + else { + nex = u3nc(u3k(u3h(acc)), u3nc(u3k(u3h(a)), u3k(u3t(acc)))); + } + u3z(hoz); + u3z(acc); + + return nex; + } + } + + static u3_noun + _sort_in(u3j_site* sit_u, u3_noun list) + { + if ( 0 == list ) { + return u3_nul; + } + else if ( c3n == u3du(list) ) { + return u3m_bail(c3__exit); + } else { + u3_noun hed, tal; + u3x_cell(list, &hed, &tal); + + u3_noun split = _split_in(sit_u, tal, hed); + u3_noun lhs = _sort_in(sit_u, u3h(split)); + u3_noun rhs = u3nc(u3k(hed), _sort_in(sit_u, u3t(split))); + + u3_noun ret = u3qb_weld(lhs, rhs); + u3z(lhs); + u3z(rhs); + u3z(split); + + return ret; + } + } + u3_noun u3qb_sort(u3_noun a, u3_noun b) { - // must think about - // - return u3m_bail(c3__fail); + u3_noun pro; + u3j_site sit_u; + u3j_gate_prep(&sit_u, u3k(b)); + pro = _sort_in(&sit_u, a); + u3j_gate_lose(&sit_u); + return pro; } u3_noun u3wb_sort(u3_noun cor) diff --git a/jets/tree.c b/jets/tree.c index a96baadedc..254a7b4654 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -797,11 +797,8 @@ static u3j_harm _141_two_slag_a[] = {{".2", u3wb_slag, c3y}, {}}; static c3_c* _141_two_slag_ha[] = {0}; static u3j_harm _141_two_snag_a[] = {{".2", u3wb_snag, c3y}, {}}; static c3_c* _141_two_snag_ha[] = {0}; - -// https://github.com/urbit/urbit/issues/387 -// static u3j_harm _141_two_sort_a[] = {{".2", u3wb_sort, c3y}, {}}; -// static c3_c* _141_two_sort_ha[] = {0}; - +static u3j_harm _141_two_sort_a[] = {{".2", u3wb_sort, c3y}, {}}; +static c3_c* _141_two_sort_ha[] = {0}; static u3j_harm _141_two_turn_a[] = {{".2", u3wb_turn, c3y}, {}}; static c3_c* _141_two_turn_ha[] = {0}; static u3j_harm _141_two_weld_a[] = {{".2", u3wb_weld, c3y}, {}}; @@ -972,7 +969,7 @@ static u3j_core _141_two_d[] = { "scag", 7, _141_two_scag_a, 0, _141_two_scag_ha }, { "slag", 7, _141_two_slag_a, 0, _141_two_slag_ha }, { "snag", 7, _141_two_snag_a, 0, _141_two_snag_ha }, - // { "sort", 7, _141_two_sort_a, 0, _141_two_sort_ha }, + { "sort", 7, _141_two_sort_a, 0, _141_two_sort_ha }, { "turn", 7, _141_two_turn_a, 0, _141_two_turn_ha }, { "weld", 7, _141_two_weld_a, 0, _141_two_weld_ha }, From 33b52c77c2549aff3576385d133e0466b3751c2c Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 6 Dec 2018 19:08:08 -0500 Subject: [PATCH 33/90] [CI] updates pinned arvo commit --- .travis/pin-arvo-commit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/pin-arvo-commit.txt b/.travis/pin-arvo-commit.txt index 9f80a20e23..9d21e4199e 100644 --- a/.travis/pin-arvo-commit.txt +++ b/.travis/pin-arvo-commit.txt @@ -1 +1 @@ -1a4462123804e168d11e278f44af03cd2e0b8d7d +6a1f32bb1984fa9329c072de09ba67b212c8dbed From 6a4fc7c9aed8384936a7cb0289fcf78ea4d6a864 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 7 Dec 2018 00:27:50 -0500 Subject: [PATCH 34/90] updates calls to the |take:dawn gates to handle units and bail on ~ --- vere/dawn.c | 84 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/vere/dawn.c b/vere/dawn.c index 45252861b9..858a45f67f 100644 --- a/vere/dawn.c +++ b/vere/dawn.c @@ -276,9 +276,19 @@ u3_dawn_vent(u3_noun seed) u3_noun oct = u3v_wish("bloq:give:dawn"); u3_noun kob = _dawn_eth_rpc(url_c, u3k(oct)); - bok = u3do("bloq:take:dawn", u3k(kob)); + u3_noun nit = u3do("bloq:take:dawn", u3k(kob)); - u3z(oct); u3z(kob); + if ( u3_nul == nit ) { + fprintf(stderr, "boot: block retrieval failed\r\n"); + // bails, won't return + u3_lo_bail(); + return u3_none; + } + else { + bok = u3k(u3t(nit)); + } + + u3z(oct); u3z(kob); u3z(nit); } { @@ -295,30 +305,46 @@ u3_dawn_vent(u3_noun seed) hul = u3v_wish("*hull:constitution:ethe"); } else { - u3_noun oct; + u3_noun who; if ( c3__earl == rank ) { - u3_noun seg = u3do("^sein:title", u3k(ship)); - u3_noun ges = u3dc("scot", 'p', u3k(seg)); - c3_c* seg_c = u3r_string(ges); + who = u3do("^sein:title", u3k(ship)); - fprintf(stderr, "boot: retrieving %s's public keys (for %s)\r\n", - seg_c, u3_Host.ops_u.who_c); - oct = u3dc("hull:give:dawn", u3k(bok), u3k(seg)); + { + u3_noun seg = u3dc("scot", 'p', u3k(who)); + c3_c* seg_c = u3r_string(seg); - free(seg_c); - u3z(seg); u3z(ges); + fprintf(stderr, "boot: retrieving %s's public keys (for %s)\r\n", + seg_c, u3_Host.ops_u.who_c); + + free(seg_c); + u3z(seg); + } } else { + who = u3k(ship); fprintf(stderr, "boot: retrieving %s's public keys\r\n", u3_Host.ops_u.who_c); - oct = u3dc("hull:give:dawn", u3k(bok), u3k(ship)); } - u3_noun luh = _dawn_eth_rpc(url_c, u3k(oct)); - hul = u3dc("hull:take:dawn", u3k(ship), u3k(luh)); + { + u3_noun oct = u3dc("hull:give:dawn", u3k(bok), u3k(who)); + u3_noun luh = _dawn_eth_rpc(url_c, u3k(oct)); + u3_noun nit = u3dc("hull:take:dawn", u3k(ship), u3k(luh)); - u3z(oct); u3z(luh); + if ( u3_nul == nit ) { + fprintf(stderr, "boot: public key retrieval failed\r\n"); + // bails, won't return + u3_lo_bail(); + return u3_none; + } + else { + hul = u3k(u3t(nit)); + } + + u3z(oct); u3z(luh); u3z(nit); + } + u3z(who); } // +live:dawn: network state @@ -358,9 +384,19 @@ u3_dawn_vent(u3_noun seed) u3_noun oct = u3do("czar:give:dawn", u3k(bok)); u3_noun raz = _dawn_eth_rpc(url_c, u3k(oct)); - zar = u3do("czar:take:dawn", u3k(raz)); + u3_noun nit = u3do("czar:take:dawn", u3k(raz)); - u3z(oct); u3z(raz); + if ( u3_nul == nit ) { + fprintf(stderr, "boot: galaxy table retrieval failed\r\n"); + // bails, won't return + u3_lo_bail(); + return u3_none; + } + else { + zar = u3k(u3t(nit)); + } + + u3z(oct); u3z(raz); u3z(nit); } // (list turf): ames domains @@ -376,9 +412,19 @@ u3_dawn_vent(u3_noun seed) u3_noun oct = u3do("turf:give:dawn", u3k(bok)); u3_noun fut = _dawn_eth_rpc(url_c, u3k(oct)); - tuf = u3do("turf:take:dawn", u3k(fut)); + u3_noun nit = u3do("turf:take:dawn", u3k(fut)); - u3z(oct); u3z(fut); + if ( u3_nul == nit ) { + fprintf(stderr, "boot: network domains retrieval failed\r\n"); + // bails, won't return + u3_lo_bail(); + return u3_none; + } + else { + tuf = u3k(u3t(nit)); + } + + u3z(oct); u3z(fut); u3z(nit); } u3z(rank); From 611d72d9579a3d2d3050b15753bb60f8c104a994 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 7 Dec 2018 01:51:10 -0500 Subject: [PATCH 35/90] refactors |take:dawn unit promotion --- vere/dawn.c | 80 +++++++++++++++++++++-------------------------------- 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/vere/dawn.c b/vere/dawn.c index 858a45f67f..697ec2b0dc 100644 --- a/vere/dawn.c +++ b/vere/dawn.c @@ -164,6 +164,24 @@ _dawn_fail(u3_noun who, u3_noun rac, u3_noun sas) u3_lo_bail(); } +/* _dawn_need_unit(): produce a value or pail +*/ +static u3_noun +_dawn_need_unit(u3_noun nit, c3_c* msg_c) +{ + if ( u3_nul == nit ) { + fprintf(stderr, "%s\r\n", msg_c); + // bails, won't return + u3_lo_bail(); + return u3_none; + } + else { + u3_noun pro = u3k(u3t(nit)); + u3z(nit); + return pro; + } +} + /* _dawn_purl(): ethereum gateway url as (unit purl) */ static u3_noun @@ -276,19 +294,10 @@ u3_dawn_vent(u3_noun seed) u3_noun oct = u3v_wish("bloq:give:dawn"); u3_noun kob = _dawn_eth_rpc(url_c, u3k(oct)); - u3_noun nit = u3do("bloq:take:dawn", u3k(kob)); - if ( u3_nul == nit ) { - fprintf(stderr, "boot: block retrieval failed\r\n"); - // bails, won't return - u3_lo_bail(); - return u3_none; - } - else { - bok = u3k(u3t(nit)); - } - - u3z(oct); u3z(kob); u3z(nit); + bok = _dawn_need_unit(u3do("bloq:take:dawn", u3k(kob)), + "boot: block retrieval failed"); + u3z(oct); u3z(kob); } { @@ -316,7 +325,6 @@ u3_dawn_vent(u3_noun seed) fprintf(stderr, "boot: retrieving %s's public keys (for %s)\r\n", seg_c, u3_Host.ops_u.who_c); - free(seg_c); u3z(seg); } @@ -330,20 +338,12 @@ u3_dawn_vent(u3_noun seed) { u3_noun oct = u3dc("hull:give:dawn", u3k(bok), u3k(who)); u3_noun luh = _dawn_eth_rpc(url_c, u3k(oct)); - u3_noun nit = u3dc("hull:take:dawn", u3k(ship), u3k(luh)); - if ( u3_nul == nit ) { - fprintf(stderr, "boot: public key retrieval failed\r\n"); - // bails, won't return - u3_lo_bail(); - return u3_none; - } - else { - hul = u3k(u3t(nit)); - } - - u3z(oct); u3z(luh); u3z(nit); + hul = _dawn_need_unit(u3dc("hull:take:dawn", u3k(ship), u3k(luh)), + "boot: failed to retrieve public keys"); + u3z(oct); u3z(luh); } + u3z(who); } @@ -384,19 +384,10 @@ u3_dawn_vent(u3_noun seed) u3_noun oct = u3do("czar:give:dawn", u3k(bok)); u3_noun raz = _dawn_eth_rpc(url_c, u3k(oct)); - u3_noun nit = u3do("czar:take:dawn", u3k(raz)); - if ( u3_nul == nit ) { - fprintf(stderr, "boot: galaxy table retrieval failed\r\n"); - // bails, won't return - u3_lo_bail(); - return u3_none; - } - else { - zar = u3k(u3t(nit)); - } - - u3z(oct); u3z(raz); u3z(nit); + zar = _dawn_need_unit(u3do("czar:take:dawn", u3k(raz)), + "boot: failed to retrieve galaxy table"); + u3z(oct); u3z(raz); } // (list turf): ames domains @@ -412,19 +403,10 @@ u3_dawn_vent(u3_noun seed) u3_noun oct = u3do("turf:give:dawn", u3k(bok)); u3_noun fut = _dawn_eth_rpc(url_c, u3k(oct)); - u3_noun nit = u3do("turf:take:dawn", u3k(fut)); - if ( u3_nul == nit ) { - fprintf(stderr, "boot: network domains retrieval failed\r\n"); - // bails, won't return - u3_lo_bail(); - return u3_none; - } - else { - tuf = u3k(u3t(nit)); - } - - u3z(oct); u3z(fut); u3z(nit); + tuf = _dawn_need_unit(u3do("turf:take:dawn", u3k(fut)), + "boot: failed to retrieve network domains"); + u3z(oct); u3z(fut); } u3z(rank); From 55f792e8ab9d728379d7542cacd0feadd03cf69a Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 7 Dec 2018 02:08:02 -0500 Subject: [PATCH 36/90] updates calls to the |snap:dawn gates to handle units --- vere/dawn.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/vere/dawn.c b/vere/dawn.c index 697ec2b0dc..f4a2c31c6f 100644 --- a/vere/dawn.c +++ b/vere/dawn.c @@ -287,7 +287,10 @@ u3_dawn_vent(u3_noun seed) // if ( c3y == u3_Host.ops_u.etn ) { fprintf(stderr, "boot: extracting block from snapshot\r\n"); - bok = u3do("bloq:snap:dawn", u3k(u3t(sap))); + + bok = _dawn_need_unit(u3do("bloq:snap:dawn", u3k(u3t(sap))), + "boot: failed to extract " + "block from snapshot"); } else { fprintf(stderr, "boot: retrieving latest block\r\n"); @@ -306,7 +309,11 @@ u3_dawn_vent(u3_noun seed) u3_noun hul; if ( c3y == u3_Host.ops_u.etn ) { - hul = u3dc("hull:snap:dawn", u3k(ship), u3k(u3t(sap))); + fprintf(stderr, "boot: extracting public keys from snapshot\r\n"); + + hul = _dawn_need_unit(u3dc("hull:snap:dawn", u3k(ship), u3k(u3t(sap))), + "boot: failed to extract " + "public keys from snapshot"); } else if ( c3__pawn == rank ) { // irrelevant, just bunt +hull @@ -377,7 +384,11 @@ u3_dawn_vent(u3_noun seed) // (map ship [=life =pass]): galaxy table // if ( c3y == u3_Host.ops_u.etn ) { - zar = u3do("czar:snap:dawn", u3k(u3t(sap))); + fprintf(stderr, "boot: extracting galaxy table from snapshot\r\n"); + + zar = _dawn_need_unit(u3do("czar:snap:dawn", u3k(u3t(sap))), + "boot: failed to extract " + "galaxy table from snapshot"); } else { fprintf(stderr, "boot: retrieving galaxy table\r\n"); @@ -396,7 +407,11 @@ u3_dawn_vent(u3_noun seed) tuf = _dawn_turf(u3_Host.ops_u.dns_c); } else if ( c3y == u3_Host.ops_u.etn ) { - tuf = u3do("turf:snap:dawn", u3k(u3t(sap))); + fprintf(stderr, "boot: extracting network domains from snapshot\r\n"); + + tuf = _dawn_need_unit(u3do("turf:snap:dawn", u3k(u3t(sap))), + "boot: failed to extract " + "network domains from snapshot"); } else { fprintf(stderr, "boot: retrieving network domains\r\n"); From eabeb4a200efd74a023197e6e6e15636dd0dda47 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 7 Dec 2018 14:15:35 -0500 Subject: [PATCH 37/90] corrects typo in comment --- vere/dawn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vere/dawn.c b/vere/dawn.c index f4a2c31c6f..e186763725 100644 --- a/vere/dawn.c +++ b/vere/dawn.c @@ -164,7 +164,7 @@ _dawn_fail(u3_noun who, u3_noun rac, u3_noun sas) u3_lo_bail(); } -/* _dawn_need_unit(): produce a value or pail +/* _dawn_need_unit(): produce a value or print error and exit */ static u3_noun _dawn_need_unit(u3_noun nit, c3_c* msg_c) From d6f02165a0cc4d75507ec5d87dfecb3b439c1fd6 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 8 Dec 2018 16:26:25 -0500 Subject: [PATCH 38/90] fixes use-after-free in _http_serv_start() --- vere/http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vere/http.c b/vere/http.c index 4b56f0a8e3..01ffc9b50c 100644 --- a/vere/http.c +++ b/vere/http.c @@ -1017,11 +1017,11 @@ _http_serv_start(u3_http* htp_u) } uL(fprintf(uH, "http: listen: %s\n", uv_strerror(sas_i))); - _http_serv_free(htp_u); if ( 0 != htp_u->rox_u ) { _proxy_serv_free(htp_u->rox_u); } + _http_serv_free(htp_u); return; } From 295affdaad5c149bffb5ce311456474daf27589a Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 8 Dec 2018 16:28:29 -0500 Subject: [PATCH 39/90] fixes memory leak in _sist_cask() --- vere/sist.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vere/sist.c b/vere/sist.c index 275eedb2c4..aed41cd08b 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -322,6 +322,8 @@ _sist_cask(c3_c* dir_c, u3_noun nun) strncat(say_c, paw_c, strlen(paw_c) - 1); say = u3do("slay", u3i_string(say_c)); + free(say_c); + if ( (u3_nul == say) || (u3_blip != u3h(u3t(say))) || ('p' != u3h(u3t(u3t(say)))) ) From 21224cc35933a7aefe7ca2e27a6949210bb985f2 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 8 Dec 2018 16:30:05 -0500 Subject: [PATCH 40/90] fixes memory leak in _cj_je_fsck() --- noun/jets.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/noun/jets.c b/noun/jets.c index 3fb353f707..67b15dccbf 100644 --- a/noun/jets.c +++ b/noun/jets.c @@ -469,7 +469,12 @@ _cj_je_fsck(u3_noun clu) } } u3z(clu); - return u3nt(u3i_string(nam_c), axe_l, huk); + + { + u3_noun pro = u3nt(u3i_string(nam_c), axe_l, huk); + free(nam_c); + return pro; + } } /* _cj_find_cold(): search cold state for `bat`s [bash registry]. From 0d5beaf774cbe21d8f32241a1d568a32cd319429 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 8 Dec 2018 16:32:37 -0500 Subject: [PATCH 41/90] fixes duplicate assignment in u3v_nick() --- noun/vortex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noun/vortex.c b/noun/vortex.c index 7f1b90c821..a23f95f30b 100644 --- a/noun/vortex.c +++ b/noun/vortex.c @@ -152,7 +152,7 @@ u3v_nick(u3_noun vir, u3_noun cor) u3_noun pi_vir, qi_vir; u3_noun vix; - if ( (c3y == u3r_cell((i_vir=u3h(vir)), &pi_vir, &qi_vir)) && + if ( (c3y == u3r_cell(i_vir, &pi_vir, &qi_vir)) && (c3y == u3du(qi_vir)) && (c3__hear == u3h(qi_vir)) ) { From b60668f1d8bfe6153f12cf0e05c4e7cb0a00e9e8 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 8 Dec 2018 16:35:40 -0500 Subject: [PATCH 42/90] fixes 0-byte allocation in _cttp_bods_to_vec() --- vere/cttp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vere/cttp.c b/vere/cttp.c index b371016883..98b463fa4a 100644 --- a/vere/cttp.c +++ b/vere/cttp.c @@ -152,6 +152,11 @@ _cttp_bods_to_vec(u3_hbod* bod_u, c3_w* tot_w) } } + if ( 0 == len_w ) { + *tot_w = len_w; + return 0; + } + vec_u = c3_malloc(sizeof(h2o_iovec_t) * len_w); len_w = 0; From a3bef0f23a8e98ff8e3de6351925ea438f75c2fb Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 8 Dec 2018 16:36:51 -0500 Subject: [PATCH 43/90] prevents 0-byte allocations in u3i_molt() and u3r_mean() --- noun/imprison.c | 2 ++ noun/retrieve.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/noun/imprison.c b/noun/imprison.c index daf59a1d37..13ba89cc53 100644 --- a/noun/imprison.c +++ b/noun/imprison.c @@ -527,6 +527,8 @@ u3i_molt(u3_noun som, ...) } va_end(ap); } + + c3_assert( 0 != len_w ); pms_m = alloca(len_w * sizeof(struct _molt_pair)); /* Install. diff --git a/noun/retrieve.c b/noun/retrieve.c index 1b796f59c7..63287154b7 100644 --- a/noun/retrieve.c +++ b/noun/retrieve.c @@ -185,6 +185,8 @@ u3r_mean(u3_noun som, } va_end(ap); } + + c3_assert( 0 != len_w ); prs_m = alloca(len_w * sizeof(struct _mean_pair)); /* Install. From 76fbb1d9181370b1310c63ebc895c69af291c1fe Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 8 Dec 2018 16:54:49 -0500 Subject: [PATCH 44/90] adds and uses c3_realloc() --- include/c/defs.h | 9 +++++++++ vere/dawn.c | 7 +------ vere/http.c | 4 +--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/c/defs.h b/include/c/defs.h index 5332d42a1b..c0eb6e5701 100644 --- a/include/c/defs.h +++ b/include/c/defs.h @@ -97,3 +97,12 @@ void* rut = c3_malloc(s); \ memset(rut, 0, s); \ rut;}) + +/* c3_realloc(): asserting realloc + */ +#define c3_realloc(a, b) ({ \ + void* rut = realloc(a, b); \ + if ( 0 == rut ) { \ + c3_assert(!"memory lost"); \ + } \ + rut;}) diff --git a/vere/dawn.c b/vere/dawn.c index e186763725..2611b28d4a 100644 --- a/vere/dawn.c +++ b/vere/dawn.c @@ -14,12 +14,7 @@ static size_t _dawn_curl_alloc(void* dat_v, size_t uni_t, size_t mem_t, uv_buf_t* buf_u) { size_t siz_t = uni_t * mem_t; - buf_u->base = realloc(buf_u->base, 1 + siz_t + buf_u->len); - - if ( 0 == buf_u->base ) { - fprintf(stderr, "out of memory\n"); - u3_lo_bail(); - } + buf_u->base = c3_realloc(buf_u->base, 1 + siz_t + buf_u->len); memcpy(buf_u->base + buf_u->len, dat_v, siz_t); buf_u->len += siz_t; diff --git a/vere/http.c b/vere/http.c index 01ffc9b50c..e0ee698ca2 100644 --- a/vere/http.c +++ b/vere/http.c @@ -2687,9 +2687,7 @@ _proxy_peek_read_cb(uv_stream_t* don_u, } else { c3_w len_w = siz_w + con_u->buf_u.len; - // XX c3_realloc - void* ptr_v = realloc(con_u->buf_u.base, len_w); - c3_assert( 0 != ptr_v ); + void* ptr_v = c3_realloc(con_u->buf_u.base, len_w); memcpy(ptr_v + con_u->buf_u.len, buf_u->base, siz_w); con_u->buf_u = uv_buf_init(ptr_v, len_w); From bdc7179a28adc6a1b44b396c9f8690ea5a6f3c8f Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 8 Dec 2018 19:48:08 -0500 Subject: [PATCH 45/90] prevents ub in u3x_cap and u3x_mas --- include/noun/xtract.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/noun/xtract.h b/include/noun/xtract.h index 7db51a0d0d..d7a355ffb1 100644 --- a/include/noun/xtract.h +++ b/include/noun/xtract.h @@ -38,12 +38,15 @@ /* u3x_cap(): root axis, 2 or 3. */ -# define u3x_cap(a_w) (0x2 | (a_w >> (u3x_dep(a_w) - 1))) +# define u3x_cap(a_w) ({ \ + c3_assert( 1 < a_w ); \ + (0x2 | (a_w >> (u3x_dep(a_w) - 1))); }) /* u3x_mas(): remainder after cap. */ -# define u3x_mas(a_w) \ - ( (a_w & ~(1 << u3x_dep(a_w))) | (1 << (u3x_dep(a_w) - 1)) ) +# define u3x_mas(a_w) ({ \ + c3_assert( 1 < a_w ); \ + ( (a_w & ~(1 << u3x_dep(a_w))) | (1 << (u3x_dep(a_w) - 1)) ); }) /* u3x_peg(): connect two axes. */ From 435596b485b07f1a43e004658a176015f8ed9c19 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 8 Dec 2018 20:07:41 -0500 Subject: [PATCH 46/90] fixes memory leak in _unix_update_dir() --- vere/unix.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vere/unix.c b/vere/unix.c index 22ccf7fa26..5903d22000 100644 --- a/vere/unix.c +++ b/vere/unix.c @@ -915,6 +915,8 @@ _unix_update_dir(u3_udir* dir_u) } } } + + free(pax_c); } } From 413b53ea16012b2bc3a857cbd8ec4f42e5d48052 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 8 Dec 2018 20:08:23 -0500 Subject: [PATCH 47/90] prevents 0-byte allocation in u3qe_lore() --- jets/e/lore.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jets/e/lore.c b/jets/e/lore.c index 13fa3c1d3d..9d62644d04 100644 --- a/jets/e/lore.c +++ b/jets/e/lore.c @@ -35,8 +35,12 @@ } { - c3_y* byts_y = alloca(meg_w); - u3r_bytes(pos_w, meg_w, byts_y, lub); + c3_y* byts_y = 0; + + if ( 0 != meg_w ) { + byts_y = alloca(meg_w); + u3r_bytes(pos_w, meg_w, byts_y, lub); + } if ( _(end_y) ) { return u3kb_flop(u3nc(u3i_bytes(meg_w, byts_y), tez)); From 606650ab3fdf207a955f5782a53b6ec3389e1058 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 12:00:22 -0500 Subject: [PATCH 48/90] disables unused _term_close_cb() --- vere/term.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vere/term.c b/vere/term.c index e57143d10c..3e2acef453 100644 --- a/vere/term.c +++ b/vere/term.c @@ -52,6 +52,10 @@ _term_alloc(uv_handle_t* had_u, } +// XX unused, but %hook is in %zuse. +// implement or remove +// +#if 0 /* _term_close_cb(): free terminal. */ static void @@ -79,6 +83,7 @@ _term_close_cb(uv_handle_t* han_t) } free(tty_u); } +#endif /* u3_term_io_init(): initialize terminal. */ From 675fd016077be4375c7976c079d5a64195457ded Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 12:00:45 -0500 Subject: [PATCH 49/90] disables unused _sist_text() --- vere/sist.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vere/sist.c b/vere/sist.c index aed41cd08b..75acb393aa 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -345,6 +345,9 @@ _sist_cask(c3_c* dir_c, u3_noun nun) return key; } +// XX unused, but may be needed for brainwallet +// +#if 0 /* _sist_text(): ask for a name string. */ static u3_noun @@ -378,7 +381,6 @@ _sist_text(c3_c* pom_c) return say; } -#if 0 /* _sist_bask(): ask a yes or no question. */ static u3_noun From 2bb7b6edd31a074c269f57253236363b4d573b60 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 12:01:03 -0500 Subject: [PATCH 50/90] removes unused variable in _reck_kick_spec() --- vere/reck.c | 1 - 1 file changed, 1 deletion(-) diff --git a/vere/reck.c b/vere/reck.c index 5d977466ab..6766b5355f 100644 --- a/vere/reck.c +++ b/vere/reck.c @@ -259,7 +259,6 @@ static u3_noun _reck_kick_spec(u3_noun pox, u3_noun fav) { u3_noun i_pox, t_pox; - u3_noun p_fav; if ( (c3n == u3r_cell(pox, &i_pox, &t_pox)) || ((i_pox != u3_blip) && From b60e10f1494bfe8242436f5049df0f45701fe167 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 12:02:16 -0500 Subject: [PATCH 51/90] corrects profiling struct initializations --- noun/trace.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/noun/trace.c b/noun/trace.c index fc09be9d96..af3b1a23d8 100644 --- a/noun/trace.c +++ b/noun/trace.c @@ -580,7 +580,7 @@ u3t_boot(void) #if defined(U3_OS_osx) || defined(U3_OS_linux) // Register _ct_sigaction to be called on `SIGPROF`. { - struct sigaction sig_s = {0}; + struct sigaction sig_s = {{0}}; sig_s.sa_handler = _ct_sigaction; sigemptyset(&(sig_s.sa_mask)); sigaction(SIGPROF, &sig_s, 0); @@ -598,7 +598,7 @@ u3t_boot(void) // Ask for SIGPROF to be sent every 10ms. { - struct itimerval itm_v = {0}; + struct itimerval itm_v = {{0}}; itm_v.it_interval.tv_usec = 10000; itm_v.it_value = itm_v.it_interval; setitimer(ITIMER_PROF, &itm_v, 0); @@ -631,13 +631,13 @@ u3t_boff(void) // Disable the SIGPROF timer. { - struct itimerval itm_v = {0}; + struct itimerval itm_v = {{0}}; setitimer(ITIMER_PROF, &itm_v, 0); } // Ignore SIGPROF signals. { - struct sigaction sig_s = {0}; + struct sigaction sig_s = {{0}}; sigemptyset(&(sig_s.sa_mask)); sig_s.sa_handler = SIG_IGN; sigaction(SIGPROF, &sig_s, 0); From 3ae323e43e4be43ff1bd4c8852b49dae6f4f32d2 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 13:39:32 -0500 Subject: [PATCH 52/90] updates subprojects to not install static libs and headers --- subprojects/argon2 | 2 +- subprojects/ed25519 | 2 +- subprojects/libh2o | 2 +- subprojects/libscrypt | 2 +- subprojects/libsni | 2 +- subprojects/libuv | 2 +- subprojects/murmur3 | 2 +- subprojects/secp256k1 | 2 +- subprojects/softfloat3 | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/subprojects/argon2 b/subprojects/argon2 index 6e7d7e3a92..4da94a611e 160000 --- a/subprojects/argon2 +++ b/subprojects/argon2 @@ -1 +1 @@ -Subproject commit 6e7d7e3a92361f11942f0c743d154ab426d1530e +Subproject commit 4da94a611ee62bad87ab2b131ffda3bcc0723d9c diff --git a/subprojects/ed25519 b/subprojects/ed25519 index ba4777acac..76385f2ebb 160000 --- a/subprojects/ed25519 +++ b/subprojects/ed25519 @@ -1 +1 @@ -Subproject commit ba4777acac5694925ab78f38577b059cd4a3e8e6 +Subproject commit 76385f2ebbbc9580a9c236952d68d11d73a6135c diff --git a/subprojects/libh2o b/subprojects/libh2o index 41958a8aed..3b1f53c86b 160000 --- a/subprojects/libh2o +++ b/subprojects/libh2o @@ -1 +1 @@ -Subproject commit 41958a8aedb3aa2a85332bc8ac0ac389aa725a09 +Subproject commit 3b1f53c86b71f6fdc099b3b378de6f379b4b8412 diff --git a/subprojects/libscrypt b/subprojects/libscrypt index 4ebe362f39..029693ff1c 160000 --- a/subprojects/libscrypt +++ b/subprojects/libscrypt @@ -1 +1 @@ -Subproject commit 4ebe362f390025e5448e9fcf777c1f38630bc011 +Subproject commit 029693ff1cbe4f69d3a2da87d0f4f034f92cc0c2 diff --git a/subprojects/libsni b/subprojects/libsni index a59901c38a..173beb88ee 160000 --- a/subprojects/libsni +++ b/subprojects/libsni @@ -1 +1 @@ -Subproject commit a59901c38a67660039ee93a6170a338634d76ec0 +Subproject commit 173beb88ee62bddd13874ca04ab338cdec704928 diff --git a/subprojects/libuv b/subprojects/libuv index 9e3aece814..0c3a346a60 160000 --- a/subprojects/libuv +++ b/subprojects/libuv @@ -1 +1 @@ -Subproject commit 9e3aece8147d28246c57b84731dad26130c7d1c1 +Subproject commit 0c3a346a60f0b3bb42445b2c63198a6e0f94c89b diff --git a/subprojects/murmur3 b/subprojects/murmur3 index 001378cbe3..71a75d57ca 160000 --- a/subprojects/murmur3 +++ b/subprojects/murmur3 @@ -1 +1 @@ -Subproject commit 001378cbe3681af1137553ed7220c79273850d6a +Subproject commit 71a75d57ca4e7ca0f7fc2fd84abd93595b0624ca diff --git a/subprojects/secp256k1 b/subprojects/secp256k1 index 9989e23ce8..66a72cf208 160000 --- a/subprojects/secp256k1 +++ b/subprojects/secp256k1 @@ -1 +1 @@ -Subproject commit 9989e23ce8a02a51a1f90a2d5e391ba7d16bef39 +Subproject commit 66a72cf2084799d0799874d4fa3c530a73713d81 diff --git a/subprojects/softfloat3 b/subprojects/softfloat3 index 9d4342099a..ec4c7e31b3 160000 --- a/subprojects/softfloat3 +++ b/subprojects/softfloat3 @@ -1 +1 @@ -Subproject commit 9d4342099a54cefc3a4117ce0d0c71cff4e48783 +Subproject commit ec4c7e31b32e07aad80e52f65ff46ac6d6aad986 From c2a0800bf8961f7b2122904133b4dfde0611154e Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 14:40:30 -0500 Subject: [PATCH 53/90] requires less-recent libcurl release --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index a4925d434f..6f4bc19709 100644 --- a/meson.build +++ b/meson.build @@ -296,7 +296,7 @@ configure_file(input : 'include/config.h.in', configuration : conf_data) # We expect these libs to supplied with the distribution -curl_dep = dependency('libcurl', version: '>=7.35.0') +curl_dep = dependency('libcurl', version: '>=7.19.0') if osdet == 'darwin' and not get_option('nix') libcrypto = meson.get_compiler('c').find_library('crypto', dirs: [ '/usr/local/opt/openssl/lib/' ]) From 012424c5d5aa96a2f90a9be85efa10fcaef54b26 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 14:43:11 -0500 Subject: [PATCH 54/90] matches "freebsd" in os conditional --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 6f4bc19709..1992a001ea 100644 --- a/meson.build +++ b/meson.build @@ -272,7 +272,7 @@ elif osdet == 'darwin' os_deps = os_deps + [ncurses_dep] -elif osdet == 'bsd' +elif osdet == 'bsd' or osdet == 'freebsd' conf_data.set('U3_OS_bsd', true) pthread_dep = meson.get_compiler('c').find_library('pthread') From 7d6da1bcf0c781f04519725d106e62a13d9a933c Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 14:46:58 -0500 Subject: [PATCH 55/90] uses linker flags for openbsd --- meson.build | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 1992a001ea..558c33c987 100644 --- a/meson.build +++ b/meson.build @@ -279,6 +279,13 @@ elif osdet == 'bsd' or osdet == 'freebsd' kvm_dep = meson.get_compiler('c').find_library('kvm') ncurses_dep = dependency('ncurses') os_deps = os_deps + [kvm_dep, pthread_dep, ncurses_dep] + +elif osdet == 'openbsd' + conf_data.set('U3_OS_bsd', true) + os_link_flags = ['-L /usr/local/lib', '-lgmp', '-lsigsegv', '-lcurses'] + gmp_dep = [] + sigsegv_dep = [] + else error('Unsupported OS detected:' + osdet) endif @@ -309,7 +316,7 @@ endif if(legacy_meson) gmp_dep = find_library('gmp') sigsegv_dep = find_library('sigsegv') -else +elif osdet != 'openbsd' gmp_dep = meson.get_compiler('c').find_library('gmp') sigsegv_dep = meson.get_compiler('c').find_library('sigsegv') endif From 626638810904fad9501e442b319f25c70d572b6a Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 16:03:37 -0500 Subject: [PATCH 56/90] removes commonmark and the markdown jet --- .gitmodules | 3 - include/jets/w.h | 4 - include/jets/y.h | 4 - jets/g/down.c | 220 ---------------------------------- jets/tree.c | 13 +- meson.build | 9 +- subprojects/commonmark-legacy | 1 - 7 files changed, 3 insertions(+), 251 deletions(-) delete mode 100644 jets/g/down.c delete mode 160000 subprojects/commonmark-legacy diff --git a/.gitmodules b/.gitmodules index 54f5235117..83769058b1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "subprojects/softfloat3"] path = subprojects/softfloat3 url = https://github.com/urbit/berkeley-softfloat-3.git -[submodule "subprojects/commonmark-legacy"] - path = subprojects/commonmark-legacy - url = https://github.com/urbit/commonmark-legacy.git [submodule "subprojects/ed25519"] path = subprojects/ed25519 url = https://github.com/urbit/ed25519.git diff --git a/include/jets/w.h b/include/jets/w.h index d8b5d8017e..dae4c80eeb 100644 --- a/include/jets/w.h +++ b/include/jets/w.h @@ -289,7 +289,3 @@ u3_noun u3wfu_snub(u3_noun); u3_noun u3wfu_toss(u3_noun); u3_noun u3wfu_wrap(u3_noun); - - /** Tier 7. - **/ - u3_noun u3wg_down(u3_noun); diff --git a/include/jets/y.h b/include/jets/y.h index f106e2b3dc..58b2595512 100644 --- a/include/jets/y.h +++ b/include/jets/y.h @@ -327,7 +327,3 @@ u3_noun u3wzu_snub(u3_noun); u3_noun u3wzu_toss(u3_noun); u3_noun u3wzu_wrap(u3_noun); - - /** Tier 7. - **/ - u3_noun u3yg_down(u3_noun); diff --git a/jets/g/down.c b/jets/g/down.c deleted file mode 100644 index 5f80290fb6..0000000000 --- a/jets/g/down.c +++ /dev/null @@ -1,220 +0,0 @@ -/* j/g/down.c -** -*/ -#include "all.h" -#include -#include -#include - -static u3_noun node_to_noun(cmark_node * nod); - -static u3_noun list_elems_to_noun(cmark_node * nod) -{ - u3_noun elems = u3_nul; - - cmark_node * child; - for ( child = nod->last_child; child; child = child->prev ) { - elems = u3nc(node_to_noun(child),elems); - } - - return elems; -} - -static u3_noun document_to_noun(cmark_node * nod) -{ - return list_elems_to_noun(nod); -} - -static u3_noun block_quote_to_noun(cmark_node * nod) -{ - return u3nc(u3nc(c3__bloq,u3_nul),list_elems_to_noun(nod)); -} - -static u3_noun list_to_noun(cmark_node * nod) -{ - return - u3nc( - u3nt( - c3__list, - __(nod->as.list.tight), - (nod->as.list.list_type == CMARK_BULLET_LIST) - ? nod->as.list.bullet_char /* XX convert? */ - : u3nc(nod->as.list.start, - (nod->as.list.delimiter == CMARK_PERIOD_DELIM) - ? '.' - : ')')), - list_elems_to_noun(nod)); -} - -static u3_noun list_item_to_noun(cmark_node * nod) -{ - return u3nc(u3nc(c3__item,u3_nul),list_elems_to_noun(nod)); -} - -static u3_noun code_block_to_noun(cmark_node * nod) -{ - u3_atom str = u3i_string((c3_c *) nod->string_content.ptr); /* XX u3i_bytes */ - u3_noun res = - u3nt( - c3__code, - nod->as.code.fenced - ? u3nq( - u3_nul, - nod->as.code.fence_char, - nod->as.code.fence_length, - u3i_tape((c3_c *) nod->as.code.info.ptr) - ) - : u3_nul, - u3qe_lore(str)); - u3z(str); - return res; -} - -static u3_noun html_to_noun(cmark_node * nod) -{ - u3_atom str = u3i_string((c3_c *) nod->string_content.ptr); /* XX u3i_bytes */ - u3_noun res = u3nc(c3__html, u3qe_lore(str)); - u3z(str); - return res; -} - -static u3_noun paragraph_to_noun(cmark_node * nod) -{ - return u3nc(c3__para, list_elems_to_noun(nod)); -} - -static u3_noun header_to_noun(cmark_node * nod) -{ - /* see also nod->as.header.setext */ - return u3nt(c3__head, nod->as.header.level, list_elems_to_noun(nod)); -} - -static u3_noun hrule_to_noun(cmark_node * nod) -{ - return u3nc(c3__hrul, u3_nul); -} - -static u3_noun reference_def_to_noun(cmark_node * nod) -{ - return u3nc(c3__defn, u3_nul); -} - -static u3_noun text_to_noun(cmark_node * nod) -{ - return u3nc(u3_blip, u3i_tape((c3_c *) cmark_chunk_to_cstr(&nod->as.literal))); -} - -static u3_noun softbreak_to_noun(cmark_node * nod) // XXX -{ - return u3nt(0, 10, 0); -} - -static u3_noun linebreak_to_noun(cmark_node * nod) -{ - return u3nc(c3__line, u3_nul); -} - -static u3_noun inline_code_to_noun(cmark_node * nod) -{ - return u3nc(c3__code, u3i_tape((c3_c *) cmark_chunk_to_cstr(&nod->as.literal))); -} - -static u3_noun inline_html_to_noun(cmark_node * nod) // XXX -{ - return u3nc(c3__htmt, u3i_string((c3_c *) cmark_chunk_to_cstr(&nod->as.literal))); -} - -static u3_noun emph_to_noun(cmark_node * nod) -{ - return u3nc(u3nc(c3__emph, c3n), list_elems_to_noun(nod)); -} - -static u3_noun strong_to_noun(cmark_node * nod) -{ - return u3nc(u3nc(c3__emph, c3y), list_elems_to_noun(nod)); -} - -static u3_noun link_to_noun(cmark_node * nod) -{ - return u3nc(u3nt(c3__link, - nod->as.link.url - ? u3i_tape((c3_c *) nod->as.link.url) - : u3_nul, - nod->as.link.title - ? u3nc(u3_nul, u3i_tape((c3_c *) nod->as.link.title)) - : u3_nul), - list_elems_to_noun(nod)); -} - -static u3_noun image_to_noun(cmark_node * nod) -{ - return u3nc(u3nt(c3__blot, - u3i_tape((c3_c *) nod->as.link.url), - nod->as.link.title - ? u3nc(u3_nul, u3i_tape((c3_c *) nod->as.link.title)) - : u3_nul), - list_elems_to_noun(nod)); -} - -static u3_noun node_to_noun(cmark_node * nod) -{ - if (!nod) { - fprintf(stderr, "markdown null node"); - return u3m_bail(c3__fail); - } - switch ( nod->type ) { - /* Block */ - case CMARK_NODE_DOCUMENT: return document_to_noun(nod); - case CMARK_NODE_BLOCK_QUOTE: return block_quote_to_noun(nod); - case CMARK_NODE_LIST: return list_to_noun(nod); - case CMARK_NODE_LIST_ITEM: return list_item_to_noun(nod); - case CMARK_NODE_CODE_BLOCK: return code_block_to_noun(nod); - case CMARK_NODE_HTML: return html_to_noun(nod); - case CMARK_NODE_PARAGRAPH: return paragraph_to_noun(nod); - case CMARK_NODE_HEADER: return header_to_noun(nod); - case CMARK_NODE_HRULE: return hrule_to_noun(nod); - case CMARK_NODE_REFERENCE_DEF: return reference_def_to_noun(nod); - /* Inline */ - case CMARK_NODE_TEXT: return text_to_noun(nod); - case CMARK_NODE_SOFTBREAK: return softbreak_to_noun(nod); - case CMARK_NODE_LINEBREAK: return linebreak_to_noun(nod); - case CMARK_NODE_INLINE_CODE: return inline_code_to_noun(nod); - case CMARK_NODE_INLINE_HTML: return inline_html_to_noun(nod); - case CMARK_NODE_EMPH: return emph_to_noun(nod); - case CMARK_NODE_STRONG: return strong_to_noun(nod); - case CMARK_NODE_LINK: return link_to_noun(nod); - case CMARK_NODE_IMAGE: return image_to_noun(nod); - default: fprintf(stderr, "bad markdown parsing"); - return u3m_bail(c3__fail); - } -} - -/* functions -*/ - u3_noun - u3qg_down(u3_atom a) - { - c3_c *tex = u3r_string(a); - - /* XX better strlen */ - cmark_node * doc = cmark_parse_document(tex, strlen(tex)); - - u3_noun res = document_to_noun(doc); - - cmark_node_free(doc); - // free out, tex? - return res; - } - u3_noun - u3wg_down(u3_noun cor) - { - u3_noun a; - - if ( (u3_none == (a = u3r_at(u3x_sam, cor))) || - (c3n == u3ud(a)) ) - { - return u3m_bail(c3__exit); - } else { - return u3qg_down(a); - } - } diff --git a/jets/tree.c b/jets/tree.c index 254a7b4654..0bfe6cf7eb 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -81,15 +81,6 @@ static u3j_core _141_hex_aes_d[] = }; static c3_c* _141_hex_aes_ha[] = {0}; -static u3j_harm _141_hex_down_mark_a[] = {{".2", u3wg_down, c3y}, {}}; -static c3_c* _141_hex_down_mark_ha[] = {0}; - - static u3j_core _141_hex_down_d[] = - { { "mark", 7, _141_hex_down_mark_a, 0, _141_hex_down_mark_ha }, - {} - }; -static c3_c* _141_hex_down_ha[] = {0}; - static u3j_harm _141_hex_lore_a[] = {{".2", u3we_lore}, {}}; static c3_c* _141_hex_lore_ha[] = {0}; static u3j_harm _141_hex_loss_a[] = {{".2", u3we_loss}, {}}; @@ -181,9 +172,7 @@ static c3_c* _141_hex_ripe_ha[] = {0}; static u3j_core _141_hex_d[] = -{ { "down", 8063, 0, _141_hex_down_d, _141_hex_down_ha }, - - { "lore", 63, _141_hex_lore_a, 0, _141_hex_lore_ha }, +{ { "lore", 63, _141_hex_lore_a, 0, _141_hex_lore_ha }, { "loss", 63, _141_hex_loss_a, 0, _141_hex_loss_ha }, { "lune", 127, _141_hex_lune_a, 0, _141_hex_lune_ha }, diff --git a/meson.build b/meson.build index a4925d434f..d023d4adac 100644 --- a/meson.build +++ b/meson.build @@ -179,10 +179,6 @@ jets_f_ut_src = [ 'jets/f/ut_wrap.c' ] -jets_g_src = [ -'jets/g/down.c' -] - jets_src = [ 'jets/tree.c' ] @@ -192,7 +188,8 @@ jets_all_src = [ jets_c_src, jets_d_src, jets_e_src, jets_e_ed_src, jets_f_src, jets_f_ut_src, - jets_g_src, jets_src] + jets_src +] noun_src = [ 'noun/allocate.c', @@ -315,7 +312,6 @@ else endif # For these libs we provide fallback bundle -cmark_dep = dependency('libcmark', version: '0.12.0', fallback: ['commonmark-legacy', 'cmark_dep']) urbitscrypt_dep = dependency('libscrypt', version: '>=0.1.21', fallback: ['libscrypt', 'libscrypt_dep']) ed25519_dep = dependency('ed25519', version: '>=0.1.0', fallback: ['ed25519', 'ed25519_dep']) @@ -332,7 +328,6 @@ deps = [openssl_dep, curl_dep, libuv_dep, libh2o_dep, - cmark_dep, secp256k1_dep, gmp_dep, sigsegv_dep, diff --git a/subprojects/commonmark-legacy b/subprojects/commonmark-legacy deleted file mode 160000 index 8555ef14c4..0000000000 --- a/subprojects/commonmark-legacy +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8555ef14c4a503f57a0d192bb120159239f4322c From de7df542c91800503b72dd7453da13c4e1fc3a5b Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 17:04:48 -0500 Subject: [PATCH 57/90] updates c3_assert() to print assertion/file/line before bail --- include/c/defs.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/c/defs.h b/include/c/defs.h index c0eb6e5701..74dfeeb339 100644 --- a/include/c/defs.h +++ b/include/c/defs.h @@ -17,8 +17,17 @@ **/ /* Assert. Good to capture. */ -// # define c3_assert(x) assert(x) -# define c3_assert(x) ( (x) ? 0 : c3_cooked(), assert(x) ) +# define c3_assert(x) \ + do { \ + if (!(x)) { \ + fprintf(stderr, \ + "\rAssertion '%s' failed " \ + "in %s:%d\n", \ + #x, __FILE__, __LINE__); \ + c3_cooked(); \ + assert(x); \ + } \ + } while(0) /* Stub. */ From 98604d04d0cc2da30901697d01e717e40ed6cee5 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 17:49:05 -0500 Subject: [PATCH 58/90] fix (my own) use-after-free in unix dir/file watch --- vere/unix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vere/unix.c b/vere/unix.c index 5903d22000..7ee2f39182 100644 --- a/vere/unix.c +++ b/vere/unix.c @@ -590,7 +590,8 @@ _unix_watch_file(u3_ufil* fil_u, u3_udir* par_u, c3_c* pax_c) fil_u->dir = c3n; fil_u->dry = c3n; - fil_u->pax_c = pax_c; + fil_u->pax_c = c3_malloc(1 + strlen(pax_c)); + strcpy(fil_u->pax_c, pax_c); fil_u->par_u = par_u; fil_u->nex_u = NULL; fil_u->mug_w = 0; @@ -627,7 +628,8 @@ _unix_watch_dir(u3_udir* dir_u, u3_udir* par_u, c3_c* pax_c) dir_u->dir = c3y; dir_u->dry = c3n; - dir_u->pax_c = pax_c; + dir_u->pax_c = c3_malloc(1 + strlen(pax_c)); + strcpy(dir_u->pax_c, pax_c); dir_u->par_u = par_u; dir_u->nex_u = NULL; dir_u->kid_u = NULL; From fc2eaf1132181341e0386218e74bf06ecbbfe999 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 10 Dec 2018 18:02:37 -0500 Subject: [PATCH 59/90] ensure file path is always freed --- vere/unix.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vere/unix.c b/vere/unix.c index 7ee2f39182..0b5f9002f7 100644 --- a/vere/unix.c +++ b/vere/unix.c @@ -371,6 +371,8 @@ _unix_scan_mount_point(u3_umon* mon_u) _unix_watch_file(fil_u, &mon_u->dir_u, pax_c); } } + + free(pax_c); } } } From a2a6b7e810196c174237aef8c55acb6827df1323 Mon Sep 17 00:00:00 2001 From: Joseph Bryan Date: Sat, 24 Feb 2018 01:59:53 -0500 Subject: [PATCH 60/90] disables tracing exit printf when tracing is off --- noun/trace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noun/trace.c b/noun/trace.c index af3b1a23d8..d2a9e9a0c3 100644 --- a/noun/trace.c +++ b/noun/trace.c @@ -531,10 +531,10 @@ u3t_print_steps(c3_c* cap_c, c3_d sep_d) void u3t_damp(void) { - fprintf(stderr, "\r\n"); - if ( 0 != u3R->pro.day ) { u3_noun wol = u3do("pi-tell", u3R->pro.day); + + fprintf(stderr, "\r\n"); u3_term_wall(wol); /* bunt a +doss From cf935baf0fb91cc0029e24834f22ae0e860d27d5 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 19 Dec 2017 05:11:55 -0800 Subject: [PATCH 61/90] Synchronous egg commitment --- vere/raft.c | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index e14e065233..5e5de9ea23 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1622,35 +1622,6 @@ _raft_punk(u3_noun ovo) } -static void -_raft_comm(c3_d bid_d) -{ - u3p(u3v_cart) egg_p; - - u3_lo_open(); - - egg_p = u3A->ova.egg_p; - while ( egg_p ) { - u3v_cart* egg_u = u3to(u3v_cart, egg_p); - - if ( egg_u->ent_d <= bid_d ) { - egg_u->cit = c3y; - } else break; - - egg_p = egg_u->nex_p; - } - u3_lo_shut(c3y); -} - -static void -_raft_comm_cb(uv_timer_t* tim_u) -{ - u3_raft* raf_u = tim_u->data; - - _raft_comm(raf_u->ent_d); -} - - static c3_d _raft_push(u3_raft* raf_u, c3_w* bob_w, c3_w len_w) { @@ -1664,8 +1635,17 @@ _raft_push(u3_raft* raf_u, c3_w* bob_w, c3_w len_w) u3t_event_trace("Recording", 'e'); raf_u->lat_w = raf_u->tem_w; // XX - if ( !uv_is_active((uv_handle_t*)&raf_u->tim_u) ) { - uv_timer_start(&raf_u->tim_u, _raft_comm_cb, 0, 0); + u3p(u3v_cart) egg_p; + + egg_p = u3A->ova.egg_p; + while ( egg_p ) { + u3v_cart* egg_u = u3to(u3v_cart, egg_p); + + if ( egg_u->ent_d <= raf_u->ent_d ) { + egg_u->cit = c3y; + } else break; + + egg_p = egg_u->nex_p; } return raf_u->ent_d; From 43d18fd0a35b85efc7cd853787bbddcb6db7aa9a Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 19 Dec 2017 05:25:33 -0800 Subject: [PATCH 62/90] uncouple roe mutation --- vere/raft.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index 5e5de9ea23..d86ec9104f 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1445,17 +1445,19 @@ u3_raft_init() /* _raft_sure(): apply and save an input ovum and its result. */ -static void +static u3_noun _raft_sure(u3_noun ovo, u3_noun vir, u3_noun cor) { // Whatever worked, save it. (XX - should be concurrent with execute.) // We'd like more events that don't change the state but need work here. { + u3_noun ret; + u3r_mug(cor); u3r_mug(u3A->roc); if ( c3n == u3r_sing(cor, u3A->roc) ) { - u3A->roe = u3nc(u3nc(vir, ovo), u3A->roe); + ret = u3nc(vir, ovo); u3z(u3A->roc); u3A->roc = cor; @@ -1464,19 +1466,21 @@ _raft_sure(u3_noun ovo, u3_noun vir, u3_noun cor) u3z(ovo); // push a new event into queue - u3A->roe = u3nc(u3nc(vir, u3_nul), u3A->roe); + ret = u3nc(vir, u3_nul); u3z(cor); } + return ret; } } /* _raft_lame(): handle an application failure. */ -static void +static u3_weak _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) { u3_noun bov, gon; + u3_noun ret; #if 0 { @@ -1509,10 +1513,12 @@ _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) gon = u3m_soft(0, u3v_poke, u3k(bov)); if ( u3_blip == u3h(gon) ) { - _raft_sure(bov, u3k(u3h(u3t(gon))), u3k(u3t(u3t(gon)))); + ret = _raft_sure(bov, u3k(u3h(u3t(gon))), u3k(u3t(u3t(gon)))); u3z(tan); u3z(gon); + + return ret; } else { u3z(gon); @@ -1522,9 +1528,11 @@ _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) u3_noun nog = u3m_soft(0, u3v_poke, u3k(vab)); if ( u3_blip == u3h(nog) ) { - _raft_sure(vab, u3k(u3h(u3t(nog))), u3k(u3t(u3t(nog)))); + ret = _raft_sure(vab, u3k(u3h(u3t(nog))), u3k(u3t(u3t(nog)))); u3z(tan); u3z(nog); + + return ret; } else { u3z(nog); @@ -1534,6 +1542,8 @@ _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) u3_lo_punt(2, u3kb_flop(u3k(tan))); uL(fprintf(uH, "crude: punted\n")); // c3_assert(!"crud"); + + return u3_nul; } } } @@ -1541,7 +1551,7 @@ _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) /* _raft_punk(): insert and apply an input ovum (unprotected). */ -static void +static u3_weak _raft_punk(u3_noun ovo) { #ifdef GHETTO @@ -1592,7 +1602,7 @@ _raft_punk(u3_noun ovo) u3_noun tan = u3k(u3t(gon)); u3z(gon); - _raft_lame(ovo, why, tan); + return _raft_lame(ovo, why, tan); } else { u3_noun vir = u3k(u3h(u3t(gon))); @@ -1607,14 +1617,14 @@ _raft_punk(u3_noun ovo) u3_noun tan = u3k(u3t(nug)); u3z(nug); - _raft_lame(ovo, why, tan); + return _raft_lame(ovo, why, tan); } else { vir = u3k(u3h(u3t(nug))); cor = u3k(u3t(u3t(nug))); u3z(nug); - _raft_sure(ovo, vir, cor); + return _raft_sure(ovo, vir, cor); } } // uL(fprintf(uH, "punk oot %s\n", txt_c)); @@ -1969,7 +1979,10 @@ u3_raft_work(void) } while ( u3_nul != ova ) { - _raft_punk(u3k(u3t(u3h(ova)))); + u3_noun sur = _raft_punk(u3k(u3t(u3h(ova)))); + if ( u3_nul != sur) { + u3A->roe = u3nc(sur, u3A->roe); + } c3_assert(u3_nul == u3h(u3h(ova))); nex = u3k(u3t(ova)); From 94cacc5629fbd64100ca3ac247d6d20a1d1f7897 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 19 Dec 2017 05:36:03 -0800 Subject: [PATCH 63/90] factored out _raft_crop() and _raft_poke() --- vere/raft.c | 122 +++++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 53 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index d86ec9104f..fc7be85ede 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1922,6 +1922,69 @@ _raft_grab(u3_noun ova) int FOO; +/* _raft_crop(): Delete finished events. +*/ +static void +_raft_crop(void) +{ + while ( u3A->ova.egg_p ) { + u3p(u3v_cart) egg_p = u3A->ova.egg_p; + u3v_cart* egg_u = u3to(u3v_cart, u3A->ova.egg_p); + + if ( c3y == egg_u->did ) { + if ( egg_p == u3A->ova.geg_p ) { + c3_assert(egg_u->nex_p == 0); + u3A->ova.geg_p = u3A->ova.egg_p = 0; + } + else { + c3_assert(egg_u->nex_p != 0); + u3A->ova.egg_p = egg_u->nex_p; + } + egg_u->cit = c3y; + u3a_free(egg_u); + } + else break; + } +} + + +/* _raft_poke(): Poke pending events, leaving the poked events + * and errors on u3A->roe. +*/ +static void +_raft_poke(void) +{ + u3_noun ova, nex; + + if ( 0 == u3Z->lug_u.len_d ) { + return; + } + ova = u3kb_flop(u3A->roe); + u3A->roe = u3_nul; + + u3_noun hed = (u3_nul == ova) ? u3_nul : u3h(ova); + + if ( u3_nul != hed ) { + u3_term_ef_blit(0, u3nc(u3nc(c3__bee, u3k(hed)), u3_nul)); + } + + while ( u3_nul != ova ) { + u3_noun sur = _raft_punk(u3k(u3t(u3h(ova)))); + if ( u3_nul != sur) { + u3A->roe = u3nc(sur, u3A->roe); + } + c3_assert(u3_nul == u3h(u3h(ova))); + + nex = u3k(u3t(ova)); + u3z(ova); ova = nex; + } + + if ( u3_nul != hed ) { + u3_term_ef_blit(0, u3nc(u3nc(c3__bee, u3_nul), u3_nul)); + } +} + + /* u3_raft_work(): work. */ void @@ -1936,63 +1999,13 @@ u3_raft_work(void) } } else { - u3_noun ova; - u3_noun vir; - u3_noun nex; - // Delete finished events. // - while ( u3A->ova.egg_p ) { - u3p(u3v_cart) egg_p = u3A->ova.egg_p; - u3v_cart* egg_u = u3to(u3v_cart, u3A->ova.egg_p); - - if ( c3y == egg_u->did ) { - vir = egg_u->vir; - - if ( egg_p == u3A->ova.geg_p ) { - c3_assert(egg_u->nex_p == 0); - u3A->ova.geg_p = u3A->ova.egg_p = 0; - } - else { - c3_assert(egg_u->nex_p != 0); - u3A->ova.egg_p = egg_u->nex_p; - } - egg_u->cit = c3y; - u3a_free(egg_u); - } - else break; - } + _raft_crop(); // Poke pending events, leaving the poked events and errors on u3A->roe. // - { - if ( 0 == u3Z->lug_u.len_d ) { - return; - } - ova = u3kb_flop(u3A->roe); - u3A->roe = u3_nul; - - u3_noun hed = (u3_nul == ova) ? u3_nul : u3h(ova); - - if ( u3_nul != hed ) { - u3_term_ef_blit(0, u3nc(u3nc(c3__bee, u3k(hed)), u3_nul)); - } - - while ( u3_nul != ova ) { - u3_noun sur = _raft_punk(u3k(u3t(u3h(ova)))); - if ( u3_nul != sur) { - u3A->roe = u3nc(sur, u3A->roe); - } - c3_assert(u3_nul == u3h(u3h(ova))); - - nex = u3k(u3t(ova)); - u3z(ova); ova = nex; - } - - if ( u3_nul != hed ) { - u3_term_ef_blit(0, u3nc(u3nc(c3__bee, u3_nul), u3_nul)); - } - } + _raft_poke(); // Cartify, jam, and encrypt this batch of events. Take a number, Raft will // be with you shortly. @@ -2000,8 +2013,11 @@ u3_raft_work(void) c3_d bid_d; c3_w len_w; c3_w* bob_w; - u3_noun ron; + u3_noun ova; u3_noun ovo; + u3_noun vir; + u3_noun nex; + u3_noun ron; ova = u3kb_flop(u3A->roe); u3A->roe = u3_nul; From 0a66673134c7f66110d8dfa9d2c55d3b64e08c33 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 19 Dec 2017 05:44:07 -0800 Subject: [PATCH 64/90] factor out raft_pump() --- vere/raft.c | 83 +++++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index fc7be85ede..5c20653d5a 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1985,6 +1985,51 @@ _raft_poke(void) } +/* _raft_pump(): Cartify, jam, and save an ovum, then perform its effects. +*/ +static void +_raft_pump(ovo, vir) +{ + u3v_cart* egg_u = u3a_malloc(sizeof(*egg_u)); + u3p(u3v_cart) egg_p = u3of(u3v_cart, egg_u); + u3_noun ron; + c3_d bid_d; + c3_w len_w; + c3_w* bob_w; + + egg_u->nex_p = 0; + egg_u->cit = c3n; + egg_u->did = c3n; + egg_u->vir = vir; + + ron = u3ke_jam(u3nc(u3k(u3A->now), ovo)); + c3_assert(u3A->key); + // don't encrypt for the moment, bootstrapping + // ron = u3dc("en:crua", u3k(u3A->key), ron); + + len_w = u3r_met(5, ron); + bob_w = c3_malloc(len_w * 4L); + u3r_words(0, len_w, bob_w, ron); + u3z(ron); + + bid_d = _raft_push(u3Z, bob_w, len_w); + egg_u->ent_d = bid_d; + + if ( 0 == u3A->ova.geg_p ) { + c3_assert(0 == u3A->ova.egg_p); + u3A->ova.geg_p = u3A->ova.egg_p = egg_p; + } + else { + c3_assert(0 == u3to(u3v_cart, u3A->ova.geg_p)->nex_p); + u3to(u3v_cart, u3A->ova.geg_p)->nex_p = egg_p; + u3A->ova.geg_p = egg_p; + } + _raft_kick_all(vir); + egg_u->did = c3y; + egg_u->vir = 0; +} + + /* u3_raft_work(): work. */ void @@ -2010,14 +2055,10 @@ u3_raft_work(void) // Cartify, jam, and encrypt this batch of events. Take a number, Raft will // be with you shortly. { - c3_d bid_d; - c3_w len_w; - c3_w* bob_w; u3_noun ova; u3_noun ovo; u3_noun vir; u3_noun nex; - u3_noun ron; ova = u3kb_flop(u3A->roe); u3A->roe = u3_nul; @@ -2029,39 +2070,7 @@ u3_raft_work(void) u3z(ova); ova = nex; if ( u3_nul != ovo ) { - u3v_cart* egg_u = u3a_malloc(sizeof(*egg_u)); - u3p(u3v_cart) egg_p = u3of(u3v_cart, egg_u); - - egg_u->nex_p = 0; - egg_u->cit = c3n; - egg_u->did = c3n; - egg_u->vir = vir; - - ron = u3ke_jam(u3nc(u3k(u3A->now), ovo)); - c3_assert(u3A->key); - // don't encrypt for the moment, bootstrapping - // ron = u3dc("en:crua", u3k(u3A->key), ron); - - len_w = u3r_met(5, ron); - bob_w = c3_malloc(len_w * 4L); - u3r_words(0, len_w, bob_w, ron); - u3z(ron); - - bid_d = _raft_push(u3Z, bob_w, len_w); - egg_u->ent_d = bid_d; - - if ( 0 == u3A->ova.geg_p ) { - c3_assert(0 == u3A->ova.egg_p); - u3A->ova.geg_p = u3A->ova.egg_p = egg_p; - } - else { - c3_assert(0 == u3to(u3v_cart, u3A->ova.geg_p)->nex_p); - u3to(u3v_cart, u3A->ova.geg_p)->nex_p = egg_p; - u3A->ova.geg_p = egg_p; - } - _raft_kick_all(vir); - egg_u->did = c3y; - egg_u->vir = 0; + _raft_pump(ovo, vir); _raft_grab(ova); } From 97408e42f490b4a933ba77de74749b49f17ff8f4 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 11 Dec 2018 15:54:06 -0500 Subject: [PATCH 65/90] handles effect/event pairs singly while iterating queue --- vere/raft.c | 90 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index 5c20653d5a..7e89aeeb93 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1476,7 +1476,7 @@ _raft_sure(u3_noun ovo, u3_noun vir, u3_noun cor) /* _raft_lame(): handle an application failure. */ -static u3_weak +static u3_noun _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) { u3_noun bov, gon; @@ -1551,7 +1551,7 @@ _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) /* _raft_punk(): insert and apply an input ovum (unprotected). */ -static u3_weak +static u3_noun _raft_punk(u3_noun ovo) { #ifdef GHETTO @@ -1631,7 +1631,8 @@ _raft_punk(u3_noun ovo) // free(txt_c); } - +/* _raft_push(): save an event +*/ static c3_d _raft_push(u3_raft* raf_u, c3_w* bob_w, c3_w len_w) { @@ -1947,6 +1948,26 @@ _raft_crop(void) } } +/* _raft_pop_roe(): pop the next [(list effects) event] pair of the queue +*/ +static u3_weak +_raft_pop_roe(void) +{ + if ( u3_nul == u3A->roe ) { + return u3_none; + } + + u3_noun ovo; + + { + u3_noun ova = u3kb_flop(u3A->roe); + u3A->roe = u3qb_flop(u3t(ova)); + ovo = u3k(u3h(ova)); + u3z(ova); + } + + return ovo; +} /* _raft_poke(): Poke pending events, leaving the poked events * and errors on u3A->roe. @@ -1954,41 +1975,44 @@ _raft_crop(void) static void _raft_poke(void) { - u3_noun ova, nex; - if ( 0 == u3Z->lug_u.len_d ) { return; } - ova = u3kb_flop(u3A->roe); - u3A->roe = u3_nul; - u3_noun hed = (u3_nul == ova) ? u3_nul : u3h(ova); + c3_o bee_o = c3n; + u3_noun oer = u3_nul; + u3_weak rus; - if ( u3_nul != hed ) { - u3_term_ef_blit(0, u3nc(u3nc(c3__bee, u3k(hed)), u3_nul)); - } + while ( u3_none != (rus = _raft_pop_roe()) ) { + u3_noun ovo, vir, sur; - while ( u3_nul != ova ) { - u3_noun sur = _raft_punk(u3k(u3t(u3h(ova)))); - if ( u3_nul != sur) { - u3A->roe = u3nc(sur, u3A->roe); + if ( c3n == bee_o ) { + u3_term_ef_blit(0, u3nc(u3nc(c3__bee, u3k(rus)), u3_nul)); + bee_o = c3y; } - c3_assert(u3_nul == u3h(u3h(ova))); - nex = u3k(u3t(ova)); - u3z(ova); ova = nex; + u3x_cell(rus, &vir, &ovo); + c3_assert( u3_nul == vir ); + + sur = _raft_punk(u3k(ovo)); + u3z(rus); + + if ( u3_nul != sur) { + oer = u3nc(sur, oer); + } } - if ( u3_nul != hed ) { + u3A->roe = oer; + + if ( c3y == bee_o ) { u3_term_ef_blit(0, u3nc(u3nc(c3__bee, u3_nul), u3_nul)); } } - /* _raft_pump(): Cartify, jam, and save an ovum, then perform its effects. */ static void -_raft_pump(ovo, vir) +_raft_pump(u3_noun ovo, u3_noun vir) { u3v_cart* egg_u = u3a_malloc(sizeof(*egg_u)); u3p(u3v_cart) egg_p = u3of(u3v_cart, egg_u); @@ -2029,7 +2053,6 @@ _raft_pump(ovo, vir) egg_u->vir = 0; } - /* u3_raft_work(): work. */ void @@ -2055,25 +2078,18 @@ u3_raft_work(void) // Cartify, jam, and encrypt this batch of events. Take a number, Raft will // be with you shortly. { - u3_noun ova; - u3_noun ovo; - u3_noun vir; - u3_noun nex; + u3_weak rus; - ova = u3kb_flop(u3A->roe); - u3A->roe = u3_nul; - - while ( u3_nul != ova ) { - ovo = u3k(u3t(u3h(ova))); - vir = u3k(u3h(u3h(ova))); - nex = u3k(u3t(ova)); - u3z(ova); ova = nex; + while ( u3_none != (rus = _raft_pop_roe()) ) { + u3_noun ovo, vir; + u3x_cell(rus, &vir, &ovo); if ( u3_nul != ovo ) { - _raft_pump(ovo, vir); - - _raft_grab(ova); + _raft_pump(u3k(ovo), u3k(vir)); + _raft_grab(u3A->roe); } + + u3z(rus); } } } From 6e77f2b2c1b62980ebcfc84a0ebb16657592a933 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 19 Dec 2017 06:37:10 -0800 Subject: [PATCH 66/90] synchronously processes each event singly --- vere/raft.c | 95 ++++++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index 7e89aeeb93..3b4a005053 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1969,44 +1969,36 @@ _raft_pop_roe(void) return ovo; } -/* _raft_poke(): Poke pending events, leaving the poked events - * and errors on u3A->roe. +/* _raft_poke(): Peel one ovum off u3A->roe and poke Arvo with it. */ -static void +static u3_weak _raft_poke(void) { - if ( 0 == u3Z->lug_u.len_d ) { - return; - } - - c3_o bee_o = c3n; - u3_noun oer = u3_nul; u3_weak rus; - while ( u3_none != (rus = _raft_pop_roe()) ) { - u3_noun ovo, vir, sur; + // XX what is this condition? + // + if ( 0 == u3Z->lug_u.len_d ) { + fprintf(stderr, "_raft_poke ret early\r\n"); + return u3_none; + } - if ( c3n == bee_o ) { - u3_term_ef_blit(0, u3nc(u3nc(c3__bee, u3k(rus)), u3_nul)); - bee_o = c3y; - } + if ( u3_none != (rus = _raft_pop_roe()) ) { + u3_noun ovo, vir; + + u3_term_ef_blit(0, u3nc(u3nc(c3__bee, u3k(rus)), u3_nul)); u3x_cell(rus, &vir, &ovo); c3_assert( u3_nul == vir ); - - sur = _raft_punk(u3k(ovo)); + u3k(ovo); u3z(rus); - if ( u3_nul != sur) { - oer = u3nc(sur, oer); - } - } + rus = _raft_punk(ovo); - u3A->roe = oer; - - if ( c3y == bee_o ) { u3_term_ef_blit(0, u3nc(u3nc(c3__bee, u3_nul), u3_nul)); } + + return rus; } /* _raft_pump(): Cartify, jam, and save an ovum, then perform its effects. @@ -2053,7 +2045,32 @@ _raft_pump(u3_noun ovo, u3_noun vir) egg_u->vir = 0; } -/* u3_raft_work(): work. +/* u3_raft_chip(): chip one event off for processing. +*/ +void +u3_raft_chip(void) +{ + u3_weak rus = _raft_poke(); + + _raft_crop(); + + if ( u3_none != rus ) { + u3_noun ovo, vir; + u3x_cell(rus, &vir, &ovo); + + if ( u3_nul != ovo ) { + _raft_pump(u3k(ovo), u3k(vir)); + + // XX should be vir + // + _raft_grab(u3A->roe); + } + + u3z(rus); + } +} + +/* u3_raft_work(): work, either synchronously or asynchronously. */ void u3_raft_work(void) @@ -2067,30 +2084,12 @@ u3_raft_work(void) } } else { - // Delete finished events. + + // Cartify, jam, and encrypt this batch of events. + // Take a number, Raft will be with you shortly. // - _raft_crop(); - - // Poke pending events, leaving the poked events and errors on u3A->roe. - // - _raft_poke(); - - // Cartify, jam, and encrypt this batch of events. Take a number, Raft will - // be with you shortly. - { - u3_weak rus; - - while ( u3_none != (rus = _raft_pop_roe()) ) { - u3_noun ovo, vir; - u3x_cell(rus, &vir, &ovo); - - if ( u3_nul != ovo ) { - _raft_pump(u3k(ovo), u3k(vir)); - _raft_grab(u3A->roe); - } - - u3z(rus); - } + while ( u3_nul != u3A->roe ) { + u3_raft_chip(); } } } From d8b70683451ddfe25926ea6d368742118c2740b8 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 19 Dec 2017 07:22:02 -0800 Subject: [PATCH 67/90] updates u3_raft_work() to be async, adds sync u3_raft_play() --- include/vere/vere.h | 7 ++++++- vere/loop.c | 1 + vere/raft.c | 44 ++++++++++++++++++++++++++++---------------- vere/sist.c | 8 +++++--- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/include/vere/vere.h b/include/vere/vere.h index 9d81e4e830..fe54c6f3a1 100644 --- a/include/vere/vere.h +++ b/include/vere/vere.h @@ -1104,7 +1104,12 @@ void u3_raft_init(void); - /* u3_raft_work(): poke, kick, and push pending events. + /* u3_raft_play(): synchronously poke, kick, and push pending events. + */ + void + u3_raft_play(void); + + /* u3_raft_work(): asynchronously poke, kick, and push pending events. */ void u3_raft_work(void); diff --git a/vere/loop.c b/vere/loop.c index 59cc76f70a..a8f9a0bdd8 100644 --- a/vere/loop.c +++ b/vere/loop.c @@ -442,6 +442,7 @@ u3_lo_shut(c3_o inn) if ( c3n == u3_Host.liv ) { // direct save and die // + u3_raft_play(); // u3_lo_grab("lo_exit", u3_none); // u3_loom_save(u3A->ent_d); // u3_loom_exit(); diff --git a/vere/raft.c b/vere/raft.c index 3b4a005053..3149a22730 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -2070,26 +2070,38 @@ u3_raft_chip(void) } } -/* u3_raft_work(): work, either synchronously or asynchronously. +/* u3_raft_play(): synchronously process events. +*/ +void +u3_raft_play(void) +{ + c3_assert( u3Z->typ_e == u3_raty_lead ); + + u3_raft_chip(); + + if ( u3_nul != u3A->roe ) { + u3_raft_play(); + } +} + +/* _raft_work_cb(): callback to recurse into u3_raft_work(). +*/ +static void +_raft_work_cb(uv_timer_t* tim_u) +{ + u3_raft_work(); +} + +/* u3_raft_work(): asynchronously process events. */ void u3_raft_work(void) { - if ( u3Z->typ_e != u3_raty_lead ) { - c3_assert(u3A->ova.egg_p == 0); - if ( u3_nul != u3A->roe ) { - uL(fprintf(uH, "raft: dropping roe!!\n")); - u3z(u3A->roe); - u3A->roe = u3_nul; - } - } - else { + c3_assert( u3Z->typ_e == u3_raty_lead ); - // Cartify, jam, and encrypt this batch of events. - // Take a number, Raft will be with you shortly. - // - while ( u3_nul != u3A->roe ) { - u3_raft_chip(); - } + u3_raft_chip(); + + if ( u3_nul != u3A->roe ) { + uv_timer_start(&u3Z->tim_u, _raft_work_cb, 0, 0); } } diff --git a/vere/sist.c b/vere/sist.c index 75acb393aa..e14b5bdb1c 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -595,7 +595,8 @@ _sist_zest() } // Work through the boot events. - u3_raft_work(); + // + u3_raft_play(); } /* _sist_rest_nuu(): upgrade log from previous format. @@ -1223,8 +1224,9 @@ u3_sist_boot(void) u3C.wag_w |= u3o_hashless; } - // process pending events - u3_raft_work(); + // process pending events + // + u3_raft_play(); } else { u3_noun pig, who; From 594b059b620989f5cc3249ff0efc5d90aaa711b6 Mon Sep 17 00:00:00 2001 From: Isaac Visintainer Date: Tue, 11 Dec 2018 14:26:57 -0800 Subject: [PATCH 68/90] set alarm for behn timers --- vere/behn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vere/behn.c b/vere/behn.c index e934d26201..bb1021dbbb 100644 --- a/vere/behn.c +++ b/vere/behn.c @@ -77,7 +77,8 @@ u3_behn_ef_doze(u3_noun wen) u3_noun now = u3_time_in_tv(&tim_tv); c3_d gap_d = u3_time_gap_ms(now, u3k(u3t(wen))); - + + teh_u->alm = c3y; uv_timer_start(&teh_u->tim_u, _behn_time_cb, gap_d, 0); } From d23e55356fa01a9901dde8da3f70cf4b62de7077 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 7 Jun 2018 22:53:43 -0400 Subject: [PATCH 69/90] updates ames to always allocate 2K bytes on read --- vere/ames.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vere/ames.c b/vere/ames.c index a28e21e192..ad9094a790 100644 --- a/vere/ames.c +++ b/vere/ames.c @@ -30,8 +30,11 @@ _ames_alloc(uv_handle_t* had_u, uv_buf_t* buf ) { - void* ptr_v = c3_malloc(len_i); - *buf = uv_buf_init(ptr_v, len_i); + // we allocate 2K, which gives us plenty of space + // for a single ames packet (max size 1060 bytes) + // + void* ptr_v = c3_malloc(2048); + *buf = uv_buf_init(ptr_v, 2048); } /* _ames_free(): contrasting free. From 2f24bb1d1bbca704600d07774fc10eaf936df0be Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 7 Jun 2018 22:54:17 -0400 Subject: [PATCH 70/90] updates terminal to always 32 bytes on read --- vere/term.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vere/term.c b/vere/term.c index 3e2acef453..2c768002b0 100644 --- a/vere/term.c +++ b/vere/term.c @@ -41,14 +41,19 @@ _term_msc_out_host() return 1000000ULL * tim_tv.tv_sec + tim_tv.tv_usec; } +/* _term_alloc(): libuv buffer allocator. +*/ static void _term_alloc(uv_handle_t* had_u, size_t len_i, uv_buf_t* buf ) { - void* ptr_v = c3_malloc(len_i); - *buf = uv_buf_init(ptr_v, len_i); + // this read can range from a single byte to a paste buffer + // 32 bytes has been chosen heuristically + // + void* ptr_v = c3_malloc(32); + *buf = uv_buf_init(ptr_v, 32); } From 302704bd227c3c13f5387c1230f3d0500fc86c0a Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 11 Dec 2018 18:03:14 -0500 Subject: [PATCH 71/90] separates effects and persistence and always apply effects, even if the state didn't change --- vere/raft.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index 3149a22730..6c2778a21a 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1456,6 +1456,9 @@ _raft_sure(u3_noun ovo, u3_noun vir, u3_noun cor) u3r_mug(cor); u3r_mug(u3A->roc); + // XX review this, and confirm it's actually an optimization + // Seems like it could be very expensive in some cases + // if ( c3n == u3r_sing(cor, u3A->roc) ) { ret = u3nc(vir, ovo); @@ -1465,7 +1468,8 @@ _raft_sure(u3_noun ovo, u3_noun vir, u3_noun cor) else { u3z(ovo); - // push a new event into queue + // we return ~ in place of the event ovum to skip persistence + // ret = u3nc(vir, u3_nul); u3z(cor); @@ -1669,10 +1673,10 @@ _raft_push(u3_raft* raf_u, c3_w* bob_w, c3_w len_w) } -/* _raft_kick_all(): kick a list of events, transferring. +/* _raft_kick(): kick a list of effects, transferring. */ static void -_raft_kick_all(u3_noun vir) +_raft_kick(u3_noun vir) { while ( u3_nul != vir ) { u3_noun ovo = u3k(u3h(vir)); @@ -2001,10 +2005,10 @@ _raft_poke(void) return rus; } -/* _raft_pump(): Cartify, jam, and save an ovum, then perform its effects. +/* _raft_pump(): Cartify, jam, and save an ovum. */ static void -_raft_pump(u3_noun ovo, u3_noun vir) +_raft_pump(u3_noun ovo) { u3v_cart* egg_u = u3a_malloc(sizeof(*egg_u)); u3p(u3v_cart) egg_p = u3of(u3v_cart, egg_u); @@ -2016,7 +2020,7 @@ _raft_pump(u3_noun ovo, u3_noun vir) egg_u->nex_p = 0; egg_u->cit = c3n; egg_u->did = c3n; - egg_u->vir = vir; + egg_u->vir = 0; ron = u3ke_jam(u3nc(u3k(u3A->now), ovo)); c3_assert(u3A->key); @@ -2040,9 +2044,8 @@ _raft_pump(u3_noun ovo, u3_noun vir) u3to(u3v_cart, u3A->ova.geg_p)->nex_p = egg_p; u3A->ova.geg_p = egg_p; } - _raft_kick_all(vir); + egg_u->did = c3y; - egg_u->vir = 0; } /* u3_raft_chip(): chip one event off for processing. @@ -2059,13 +2062,12 @@ u3_raft_chip(void) u3x_cell(rus, &vir, &ovo); if ( u3_nul != ovo ) { - _raft_pump(u3k(ovo), u3k(vir)); - - // XX should be vir - // - _raft_grab(u3A->roe); + _raft_pump(u3k(ovo)); } + _raft_kick(u3k(vir)); + _raft_grab(vir); + u3z(rus); } } From d448340a76df9e070a3c233fd55a2329809123df Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 11 Dec 2018 18:17:13 -0500 Subject: [PATCH 72/90] adds and corrects some raft comments --- vere/raft.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index 6c2778a21a..e4134c29ad 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1952,7 +1952,10 @@ _raft_crop(void) } } -/* _raft_pop_roe(): pop the next [(list effects) event] pair of the queue +/* _raft_pop_roe(): pop the next [~ event] off the queue. +** +** effects are no longer stored on u3A->roe; the head of +** each pair is always null. */ static u3_weak _raft_pop_roe(void) @@ -1973,17 +1976,16 @@ _raft_pop_roe(void) return ovo; } -/* _raft_poke(): Peel one ovum off u3A->roe and poke Arvo with it. +/* _raft_poke(): poke Arvo with the next queued event. */ static u3_weak _raft_poke(void) { u3_weak rus; - // XX what is this condition? + // defer event processing until storage is initialized // if ( 0 == u3Z->lug_u.len_d ) { - fprintf(stderr, "_raft_poke ret early\r\n"); return u3_none; } From 918e1cb38f9166d11da281ca6a39d3dc8d713885 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 11 Dec 2018 18:42:38 -0800 Subject: [PATCH 73/90] trailing whitespace --- vere/behn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vere/behn.c b/vere/behn.c index bb1021dbbb..9d7bd8b2d4 100644 --- a/vere/behn.c +++ b/vere/behn.c @@ -77,7 +77,7 @@ u3_behn_ef_doze(u3_noun wen) u3_noun now = u3_time_in_tv(&tim_tv); c3_d gap_d = u3_time_gap_ms(now, u3k(u3t(wen))); - + teh_u->alm = c3y; uv_timer_start(&teh_u->tim_u, _behn_time_cb, gap_d, 0); } From dfecb3a1cb33f65209368a8ff56494163f631b0e Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 12 Dec 2018 00:37:56 -0500 Subject: [PATCH 74/90] refactors event poke, removing unnecessary effect traversal --- vere/raft.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index e4134c29ad..508dddb6da 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1601,38 +1601,26 @@ _raft_punk(u3_noun ovo) free(txt_c); #endif - if ( u3_blip != u3h(gon) ) { - u3_noun why = u3k(u3h(gon)); - u3_noun tan = u3k(u3t(gon)); + { + u3_noun hed, tal; + u3x_cell(gon, &hed, &tal); + u3k(hed); u3k(tal); u3z(gon); - return _raft_lame(ovo, why, tan); - } - else { - u3_noun vir = u3k(u3h(u3t(gon))); - u3_noun cor = u3k(u3t(u3t(gon))); - u3_noun nug; - u3z(gon); - nug = u3v_nick(vir, cor); - - if ( u3_blip != u3h(nug) ) { - u3_noun why = u3k(u3h(nug)); - u3_noun tan = u3k(u3t(nug)); - - u3z(nug); - return _raft_lame(ovo, why, tan); + if ( u3_blip != hed ) { + return _raft_lame(ovo, hed, tal); } else { - vir = u3k(u3h(u3t(nug))); - cor = u3k(u3t(u3t(nug))); + u3_noun vir, cor; + u3x_cell(tal, &vir, &cor); + + u3k(vir); u3k(cor); + u3z(tal); - u3z(nug); return _raft_sure(ovo, vir, cor); } } - // uL(fprintf(uH, "punk oot %s\n", txt_c)); - // free(txt_c); } /* _raft_push(): save an event From a848191c504082378d2ac2599a0ad6428b6936cc Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 12 Dec 2018 00:39:31 -0500 Subject: [PATCH 75/90] refactors event replay, removing unnecessary effect traversal --- vere/sist.c | 58 ++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/vere/sist.c b/vere/sist.c index e14b5bdb1c..f20b1d4b22 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -237,42 +237,42 @@ _sist_sing(u3_noun ovo) { u3_noun gon = u3m_soft(0, u3v_poke, u3k(ovo)); - if ( u3_blip != u3h(gon) ) { - _sist_suck(ovo, gon); - } - else { - u3_noun vir = u3k(u3h(u3t(gon))); - u3_noun cor = u3k(u3t(u3t(gon))); - u3_noun nug; + { + u3_noun hed, tal; + u3x_cell(gon, &hed, &tal); - u3z(gon); - nug = u3v_nick(vir, cor); - - if ( u3_blip != u3h(nug) ) { - _sist_suck(ovo, nug); + if ( u3_blip != hed ) { + _sist_suck(ovo, gon); } else { - vir = u3h(u3t(nug)); - cor = u3k(u3t(u3t(nug))); + u3_noun vir, cor; + u3x_cell(tal, &vir, &cor); - while ( u3_nul != vir ) { - u3_noun fex = u3h(vir); - u3_noun fav = u3t(fex); - - if ( c3__init == u3h(fav) ) { - u3A->own = u3k(u3t(fav)); - // note: c3__boot == u3h(u3t(ovo)) - u3A->fak = ( c3__fake == u3h(u3t(u3t(ovo))) ) ? c3y : c3n; - } - - vir = u3t(vir); - } - u3z(nug); u3z(u3A->roc); - u3A->roc = cor; + u3A->roc = u3k(cor); + + { + u3_noun tag, dat; + u3x_trel(ovo, 0, &tag, &dat); + + if ( c3__boot == tag ) { + while ( u3_nul != vir ) { + u3_noun fav = u3t(u3h(vir)); + + if ( c3__init == u3h(fav) ) { + u3A->own = u3k(u3t(fav)); + u3A->fak = ( c3__fake == u3h(tag) ) ? c3y : c3n; + } + + vir = u3t(vir); + } + } + } } - u3z(ovo); } + + u3z(gon); + u3z(ovo); } /* _sist_cask(): ask for a passcode. From f18d6cbc103e0457c8da9b21e48af023415b4d44 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 12 Dec 2018 00:40:04 -0500 Subject: [PATCH 76/90] removes unused u3v_nick (effect traversal) and u3v_http_request --- include/noun/vortex.h | 10 ------- noun/vortex.c | 67 ------------------------------------------- 2 files changed, 77 deletions(-) diff --git a/include/noun/vortex.h b/include/noun/vortex.h index d84dbf2c60..dfb7e8bae4 100644 --- a/include/noun/vortex.h +++ b/include/noun/vortex.h @@ -84,11 +84,6 @@ u3_noun u3v_pike(u3_noun ovo, u3_noun cor); - /* u3v_nick(): transform enveloped packets, [vir cor]. - */ - u3_noun - u3v_nick(u3_noun vir, u3_noun cor); - /* u3v_do(): use a kernel function. */ u3_noun @@ -119,11 +114,6 @@ u3_noun u3v_poke(u3_noun ovo); - /* u3v_http_request(): hear http request on channel (unprotected). - */ - void - u3v_http_request(c3_o sec, u3_noun pox, u3_noun req); - /* u3v_tank(): dump single tank. */ void diff --git a/noun/vortex.c b/noun/vortex.c index a23f95f30b..c40fd3fcf9 100644 --- a/noun/vortex.c +++ b/noun/vortex.c @@ -139,64 +139,6 @@ u3v_pike(u3_noun ovo, u3_noun cor) return _cv_mung(0, fun, sam); } -/* u3v_nick(): transform enveloped packets, [vir cor]. -*/ -u3_noun -u3v_nick(u3_noun vir, u3_noun cor) -{ - if ( u3_nul == vir ) { - return u3nt(u3_blip, vir, cor); - } - else { - u3_noun i_vir = u3h(vir); - u3_noun pi_vir, qi_vir; - u3_noun vix; - - if ( (c3y == u3r_cell(i_vir, &pi_vir, &qi_vir)) && - (c3y == u3du(qi_vir)) && - (c3__hear == u3h(qi_vir)) ) - { - u3_noun gon; - - gon = u3v_pike(u3k(i_vir), cor); - if ( u3_blip != u3h(gon) ) { - u3z(vir); - return gon; - } - else { - u3_noun viz; - - vix = u3k(u3h(u3t(gon))); - cor = u3k(u3t(u3t(gon))); - u3z(gon); - - viz = u3kb_weld(vix, u3k(u3t(vir))); - u3z(vir); - - return u3v_nick(viz, cor); - } - } - else { - u3_noun nez = u3v_nick(u3k(u3t(vir)), cor); - - if ( u3_blip != u3h(nez) ) { - u3z(vir); - return nez; - } else { - u3_noun viz; - - viz = u3nc(u3k(i_vir), u3k(u3h(u3t(nez)))); - cor = u3k(u3t(u3t(nez))); - - u3z(vir); - u3z(nez); - - return u3nt(u3_blip, viz, cor); - } - } - } -} - /* _cv_nock_poke(): call poke through hardcoded interface. */ static u3_noun @@ -374,15 +316,6 @@ u3v_poke(u3_noun ovo) return _cv_nock_poke(ovo); } -/* u3v_http_request(): hear http request on channel (unprotected). -*/ -void -u3v_http_request(c3_o sec, u3_noun pox, u3_noun req) -{ - // uL(fprintf(uH, "http: request\n")); - u3v_plan(pox, u3nq(c3__this, sec, 0, req)); -} - /* u3v_tank(): dump single tank. */ void From 62960bbc2882b745f8ad9c9efec9984e95d6de33 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 12 Dec 2018 01:19:34 -0500 Subject: [PATCH 77/90] enables event-log encryption --- vere/raft.c | 3 +-- vere/sist.c | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index e4134c29ad..a05e45a285 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -2026,8 +2026,7 @@ _raft_pump(u3_noun ovo) ron = u3ke_jam(u3nc(u3k(u3A->now), ovo)); c3_assert(u3A->key); - // don't encrypt for the moment, bootstrapping - // ron = u3dc("en:crua", u3k(u3A->key), ron); + ron = u3dc("en:crub:crypto", u3k(u3A->key), ron); len_w = u3r_met(5, ron); bob_w = c3_malloc(len_w * 4L); diff --git a/vere/sist.c b/vere/sist.c index e14b5bdb1c..898a3484b2 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -971,13 +971,10 @@ _sist_rest() continue; } -#if 0 - // disable encryption for now - // if ( u3A->key ) { u3_noun dep; - dep = u3dc("de:crua", u3k(u3A->key), ron); + dep = u3dc("de:crub:crypto", u3k(u3A->key), ron); if ( c3n == u3du(dep) ) { uL(fprintf(uH, "record (%s) is corrupt (k)\n", ful_c)); u3_lo_bail(); @@ -987,7 +984,7 @@ _sist_rest() u3z(dep); } } -#endif + roe = u3nc(u3ke_cue(ron), roe); } u3A->ent_d = c3_max(las_d + 1ULL, old_d); From 958e857476f755c1e2301de61224d8ba6cef1b02 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 12 Dec 2018 02:24:13 -0500 Subject: [PATCH 78/90] calls u3_raft_work on leader promotion (for eager restart effects) --- vere/raft.c | 1 + 1 file changed, 1 insertion(+) diff --git a/vere/raft.c b/vere/raft.c index e4134c29ad..5c0ec25e5a 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -179,6 +179,7 @@ _raft_promote(u3_raft* raf_u) u3_sist_boot(); if ( c3n == u3_Host.ops_u.bat ) { u3_lo_lead(); + u3_raft_work(); } } else { From 6b3c9f8dffc3c72a823d29c942db57251cb394a3 Mon Sep 17 00:00:00 2001 From: Joshua Reagan Date: Wed, 12 Dec 2018 18:19:54 -0800 Subject: [PATCH 79/90] fit UTF-8 tape bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You should be able to do this in dojo: ``` > "Some UTF-8: ἄλφα" "Some UTF-8: ἄλφα" ``` Now you can. @joemfb told me where to find the problem. --- vere/term.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vere/term.c b/vere/term.c index 2c768002b0..54cb0a222b 100644 --- a/vere/term.c +++ b/vere/term.c @@ -657,7 +657,7 @@ _term_io_suck_char(u3_utty* uty_u, c3_y cay_y) // uL(fprintf(uH, "muck-utf8 len %d\n", tat_u->fut.len_w)); // uL(fprintf(uH, "muck-utf8 %x\n", huv)); - wug = u3do("turf", huv); + wug = u3do("taft", huv); // uL(fprintf(uH, "muck-utf32 %x\n", tat_u->fut.len_w)); tat_u->fut.len_w = tat_u->fut.wid_w = 0; From aea2139261049d68470e452d24f3e8254fe4b094 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Wed, 12 Dec 2018 16:27:09 -0800 Subject: [PATCH 80/90] Add a jet for +del:by --- include/jets/w.h | 1 + jets/d/by_del.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++ jets/tree.c | 3 ++ meson.build | 1 + 4 files changed, 109 insertions(+) create mode 100644 jets/d/by_del.c diff --git a/include/jets/w.h b/include/jets/w.h index dae4c80eeb..65a7cef8d6 100644 --- a/include/jets/w.h +++ b/include/jets/w.h @@ -79,6 +79,7 @@ /** Tier 4. **/ u3_noun u3wdb_bif(u3_noun); + u3_noun u3wdb_del(u3_noun); u3_noun u3wdb_dif(u3_noun); u3_noun u3wdb_gas(u3_noun); u3_noun u3wdb_get(u3_noun); diff --git a/jets/d/by_del.c b/jets/d/by_del.c new file mode 100644 index 0000000000..ea87c1862f --- /dev/null +++ b/jets/d/by_del.c @@ -0,0 +1,104 @@ +/* j/4/by_del.c +** +*/ +#include "all.h" + +/* functions +*/ + static u3_noun + _rebalance(u3_noun a) + { + u3_noun l_a, n_a, r_a; + + if ( c3n == u3r_trel(a, &n_a, &l_a, &r_a) ) { + return u3m_bail(c3__exit); + } else { + if ( u3_nul == l_a) { + return u3k(r_a); + } else if ( u3_nul == r_a) { + return u3k(l_a); + } else { + u3_noun n_l_a, l_l_a, r_l_a; + u3_noun n_r_a, l_r_a, r_r_a; + + if ( (c3n == u3r_trel(l_a, &n_l_a, &l_l_a, &r_l_a) ) || + (c3n == u3r_trel(r_a, &n_r_a, &l_r_a, &r_r_a) ) || + (c3n == u3du(n_l_a)) || + (c3n == u3du(n_r_a)) ) { + return u3m_bail(c3__exit); + } else { + if ( c3y == u3qc_vor(u3h(n_l_a), u3h(n_r_a)) ) { + u3_noun new_right = u3nt(u3k(n_a), + u3k(r_l_a), + u3k(r_a)); + + u3_noun ret = u3nt(u3k(n_l_a), + u3k(l_l_a), + _rebalance(new_right)); + u3z(new_right); + + return ret; + } else { + u3_noun new_left = u3nt(u3k(n_a), + u3k(l_a), + u3k(l_r_a)); + + u3_noun ret = u3nt(u3k(n_r_a), + _rebalance(new_left), + u3k(r_r_a)); + u3z(new_left); + + return ret; + } + } + } + } + } + + u3_noun + u3qdb_del(u3_noun a, + u3_noun b) + { + if ( u3_nul == a ) { + return u3_nul; + } + else { + u3_noun l_a, n_a, r_a, pn_a, qn_a; + + if ( (c3n == u3r_trel(a, &n_a, &l_a, &r_a)) || + (c3n == u3r_cell(n_a, &pn_a, &qn_a)) ) + { + return u3m_bail(c3__exit); + } + else if ( c3n == u3r_sing(pn_a, b) ) { + if ( c3y == u3qc_gor(b, pn_a) ) { + return u3nt(u3k(n_a), + u3qdb_del(l_a, b), + u3k(r_a)); + } else { + return u3nt(u3k(n_a), + u3k(l_a), + u3qdb_del(r_a, b)); + } + } + else { + return _rebalance(a); + } + } + } + + u3_noun + u3wdb_del(u3_noun cor) + { + u3_noun a, b; + + if ( c3n == u3r_mean(cor, u3x_sam, &b, + u3x_con_sam, &a, 0) ) { + return u3m_bail(c3__exit); + } else { + u3_noun n = u3qdb_del(a, b); + return n; + } + } + + diff --git a/jets/tree.c b/jets/tree.c index 0bfe6cf7eb..c0da86ffd2 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -892,6 +892,8 @@ static c3_c* _141_two__in_ha[] = {0}; static u3j_harm _141_two__by_bif_a[] = {{".2", u3wdb_bif, c3y}, {}}; static c3_c* _141_two__by_bif_ha[] = {0}; + static u3j_harm _141_two__by_del_a[] = {{".2", u3wdb_del, c3y}, {}}; + static c3_c* _141_two__by_del_ha[] = {0}; static u3j_harm _141_two__by_dif_a[] = {{".2", u3wdb_dif, c3y}, {}}; static c3_c* _141_two__by_dif_ha[] = {0}; static u3j_harm _141_two__by_gas_a[] = {{".2", u3wdb_gas, c3y}, {}}; @@ -918,6 +920,7 @@ static c3_c* _141_two__in_ha[] = {0}; static u3j_core _141_two__by_d[] = { { "bif", 7, _141_two__by_bif_a, 0, _141_two__by_bif_ha }, + { "del", 7, _141_two__by_del_a, 0, _141_two__by_del_ha }, { "dif", 7, _141_two__by_dif_a, 0, _141_two__by_dif_ha }, { "gas", 7, _141_two__by_gas_a, 0, _141_two__by_gas_ha }, { "get", 7, _141_two__by_get_a, 0, _141_two__by_get_ha }, diff --git a/meson.build b/meson.build index d023d4adac..71b9029999 100644 --- a/meson.build +++ b/meson.build @@ -90,6 +90,7 @@ jets_d_src = [ 'jets/d/in_wyt.c', 'jets/d/in_bif.c', 'jets/d/in_dif.c', +'jets/d/by_del.c', 'jets/d/by_gas.c', 'jets/d/by_get.c', 'jets/d/by_has.c', From df40b0252f2e57e2a3844ffaa82bc3fa0983ef73 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Wed, 12 Dec 2018 16:45:38 -0800 Subject: [PATCH 81/90] [CI] Update arvo --- .travis/pin-arvo-commit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/pin-arvo-commit.txt b/.travis/pin-arvo-commit.txt index 9d21e4199e..a59368215f 100644 --- a/.travis/pin-arvo-commit.txt +++ b/.travis/pin-arvo-commit.txt @@ -1 +1 @@ -6a1f32bb1984fa9329c072de09ba67b212c8dbed +00c79de3df4ecae9f499053990471d420f0e79a0 From 6c1e20dcbd2828368ed1fec1c5602c820db1fd66 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Thu, 13 Dec 2018 11:29:36 -0800 Subject: [PATCH 82/90] Style nits --- jets/d/by_del.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/jets/d/by_del.c b/jets/d/by_del.c index ea87c1862f..90e11b37cf 100644 --- a/jets/d/by_del.c +++ b/jets/d/by_del.c @@ -12,12 +12,15 @@ if ( c3n == u3r_trel(a, &n_a, &l_a, &r_a) ) { return u3m_bail(c3__exit); - } else { + } + else { if ( u3_nul == l_a) { return u3k(r_a); - } else if ( u3_nul == r_a) { + } + else if ( u3_nul == r_a) { return u3k(l_a); - } else { + } + else { u3_noun n_l_a, l_l_a, r_l_a; u3_noun n_r_a, l_r_a, r_r_a; @@ -26,7 +29,8 @@ (c3n == u3du(n_l_a)) || (c3n == u3du(n_r_a)) ) { return u3m_bail(c3__exit); - } else { + } + else { if ( c3y == u3qc_vor(u3h(n_l_a), u3h(n_r_a)) ) { u3_noun new_right = u3nt(u3k(n_a), u3k(r_l_a), @@ -38,7 +42,8 @@ u3z(new_right); return ret; - } else { + } + else { u3_noun new_left = u3nt(u3k(n_a), u3k(l_a), u3k(l_r_a)); @@ -75,7 +80,8 @@ return u3nt(u3k(n_a), u3qdb_del(l_a, b), u3k(r_a)); - } else { + } + else { return u3nt(u3k(n_a), u3k(l_a), u3qdb_del(r_a, b)); @@ -95,7 +101,8 @@ if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) ) { return u3m_bail(c3__exit); - } else { + } + else { u3_noun n = u3qdb_del(a, b); return n; } From 5b55368c4a7a2159fb68e5a92411cb067e04dd99 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 13 Dec 2018 15:44:38 -0500 Subject: [PATCH 83/90] updates secp256k1 to include /usr/local/include for openbsd --- subprojects/secp256k1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subprojects/secp256k1 b/subprojects/secp256k1 index 9989e23ce8..87f73ffad3 160000 --- a/subprojects/secp256k1 +++ b/subprojects/secp256k1 @@ -1 +1 @@ -Subproject commit 9989e23ce8a02a51a1f90a2d5e391ba7d16bef39 +Subproject commit 87f73ffad3d3047baf1ed134fb7827a9dca163ee From a9f912cf0b76a425fff0f9d2dee6a89108a6509b Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 13 Dec 2018 15:49:02 -0500 Subject: [PATCH 84/90] removes preprocessor errors in trace.c on openbsd --- noun/trace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noun/trace.c b/noun/trace.c index af3b1a23d8..75e2ce1937 100644 --- a/noun/trace.c +++ b/noun/trace.c @@ -604,7 +604,7 @@ u3t_boot(void) setitimer(ITIMER_PROF, &itm_v, 0); } #elif defined(U3_OS_bsd) -# error "Profiling isn't yet supported on BSD" + // XX "Profiling isn't yet supported on BSD" #else # error "port: profiling" #endif @@ -644,7 +644,7 @@ u3t_boff(void) } #elif defined(U3_OS_bsd) -# error "Profiling isn't yet supported on BSD" + // XX "Profiling isn't yet supported on BSD" #else # error "port: profiling" #endif From 766e6e507e2e59e471e4f565b0fd2c870d20d986 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 13 Dec 2018 17:04:26 -0500 Subject: [PATCH 85/90] prevents profiling on *bsd --- vere/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vere/main.c b/vere/main.c index b4194433b7..e4a68695f4 100644 --- a/vere/main.c +++ b/vere/main.c @@ -186,6 +186,13 @@ _main_getopt(c3_i argc, c3_c** argv) } } +#if defined(U3_OS_bsd) + { + fprintf(stderr, "profiling isn't yet supported on BSD\r\n"); + return c3n; + } +#endif + if ( 0 != u3_Host.ops_u.fak_c ) { if ( 28 < strlen(u3_Host.ops_u.fak_c) ) { fprintf(stderr, "fake comets are disallowed\r\n"); From e25c8388a4658aea5a143b705c58d342ef1f2adb Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Thu, 13 Dec 2018 14:39:53 -0800 Subject: [PATCH 86/90] Add jet for +del:in --- include/jets/w.h | 1 + jets/d/in_del.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++ jets/tree.c | 3 ++ meson.build | 1 + 4 files changed, 110 insertions(+) create mode 100644 jets/d/in_del.c diff --git a/include/jets/w.h b/include/jets/w.h index 65a7cef8d6..0dd3d7f421 100644 --- a/include/jets/w.h +++ b/include/jets/w.h @@ -91,6 +91,7 @@ u3_noun u3wdb_uni(u3_noun); u3_noun u3wdi_bif(u3_noun); + u3_noun u3wdi_del(u3_noun); u3_noun u3wdi_dif(u3_noun); u3_noun u3wdi_gas(u3_noun); u3_noun u3wdi_has(u3_noun); diff --git a/jets/d/in_del.c b/jets/d/in_del.c new file mode 100644 index 0000000000..02390ccce8 --- /dev/null +++ b/jets/d/in_del.c @@ -0,0 +1,105 @@ +/* j/4/in_del.c +** +*/ +#include "all.h" + +/* functions +*/ + static u3_noun + _rebalance(u3_noun a) + { + u3_noun l_a, n_a, r_a; + + if ( c3n == u3r_trel(a, &n_a, &l_a, &r_a) ) { + return u3m_bail(c3__exit); + } + else { + if ( u3_nul == l_a) { + return u3k(r_a); + } + else if ( u3_nul == r_a) { + return u3k(l_a); + } + else { + u3_noun n_l_a, l_l_a, r_l_a; + u3_noun n_r_a, l_r_a, r_r_a; + + if ( (c3n == u3r_trel(l_a, &n_l_a, &l_l_a, &r_l_a) ) || + (c3n == u3r_trel(r_a, &n_r_a, &l_r_a, &r_r_a) ) ) { + return u3m_bail(c3__exit); + } + else { + if ( c3y == u3qc_vor(n_l_a, n_r_a) ) { + u3_noun new_right = u3nt(u3k(n_a), + u3k(r_l_a), + u3k(r_a)); + + u3_noun ret = u3nt(u3k(n_l_a), + u3k(l_l_a), + _rebalance(new_right)); + u3z(new_right); + + return ret; + } + else { + u3_noun new_left = u3nt(u3k(n_a), + u3k(l_a), + u3k(l_r_a)); + + u3_noun ret = u3nt(u3k(n_r_a), + _rebalance(new_left), + u3k(r_r_a)); + u3z(new_left); + + return ret; + } + } + } + } + } + + u3_noun + u3qdi_del(u3_noun a, + u3_noun b) + { + if ( u3_nul == a ) { + return u3_nul; + } + else { + u3_noun l_a, n_a, r_a; + + if ( (c3n == u3r_trel(a, &n_a, &l_a, &r_a)) ) { + return u3m_bail(c3__exit); + } + else if ( c3n == u3r_sing(n_a, b) ) { + if ( c3y == u3qc_hor(b, n_a) ) { + return u3nt(u3k(n_a), + u3qdi_del(l_a, b), + u3k(r_a)); + } + else { + return u3nt(u3k(n_a), + u3k(l_a), + u3qdi_del(r_a, b)); + } + } + else { + return _rebalance(a); + } + } + } + + u3_noun + u3wdi_del(u3_noun cor) + { + u3_noun a, b; + + if ( c3n == u3r_mean(cor, u3x_sam, &b, + u3x_con_sam, &a, 0) ) { + return u3m_bail(c3__exit); + } + else { + u3_noun n = u3qdi_del(a, b); + return n; + } + } diff --git a/jets/tree.c b/jets/tree.c index c0da86ffd2..b73f0110a2 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -854,6 +854,8 @@ static c3_c* _141_two_xeb_ha[] = {0}; static u3j_harm _141_two__in_bif_a[] = {{".2", u3wdi_bif}, {}}; static c3_c* _141_two__in_bif_ha[] = {0}; + static u3j_harm _141_two__in_del_a[] = {{".2", u3wdi_del}, {}}; + static c3_c* _141_two__in_del_ha[] = {0}; static u3j_harm _141_two__in_dif_a[] = {{".2", u3wdi_dif}, {}}; static c3_c* _141_two__in_dif_ha[] = {0}; static u3j_harm _141_two__in_gas_a[] = {{".2", u3wdi_gas}, {}}; @@ -877,6 +879,7 @@ static c3_c* _141_two_xeb_ha[] = {0}; static c3_c* _141_two__in_uni_ha[] = {0}; static u3j_core _141_two__in_d[] = { { "bif", 7, _141_two__in_bif_a, 0, _141_two__in_bif_ha }, + { "del", 7, _141_two__in_del_a, 0, _141_two__in_del_ha }, { "dif", 7, _141_two__in_dif_a, 0, _141_two__in_dif_ha }, { "gas", 7, _141_two__in_gas_a, 0, _141_two__in_gas_ha }, { "has", 7, _141_two__in_has_a, 0, _141_two__in_has_ha }, diff --git a/meson.build b/meson.build index 71b9029999..03c1b613ce 100644 --- a/meson.build +++ b/meson.build @@ -90,6 +90,7 @@ jets_d_src = [ 'jets/d/in_wyt.c', 'jets/d/in_bif.c', 'jets/d/in_dif.c', +'jets/d/in_del.c', 'jets/d/by_del.c', 'jets/d/by_gas.c', 'jets/d/by_get.c', From 7a172f68602216c817247b1dec8be2b94539e73d Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 13 Dec 2018 20:03:19 -0500 Subject: [PATCH 87/90] renames event-timing, adds build option to enable --- include/config.h.in | 1 + meson.build | 1 + meson_options.txt | 2 ++ noun/trace.c | 2 +- vere/raft.c | 6 +++--- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/config.h.in b/include/config.h.in index e8063e87ea..563cfa05ac 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -12,5 +12,6 @@ #mesondefine U3_MEMORY_DEBUG #mesondefine U3_CPU_DEBUG +#mesondefine U3_EVENT_TIME_DEBUG #endif /*CONFIG_H*/ diff --git a/meson.build b/meson.build index 869e48a62b..69aed91641 100644 --- a/meson.build +++ b/meson.build @@ -240,6 +240,7 @@ conf_data = configuration_data() conf_data.set('URBIT_VERSION', '"0.6.0"') conf_data.set('U3_MEMORY_DEBUG', get_option('gc')) conf_data.set('U3_CPU_DEBUG', get_option('prof')) +conf_data.set('U3_EVENT_TIME_DEBUG', get_option('event-time')) osdet = build_machine.system() os_c_flags = ['-funsigned-char','-ffast-math'] diff --git a/meson_options.txt b/meson_options.txt index 0785290ba9..b09e525d0b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,5 +2,7 @@ option('gc', type : 'boolean', value : false, description : 'Add debugging information to heap. Run with -g. Breaks image.') option('prof', type : 'boolean', value : false, description : 'Activate profiling. Run with -P.') +option('event-time', type : 'boolean', value : false, + description : 'Print timing information per event.') option('nix', type: 'boolean', value: false, description: 'Build using nix.') diff --git a/noun/trace.c b/noun/trace.c index 480061a306..ef5a171ffb 100644 --- a/noun/trace.c +++ b/noun/trace.c @@ -45,7 +45,7 @@ u3_lo_tank(c3_l tab_l, u3_noun tac); void u3t_slog(u3_noun hod) { -#ifdef GHETTO +#ifdef U3_EVENT_TIME_DEBUG static int old; static struct timeval b4, f2, d0; c3_w ms_w; diff --git a/vere/raft.c b/vere/raft.c index 12f2afeb30..ee8dade84e 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1559,7 +1559,7 @@ _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) static u3_noun _raft_punk(u3_noun ovo) { -#ifdef GHETTO +#ifdef U3_EVENT_TIME_DEBUG c3_c* txt_c = u3r_string(u3h(u3t(ovo))); #endif c3_w sec_w; @@ -1574,7 +1574,7 @@ _raft_punk(u3_noun ovo) sec_w = 0; } else sec_w = 600; -#ifdef GHETTO +#ifdef U3_EVENT_TIME_DEBUG struct timeval b4, f2, d0; gettimeofday(&b4, 0); if( c3__belt != u3h(u3t(ovo)) ){ @@ -1587,7 +1587,7 @@ _raft_punk(u3_noun ovo) gon = u3m_soft(sec_w, u3v_poke, u3k(ovo)); u3t_event_trace("Running", 'e'); -#ifdef GHETTO +#ifdef U3_EVENT_TIME_DEBUG c3_w ms_w; c3_w clr_w; From 916223326cd40e73a276e4d8dc7bd2bb35236c7f Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 13 Dec 2018 23:26:17 -0500 Subject: [PATCH 88/90] don't abort on bail:fail, but continue with crash handling --- noun/manage.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/noun/manage.c b/noun/manage.c index 94ba35f3ea..7d3517da33 100644 --- a/noun/manage.c +++ b/noun/manage.c @@ -625,14 +625,15 @@ u3m_bail(u3_noun how) } else { c3_assert(_(u3ud(u3h(how)))); - fprintf(stderr, "\r\nbail: %d\r\n", u3h(how)); - u3m_p("bail", u3t(how)); } } switch ( how ) { - case c3__fail: + case c3__fail: { + break; + } + case c3__meme: { fprintf(stderr, "bailing out\r\n"); abort(); From 69f41575887eecb7a8bad7924ac8d0e058bab89a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= <_@wholezero.org> Date: Fri, 14 Dec 2018 22:49:05 +0000 Subject: [PATCH 89/90] Fixes the build on OpenBSD Tested with stock clang on an OpenBSD 6.4 amd64 VM. Unfortunately clang (and also gcc from ports) was not pleased about c3_rand, whereas this was fine before. I have no idea what changed, but it works now. --- include/c/portable.h | 7 +------ meson.build | 2 +- vere/sist.c | 6 ++++++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/c/portable.h b/include/c/portable.h index 650dff24dc..7595921a91 100644 --- a/include/c/portable.h +++ b/include/c/portable.h @@ -188,12 +188,7 @@ /* Entropy */ -# if defined(U3_OS_bsd) && defined(__OpenBSD__) -# define c3_rand(rd) (getentropy((void*)rd, 64) == 0 ? \ - (void)0 : c3_assert(!"ent")) -# else -# define c3_rand u3_sist_rand -# endif +#define c3_rand u3_sist_rand /* Static assertion */ diff --git a/meson.build b/meson.build index 69aed91641..e1da8d14e1 100644 --- a/meson.build +++ b/meson.build @@ -282,7 +282,7 @@ elif osdet == 'bsd' or osdet == 'freebsd' elif osdet == 'openbsd' conf_data.set('U3_OS_bsd', true) - os_link_flags = ['-L /usr/local/lib', '-lgmp', '-lsigsegv', '-lcurses'] + os_link_flags = ['-L/usr/local/lib', '-lgmp', '-lsigsegv', '-lcurses'] gmp_dep = [] sigsegv_dep = [] diff --git a/vere/sist.c b/vere/sist.c index 75b572ba62..cbfa17f322 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -415,12 +415,18 @@ _sist_bask(c3_c* pop_c, u3_noun may) void u3_sist_rand(c3_w* rad_w) { +#if defined(U3_OS_bsd) && defined(__OpenBSD__) + if (-1 == getentropy(rad_w, 64)) { + c3_assert(!"lo_rand"); + } +#else c3_i fid_i = open(DEVRANDOM, O_RDONLY); if ( 64 != read(fid_i, (c3_y*) rad_w, 64) ) { c3_assert(!"lo_rand"); } close(fid_i); +#endif } /* _sist_fast(): offer to save passcode by mug in home directory. From 830c0715f893a89b6818d3e683875a95fd44c6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= <_@wholezero.org> Date: Fri, 14 Dec 2018 23:04:38 +0000 Subject: [PATCH 90/90] Only bail if profiling is enabled --- vere/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vere/main.c b/vere/main.c index e4a68695f4..9aebe6fef9 100644 --- a/vere/main.c +++ b/vere/main.c @@ -187,7 +187,7 @@ _main_getopt(c3_i argc, c3_c** argv) } #if defined(U3_OS_bsd) - { + if (u3_Host.ops_u.pro == c3y) { fprintf(stderr, "profiling isn't yet supported on BSD\r\n"); return c3n; }