Skip to content

Commit

Permalink
Fix Object#object_id to not collide between immediates and references
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Phoenix committed Mar 4, 2008
1 parent 48495b5 commit fa413a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 5 additions & 2 deletions shotgun/lib/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ static inline uintptr_t object_get_id(STATE, OBJECT self) {

/* Lazy allocate object's ids, since most don't need them. */
if(NIL_P(id)) {
id = I2N(state->om->last_object_id++);
/* All references have an even object_id. last_object_id starts out at 0
* but we don't want to use 0 as an object_id, so we just add before using */
id = I2N(state->om->last_object_id += 2);
object_set_ivar(state, meta, state->global->sym_object_id, id);
}

return (uintptr_t)id;
} else {
return (uintptr_t)(self);
/* All non-references have an odd object_id */
return (((uintptr_t)self << 1) | 1);
}
}

Expand Down
4 changes: 1 addition & 3 deletions shotgun/lib/object_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ object_memory object_memory_new() {
om->context_bottom = (OBJECT)(om->contexts->address);
om->context_last = (OBJECT)((uintptr_t)om->contexts->address + CONTEXT_SIZE - (CTX_SIZE * 10));

// Start the values up a bit higher so they don't collide
// with the hashs of symbols right off the bat.
om->last_object_id = 0x10000;
om->last_object_id = 0;
// om->enlarge_new = 0;
// om->new_size = 0;
return om;
Expand Down

0 comments on commit fa413a5

Please sign in to comment.