Skip to content

Commit

Permalink
Rename c3_assert() as u3_assert()
Browse files Browse the repository at this point in the history
  • Loading branch information
mcevoypeter committed Apr 25, 2023
1 parent f66ba84 commit fe45997
Show file tree
Hide file tree
Showing 45 changed files with 443 additions and 443 deletions.
8 changes: 4 additions & 4 deletions doc/spec/u3.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,12 @@ at the global level, and will leave them in an inconsistent state
if your inner road gets terminated. (Instead, use our drop-in
replacements, `u3a_malloc()`, `u3a_free()`, `u3a_realloc()`.)

A good example is the different meaning of `c3_assert()` inside
A good example is the different meaning of `u3_assert()` inside
and outside the interpreter. At either layer, you can use
regular assert(), which will just kill your process. On the
surface, `c3_assert()` will just... kill your process.
surface, `u3_assert()` will just... kill your process.

In deep execution, `c3_assert()` will issue an exception that
In deep execution, `u3_assert()` will issue an exception that
queues an error event, complete with trace stack, on the Arvo
event queue. Let's see how this happens.

Expand Down Expand Up @@ -544,7 +544,7 @@ on the main thread.
There are also two kinds of exception: mild and severe. An
external exception is always severe. An internal exception is
normally mild, but some (like `c3__oops`, generated by
`c3_assert()`) are severe.
`u3_assert()`) are severe.

Either way, exceptions come with a stack trace. The `u3` nock
interpreter is instrumented to retain stack trace hints and
Expand Down
16 changes: 8 additions & 8 deletions pkg/c3/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
**/
/* Assert. Good to capture.
TODO: determine which c3_assert calls can rather call c3_dessert, i.e. in
public releases, which calls to c3_assert should abort and which should
TODO: determine which u3_assert calls can rather call c3_dessert, i.e. in
public releases, which calls to u3_assert should abort and which should
no-op? If the latter, is the assert useful inter-development to validate
conditions we might accidentally break or not useful at all?
*/

# if defined(ASAN_ENABLED) && defined(__clang__)
# define c3_assert(x) \
# define u3_assert(x) \
do { \
if (!(x)) { \
assert(x); \
} \
} while(0)
# else
# define c3_assert(x) \
# define u3_assert(x) \
do { \
if (!(x)) { \
fflush(stderr); \
Expand Down Expand Up @@ -71,7 +71,7 @@

/* Stub.
*/
# define c3_stub c3_assert(!"stub")
# define c3_stub u3_assert(!"stub")

/* Size in words.
*/
Expand Down Expand Up @@ -137,23 +137,23 @@
if ( 0 == rut ) { \
fprintf(stderr, "c3_malloc(%" PRIu64 ") failed\r\n", \
(c3_d)s); \
c3_assert(!"memory lost"); \
u3_assert(!"memory lost"); \
} \
rut;})
# define c3_calloc(s) ({ \
void* rut = calloc(1,s); \
if ( 0 == rut ) { \
fprintf(stderr, "c3_calloc(%" PRIu64 ") failed\r\n", \
(c3_d)s); \
c3_assert(!"memory lost"); \
u3_assert(!"memory lost"); \
} \
rut;})
# define c3_realloc(a, b) ({ \
void* rut = realloc(a, b); \
if ( 0 == rut ) { \
fprintf(stderr, "c3_realloc(%" PRIu64 ") failed\r\n", \
(c3_d)b); \
c3_assert(!"memory lost"); \
u3_assert(!"memory lost"); \
} \
rut;})

Expand Down
80 changes: 40 additions & 40 deletions pkg/noun/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ _box_make(void* box_v, c3_w siz_w, c3_w use_w)
u3a_box* box_u = box_v;
c3_w* box_w = box_v;

c3_assert(siz_w >= u3a_minimum);
u3_assert(siz_w >= u3a_minimum);

