Skip to content

Commit

Permalink
Properly set eqtable signatures to jl_value_t* rather than void*
Browse files Browse the repository at this point in the history
Of course this doesn't currently make any difference to the generated
code, but we have a few tools that parse the C source to perform additional
analysis (e.g. the GC root analyzer), that rely on tracked pointers having
a GC-tracked type for proper functioning, so switch that over.
  • Loading branch information
Keno committed Jan 8, 2019
1 parent 436eec7 commit 1868f4f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ static void foreach_mtable_in_module(
{
size_t i;
void **table = m->bindings.table;
jl_eqtable_put(visited, m, jl_true, NULL);
jl_eqtable_put(visited, (jl_value_t*)m, jl_true, NULL);
for (i = 1; i < m->bindings.size; i += 2) {
if (table[i] != HT_NOTFOUND) {
jl_binding_t *b = (jl_binding_t*)table[i];
Expand Down
4 changes: 2 additions & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1381,8 +1381,8 @@ STATIC_INLINE jl_function_t *jl_get_function(jl_module_t *m, const char *name)
int jl_is_submodule(jl_module_t *child, jl_module_t *parent) JL_NOTSAFEPOINT;

// eq hash tables
JL_DLLEXPORT jl_array_t *jl_eqtable_put(jl_array_t *h, void *key, void *val, int *inserted);
JL_DLLEXPORT jl_value_t *jl_eqtable_get(jl_array_t *h, void *key,
JL_DLLEXPORT jl_array_t *jl_eqtable_put(jl_array_t *h, jl_value_t *key, jl_value_t *val, int *inserted);
JL_DLLEXPORT jl_value_t *jl_eqtable_get(jl_array_t *h, jl_value_t *key,
jl_value_t *deflt);

// system information
Expand Down
22 changes: 11 additions & 11 deletions src/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#define keyhash(k) jl_object_id(k)
#define h2index(hv, sz) (size_t)(((hv) & ((sz)-1)) * 2)

static int jl_table_assign_bp(jl_array_t **pa, void *key, void *val);
static int jl_table_assign_bp(jl_array_t **pa, jl_value_t *key, jl_value_t *val);

JL_DLLEXPORT jl_array_t *jl_idtable_rehash(jl_array_t *a, size_t newsz)
{
// Assume *pa don't need a write barrier
// pa doesn't have to be a GC slot but *pa needs to be rooted
size_t sz = jl_array_len(a);
size_t i;
void **ol = (void **)a->data;
jl_value_t **ol = (jl_value_t **)a->data;
jl_array_t *newa = jl_alloc_vec_any(newsz);
// keep the original array in the original slot since we need `ol`
// to be valid in the loop below.
Expand All @@ -36,7 +36,7 @@ JL_DLLEXPORT jl_array_t *jl_idtable_rehash(jl_array_t *a, size_t newsz)
return newa;
}

static int jl_table_assign_bp(jl_array_t **pa, void *key, void *val)
static int jl_table_assign_bp(jl_array_t **pa, jl_value_t *key, jl_value_t *val)
{
// pa points to a **rooted** gc frame slot
uint_t hv;
Expand All @@ -47,7 +47,7 @@ static int jl_table_assign_bp(jl_array_t **pa, void *key, void *val)
size_t maxprobe = max_probe(sz);
void **tab = (void **)a->data;

hv = keyhash((jl_value_t *)key);
hv = keyhash(key);
while (1) {
iter = 0;
index = h2index(hv, sz);
Expand All @@ -61,7 +61,7 @@ static int jl_table_assign_bp(jl_array_t **pa, void *key, void *val)
empty_slot = index;
break;
}
if (jl_egal((jl_value_t *)key, (jl_value_t *)tab[index])) {
if (jl_egal(key, (jl_value_t *)tab[index])) {
if (tab[index + 1] != NULL) {
tab[index + 1] = val;
jl_gc_wb(a, val);
Expand Down Expand Up @@ -110,13 +110,13 @@ static int jl_table_assign_bp(jl_array_t **pa, void *key, void *val)
}

/* returns bp if key is in hash, otherwise NULL */
static void **jl_table_peek_bp(jl_array_t *a, void *key)
static void **jl_table_peek_bp(jl_array_t *a, jl_value_t *key)
{
size_t sz = hash_size(a);
assert(sz >= 1);
size_t maxprobe = max_probe(sz);
void **tab = (void **)a->data;
uint_t hv = keyhash((jl_value_t *)key);
uint_t hv = keyhash(key);
size_t index = h2index(hv, sz);
sz *= 2;
size_t orig = index;
Expand All @@ -125,7 +125,7 @@ static void **jl_table_peek_bp(jl_array_t *a, void *key)
do {
if (tab[index] == NULL)
return NULL;
if (jl_egal((jl_value_t *)key, (jl_value_t *)tab[index])) {
if (jl_egal(key, (jl_value_t *)tab[index])) {
if (tab[index + 1] != NULL)
return &tab[index + 1];
// `nothing` is our sentinel value for deletion, so need to keep searching if it's also our search key
Expand All @@ -140,7 +140,7 @@ static void **jl_table_peek_bp(jl_array_t *a, void *key)
}

JL_DLLEXPORT
jl_array_t *jl_eqtable_put(jl_array_t *h, void *key, void *val, int *p_inserted)
jl_array_t *jl_eqtable_put(jl_array_t *h, jl_value_t *key, jl_value_t *val, int *p_inserted)
{
JL_GC_PUSH1(&h);
// &h may be assigned to in jl_idtable_rehash so it need to be rooted
Expand All @@ -152,14 +152,14 @@ jl_array_t *jl_eqtable_put(jl_array_t *h, void *key, void *val, int *p_inserted)
}

JL_DLLEXPORT
jl_value_t *jl_eqtable_get(jl_array_t *h, void *key, jl_value_t *deflt)
jl_value_t *jl_eqtable_get(jl_array_t *h, jl_value_t *key, jl_value_t *deflt)
{
void **bp = jl_table_peek_bp(h, key);
return (bp == NULL) ? deflt : (jl_value_t *)*bp;
}

JL_DLLEXPORT
jl_value_t *jl_eqtable_pop(jl_array_t *h, void *key, jl_value_t *deflt, int *found)
jl_value_t *jl_eqtable_pop(jl_array_t *h, jl_value_t *key, jl_value_t *deflt, int *found)
{
void **bp = jl_table_peek_bp(h, key);
if (found)
Expand Down

0 comments on commit 1868f4f

Please sign in to comment.