From 39a82fe66d8e97e3517077387499515924ebdc83 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Tue, 15 Sep 2020 13:50:22 -0700 Subject: [PATCH] ur: updates api to consistently use (len, bytes) for vectors --- pkg/urbit/include/ur/defs.h | 2 +- pkg/urbit/include/ur/hashcons.h | 4 ++-- pkg/urbit/noun/urth.c | 4 ++-- pkg/urbit/tests/ur_tests.c | 4 ++-- pkg/urbit/ur/hashcons.c | 18 +++++++++--------- pkg/urbit/ur/serial.c | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pkg/urbit/include/ur/defs.h b/pkg/urbit/include/ur/defs.h index d3b1c6ebf..c5cf411c1 100644 --- a/pkg/urbit/include/ur/defs.h +++ b/pkg/urbit/include/ur/defs.h @@ -64,7 +64,7 @@ typedef uint8_t ur_bool_t; ** unsafe wrt trailing null bytes, which are invalid */ inline uint64_t -ur_met0_bytes_unsafe(uint8_t *byt, uint64_t len) +ur_met0_bytes_unsafe(uint64_t len, uint8_t *byt) { uint64_t last = len - 1; return (last << 3) + ur_met0_8(byt[last]); diff --git a/pkg/urbit/include/ur/hashcons.h b/pkg/urbit/include/ur/hashcons.h index 045d5055a..c8a8e4ba5 100644 --- a/pkg/urbit/include/ur/hashcons.h +++ b/pkg/urbit/include/ur/hashcons.h @@ -174,10 +174,10 @@ ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref); ** allocated with system malloc) and trailing null bytes (not allowed). */ ur_nref -ur_coin_bytes_unsafe(ur_root_t *r, uint8_t *byt, uint64_t len); +ur_coin_bytes_unsafe(ur_root_t *r, uint64_t len, uint8_t *byt); ur_nref -ur_coin_bytes(ur_root_t *r, uint8_t *byt, uint64_t len); +ur_coin_bytes(ur_root_t *r, uint64_t len, uint8_t *byt); ur_nref ur_coin64(ur_root_t *r, uint64_t n); diff --git a/pkg/urbit/noun/urth.c b/pkg/urbit/noun/urth.c index 82f052d1d..876e2d5dc 100644 --- a/pkg/urbit/noun/urth.c +++ b/pkg/urbit/noun/urth.c @@ -57,10 +57,10 @@ _cu_atom_to_ref(ur_root_t* rot_u, u3a_atom* vat_u) c3_assert( len_d ); - // NB: this call will accounts for any trailing null bytes + // NB: this call will account for any trailing null bytes // caused by an overestimate in [len_d] // - ref = ur_coin_bytes(rot_u, byt_y, len_d); + ref = ur_coin_bytes(rot_u, len_d, byt_y); } break; } diff --git a/pkg/urbit/tests/ur_tests.c b/pkg/urbit/tests/ur_tests.c index 8859966ee..56e8f2dc1 100644 --- a/pkg/urbit/tests/ur_tests.c +++ b/pkg/urbit/tests/ur_tests.c @@ -1810,13 +1810,13 @@ _test_jam_cue(void) { uint8_t inp[33] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }; uint8_t res[35] = { 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 }; - TEST_CASE("wide", ur_coin_bytes(r, inp, sizeof(inp))); + TEST_CASE("wide", ur_coin_bytes(r, sizeof(inp), inp)); } { uint8_t inp[16] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc, 0xa8, 0xab, 0x60, 0xef, 0x2d, 0xd, 0x0, 0x0, 0x80 }; uint8_t res[19] = { 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0x50, 0x57, 0xc1, 0xde, 0x5b, 0x1a, 0x0, 0x0, 0x0, 0x1 }; - TEST_CASE("date", ur_coin_bytes(r, inp, sizeof(inp))); + TEST_CASE("date", ur_coin_bytes(r, sizeof(inp), inp)); } ur_root_free(r); diff --git a/pkg/urbit/ur/hashcons.c b/pkg/urbit/ur/hashcons.c index a08de0311..756c92f6d 100644 --- a/pkg/urbit/ur/hashcons.c +++ b/pkg/urbit/ur/hashcons.c @@ -15,7 +15,7 @@ // declarations of inline functions // uint64_t -ur_met0_bytes_unsafe(uint8_t *byt, uint64_t len); +ur_met0_bytes_unsafe(uint64_t len, uint8_t *byt); static void* _oom(const char* cap, void* v) @@ -543,7 +543,7 @@ ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref) uint64_t len = r->atoms.lens[idx]; uint8_t *byt = r->atoms.bytes[idx]; - m_bit = ur_met0_bytes_unsafe(byt, len); + m_bit = ur_met0_bytes_unsafe(len, byt); } switch ( bloq ) { @@ -568,7 +568,7 @@ ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref) } static ur_nref -_coin_unsafe(ur_atoms_t *atoms, ur_mug mug, uint8_t *byt, uint64_t len) +_coin_unsafe(ur_atoms_t *atoms, ur_mug mug, uint64_t len, uint8_t *byt) { uint64_t fill = atoms->fill; ur_tag tag = ur_iatom; @@ -606,7 +606,7 @@ _cons_unsafe(ur_cells_t *cells, ur_mug mug, ur_nref hed, ur_nref tal) } ur_nref -ur_coin_bytes_unsafe(ur_root_t *r, uint8_t *byt, uint64_t len) +ur_coin_bytes_unsafe(ur_root_t *r, uint64_t len, uint8_t *byt) { ur_atoms_t *atoms = &(r->atoms); ur_dict_t *dict = &(atoms->dict); @@ -641,7 +641,7 @@ ur_coin_bytes_unsafe(ur_root_t *r, uint8_t *byt, uint64_t len) ur_atoms_grow(atoms); } - tom = _coin_unsafe(atoms, mug, byt, len); + tom = _coin_unsafe(atoms, mug, len, byt); bucket->refs[b_fill] = tom; bucket->fill = 1 + b_fill; @@ -651,7 +651,7 @@ ur_coin_bytes_unsafe(ur_root_t *r, uint8_t *byt, uint64_t len) } ur_nref -ur_coin_bytes(ur_root_t *r, uint8_t *byt, uint64_t len) +ur_coin_bytes(ur_root_t *r, uint64_t len, uint8_t *byt) { // strip trailing zeroes // @@ -661,7 +661,7 @@ ur_coin_bytes(ur_root_t *r, uint8_t *byt, uint64_t len) // produce a direct atom if possible // - if ( 62 >= ur_met0_bytes_unsafe(byt, len) ) { + if ( 62 >= ur_met0_bytes_unsafe(len, byt) ) { uint64_t i, direct = 0; for ( i = 0; i < len; i++ ) { @@ -674,7 +674,7 @@ ur_coin_bytes(ur_root_t *r, uint8_t *byt, uint64_t len) uint8_t *copy = _oom("coin_bytes", malloc(len)); memcpy(copy, byt, len); - return ur_coin_bytes_unsafe(r, copy, len); + return ur_coin_bytes_unsafe(r, len, copy); } } @@ -699,7 +699,7 @@ ur_coin64(ur_root_t *r, uint64_t n) byt[6] = ur_mask_8(n >> 48); byt[7] = ur_mask_8(n >> 56); - return ur_coin_bytes_unsafe(r, byt, 8); + return ur_coin_bytes_unsafe(r, 8, byt); } } diff --git a/pkg/urbit/ur/serial.c b/pkg/urbit/ur/serial.c index 83610c12b..a2d111e91 100644 --- a/pkg/urbit/ur/serial.c +++ b/pkg/urbit/ur/serial.c @@ -214,7 +214,7 @@ _cue_next(ur_root_t *r, len_byt--; } - *out = ur_coin_bytes_unsafe(r, byt, len_byt); + *out = ur_coin_bytes_unsafe(r, len_byt, byt); } ur_dict64_put(r, dict, bits, (uint64_t)*out);