box_u->siz_w = siz_w;
box_w[siz_w - 1] = siz_w; /* stor size at end of allocation as well */
Expand All @@ -132,8 +132,8 @@ _box_make(void* box_v, c3_w siz_w, c3_w use_w)
static void
_box_attach(u3a_box* box_u)
{
c3_assert(box_u->siz_w >= (1 + c3_wiseof(u3a_fbox)));
c3_assert(0 != u3of(u3a_fbox, box_u));
u3_assert(box_u->siz_w >= (1 + c3_wiseof(u3a_fbox)));
u3_assert(0 != u3of(u3a_fbox, box_u));

#if 0
// For debugging, fill the box with beef.
Expand Down Expand Up @@ -176,21 +176,21 @@ _box_detach(u3a_box* box_u)

if ( nex_p ) {
if ( u3to(u3a_fbox, nex_p)->pre_p != fre_p ) {
c3_assert(!"loom: corrupt");
u3_assert(!"loom: corrupt");
}
u3to(u3a_fbox, nex_p)->pre_p = pre_p;
}
if ( pre_p ) {
if( u3to(u3a_fbox, pre_p)->nex_p != fre_p ) {
c3_assert(!"loom: corrupt");
u3_assert(!"loom: corrupt");
}
u3to(u3a_fbox, pre_p)->nex_p = nex_p;
}
else {
c3_w sel_w = _box_slot(box_u->siz_w);

if ( fre_p != u3R->all.fre_p[sel_w] ) {
c3_assert(!"loom: corrupt");
u3_assert(!"loom: corrupt");
}
u3R->all.fre_p[sel_w] = nex_p;
}
Expand All @@ -203,7 +203,7 @@ _box_free(u3a_box* box_u)
{
c3_w* box_w = (c3_w *)(void *)box_u;

c3_assert(box_u->use_w != 0);
u3_assert(box_u->use_w != 0);
box_u->use_w -= 1;
if ( 0 != box_u->use_w ) {
return;
Expand Down Expand Up @@ -378,13 +378,13 @@ u3a_sane(void)

while ( fre_u ) {
if ( fre_u == u3R->all.fre_u[i_w] ) {
c3_assert(fre_u->pre_u == 0);
u3_assert(fre_u->pre_u == 0);
}
else {
c3_assert(fre_u->pre_u != 0);
c3_assert(fre_u->pre_u->nex_u == fre_u);
u3_assert(fre_u->pre_u != 0);
u3_assert(fre_u->pre_u->nex_u == fre_u);
if ( fre_u->nex_u != 0 ) {
c3_assert(fre_u->nex_u->pre_u == fre_u);
u3_assert(fre_u->nex_u->pre_u == fre_u);
}
}
fre_u = fre_u->nex_u;
Expand Down Expand Up @@ -536,14 +536,14 @@ _ca_willoc(c3_w len_w, c3_w ald_w, c3_w off_w)
(u3to(u3a_fbox, u3to(u3a_fbox, *pfr_p)->pre_p)->nex_p
!= (*pfr_p)) )
{ /* this->pre->nex isn't this */
c3_assert(!"loom: corrupt");
u3_assert(!"loom: corrupt");
}

if( (0 != u3to(u3a_fbox, *pfr_p)->nex_p) &&
(u3to(u3a_fbox, u3to(u3a_fbox, *pfr_p)->nex_p)->pre_p
!= (*pfr_p)) )
{ /* this->nex->pre isn't this */
c3_assert(!"loom: corrupt");
u3_assert(!"loom: corrupt");
}

/* pop the block */
Expand Down Expand Up @@ -575,7 +575,7 @@ _ca_willoc(c3_w len_w, c3_w ald_w, c3_w off_w)
return u3a_boxto(_box_make(box_w, des_w, 1));
}
else {
c3_assert(0 == box_u->use_w);
u3_assert(0 == box_u->use_w);
box_u->use_w = 1;

#ifdef U3_MEMORY_DEBUG
Expand Down Expand Up @@ -738,7 +738,7 @@ u3a_calloc(size_t num_i, size_t len_i)
size_t byt_i = num_i * len_i;
c3_w* out_w;

c3_assert(byt_i / len_i == num_i);
u3_assert(byt_i / len_i == num_i);
out_w = u3a_malloc(byt_i);
memset(out_w, 0, byt_i);

Expand Down Expand Up @@ -981,8 +981,8 @@ _me_wash_north_in(u3_noun som)
static void
_me_wash_north(u3_noun dog)
{
c3_assert(c3y == u3a_is_dog(dog));
// c3_assert(c3y == u3a_north_is_junior(u3R, dog));
u3_assert(c3y == u3a_is_dog(dog));
// u3_assert(c3y == u3a_north_is_junior(u3R, dog));
{
u3a_noun* dog_u = u3a_to_ptr(dog);

Expand Down Expand Up @@ -1014,8 +1014,8 @@ _me_wash_south_in(u3_noun som)
static void
_me_wash_south(u3_noun dog)
{
c3_assert(c3y == u3a_is_dog(dog));
// c3_assert(c3y == u3a_south_is_junior(u3R, dog));
u3_assert(c3y == u3a_is_dog(dog));
// u3_assert(c3y == u3a_south_is_junior(u3R, dog));
{
u3a_noun* dog_u = u3a_to_ptr(dog);

Expand Down Expand Up @@ -1185,7 +1185,7 @@ _ca_take_next_north(u3a_pile* pil_u, u3_noun veb)
if ( veb_u->mug_w >> 31 ) {
u3_noun nov = (u3_noun)veb_u->mug_w;

c3_assert( c3y == u3a_north_is_normal(u3R, nov) );
u3_assert( c3y == u3a_north_is_normal(u3R, nov) );

#ifdef VERBOSE_TAKE
u3l_log("north: %p is already %p", veb_u, u3a_to_ptr(nov));
Expand Down Expand Up @@ -1240,7 +1240,7 @@ _ca_take_next_south(u3a_pile* pil_u, u3_noun veb)
if ( veb_u->mug_w >> 31 ) {
u3_noun nov = (u3_noun)veb_u->mug_w;

c3_assert( c3y == u3a_south_is_normal(u3R, nov) );
u3_assert( c3y == u3a_south_is_normal(u3R, nov) );

#ifdef VERBOSE_TAKE
u3l_log("south: %p is already %p", veb_u, u3a_to_ptr(nov));
Expand Down Expand Up @@ -1355,7 +1355,7 @@ u3a_take(u3_noun veb)
u3_noun pro;
u3t_on(coy_o);

c3_assert(u3_none != veb);
u3_assert(u3_none != veb);

pro = ( c3y == u3a_is_north(u3R) )
? _ca_take_north(veb)
Expand Down Expand Up @@ -1395,7 +1395,7 @@ _me_gain_north(u3_noun dog)
else {
/* junior nouns are disallowed
*/
c3_assert(!_(u3a_north_is_junior(u3R, dog)));
u3_assert(!_(u3a_north_is_junior(u3R, dog)));

/* normal pointers are refcounted
*/
Expand All @@ -1417,7 +1417,7 @@ _me_gain_south(u3_noun dog)
else {
/* junior nouns are disallowed
*/
c3_assert(!_(u3a_south_is_junior(u3R, dog)));
u3_assert(!_(u3a_south_is_junior(u3R, dog)));

/* normal nouns are refcounted
*/
Expand Down Expand Up @@ -1512,7 +1512,7 @@ u3_noun
u3a_gain(u3_noun som)
{
u3t_on(mal_o);
c3_assert(u3_none != som);
u3_assert(u3_none != som);

if ( !_(u3a_is_cat(som)) ) {
som = _(u3a_is_north(u3R))
Expand Down Expand Up @@ -1711,7 +1711,7 @@ u3a_mark_ptr(void* ptr_v)
siz_w = 0;
}
else {
c3_assert(use_ws != 0);
u3_assert(use_ws != 0);

if ( 0x80000000 == (c3_w)use_ws ) { // see _raft_prof()
use_ws = -1;
Expand Down Expand Up @@ -1839,7 +1839,7 @@ u3a_count_ptr(void* ptr_v)
siz_w = 0;
}
else {
c3_assert(use_ws != 0);
u3_assert(use_ws != 0);

if ( use_ws < 0 ) {
siz_w = 0;
Expand Down Expand Up @@ -1913,7 +1913,7 @@ u3a_discount_ptr(void* ptr_v)
siz_w = 0;
}
else {
c3_assert(use_ws != 0);
u3_assert(use_ws != 0);

if ( use_ws < 0 ) {
use_ws = -use_ws;
Expand Down Expand Up @@ -1963,7 +1963,7 @@ u3a_discount_noun(u3_noun som)
void
u3a_print_time(c3_c* str_c, c3_c* cap_c, c3_d mic_d)
{
c3_assert( 0 != str_c );
u3_assert( 0 != str_c );

c3_w sec_w = (mic_d / 1000000);
c3_w mec_w = (mic_d % 1000000) / 1000;
Expand All @@ -1985,7 +1985,7 @@ u3a_print_time(c3_c* str_c, c3_c* cap_c, c3_d mic_d)
void
u3a_print_memory(FILE* fil_u, c3_c* cap_c, c3_w wor_w)
{
c3_assert( 0 != fil_u );
u3_assert( 0 != fil_u );

c3_z byt_z = ((c3_z)wor_w * 4);
c3_z gib_z = (byt_z / 1000000000);
Expand Down Expand Up @@ -2318,8 +2318,8 @@ u3a_sweep(void)
u3a_print_memory(stderr, "leaked", leq_w);
u3a_print_memory(stderr, "weaked", weq_w);

c3_assert( (pos_w + leq_w + weq_w) == neg_w );
c3_assert( (0 == leq_w) && (0 == weq_w) );
u3_assert( (pos_w + leq_w + weq_w) == neg_w );
u3_assert( (0 == leq_w) && (0 == weq_w) );

return neg_w;
}
Expand Down Expand Up @@ -2408,7 +2408,7 @@ _ca_pack_move_north(c3_w* box_w, c3_w* end_w, u3_post new_p)
if ( old_u->use_w ) {
c3_w* new_w = (void*)u3a_botox(u3a_into(new_p));

c3_assert( box_w[siz_w - 1] == new_p );
u3_assert( box_w[siz_w - 1] == new_p );

// note: includes leading size
//
Expand All @@ -2420,7 +2420,7 @@ _ca_pack_move_north(c3_w* box_w, c3_w* end_w, u3_post new_p)
}
}
else {
c3_assert( new_w == box_w );
u3_assert( new_w == box_w );
}

// restore trailing size
Expand Down Expand Up @@ -2464,7 +2464,7 @@ _ca_pack_move_south(c3_w* box_w, c3_w* end_w, u3_post new_p)
if ( old_u->use_w ) {
c3_w* new_w = (void*)u3a_botox(u3a_into(new_p));

c3_assert( old_u->siz_w == new_p );
u3_assert( old_u->siz_w == new_p );

// note: includes trailing size
//
Expand All @@ -2476,7 +2476,7 @@ _ca_pack_move_south(c3_w* box_w, c3_w* end_w, u3_post new_p)
}
}
else {
c3_assert( new_w == box_w );
u3_assert( new_w == box_w );
}

// restore leading size
Expand All @@ -2500,7 +2500,7 @@ _ca_pack_move_south(c3_w* box_w, c3_w* end_w, u3_post new_p)
}
}
else {
c3_assert( end_w == box_w );
u3_assert( end_w == box_w );
break;
}
}
Expand Down Expand Up @@ -2734,11 +2734,11 @@ u3a_loom_sane()
u3a_fbox *pre_u = u3to(u3a_fbox, this_u->pre_p)
, *nex_u = u3to(u3a_fbox, this_u->nex_p);

if (nex_p && nex_u->pre_p != this_p) c3_assert(!"loom: wack");
if (pre_p && pre_u->nex_p != this_p) c3_assert(!"loom: wack");
if (nex_p && nex_u->pre_p != this_p) u3_assert(!"loom: wack");
if (pre_p && pre_u->nex_p != this_p) u3_assert(!"loom: wack");
if (!pre_p /* this must be the head of a freelist */
&& u3R->all.fre_p[_box_slot(this_u->box_u.siz_w)] != this_p)
c3_assert(!"loom: wack");
u3_assert(!"loom: wack");
}
}
}
Loading

0 comments on commit fe45997

Please sign in to comment.