Skip to content

Commit

Permalink
Consistently use stdint.h int types
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Jan 30, 2016
1 parent 4d1bf92 commit 53df511
Show file tree
Hide file tree
Showing 32 changed files with 287 additions and 297 deletions.
6 changes: 3 additions & 3 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ JL_DEFINE_MUTEX(symbol_table)

static jl_sym_t *volatile symtab = NULL;

static uptrint_t hash_symbol(const char *str, size_t len)
static uintptr_t hash_symbol(const char *str, size_t len)
{
return memhash(str, len) ^ ~(uptrint_t)0/3*2;
return memhash(str, len) ^ ~(uintptr_t)0/3*2;
}

#define SYM_POOL_SIZE 524288
Expand Down Expand Up @@ -416,7 +416,7 @@ static jl_sym_t *symtab_lookup(jl_sym_t *volatile *ptree, const char *str,
size_t len, jl_sym_t *volatile **slot)
{
jl_sym_t *node = *ptree;
uptrint_t h = hash_symbol(str, len);
uintptr_t h = hash_symbol(str, len);

// Tree nodes sorted by major key of (int(hash)) and minor key of (str).
while (node != NULL) {
Expand Down
20 changes: 10 additions & 10 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ JL_CALLABLE(jl_f_invoke)
#define hash64(a) int64to32hash(a)
#endif

static uptrint_t bits_hash(void *b, size_t sz)
static uintptr_t bits_hash(void *b, size_t sz)
{
switch (sz) {
case 1: return int32hash(*(int8_t*)b);
Expand All @@ -1007,19 +1007,19 @@ static uptrint_t bits_hash(void *b, size_t sz)
}
}

static uptrint_t NOINLINE hash_svec(jl_svec_t *v)
static uintptr_t NOINLINE hash_svec(jl_svec_t *v)
{
uptrint_t h = 0;
uintptr_t h = 0;
size_t l = jl_svec_len(v);
for(size_t i = 0; i < l; i++) {
jl_value_t *x = jl_svecref(v,i);
uptrint_t u = x==NULL ? 0 : jl_object_id(x);
uintptr_t u = x==NULL ? 0 : jl_object_id(x);
h = bitmix(h, u);
}
return h;
}

static uptrint_t jl_object_id_(jl_value_t *tv, jl_value_t *v)
static uintptr_t jl_object_id_(jl_value_t *tv, jl_value_t *v)
{
if (tv == (jl_value_t*)jl_sym_type)
return ((jl_sym_t*)v)->hash;
Expand All @@ -1028,7 +1028,7 @@ static uptrint_t jl_object_id_(jl_value_t *tv, jl_value_t *v)
jl_datatype_t *dt = (jl_datatype_t*)tv;
if (dt == jl_datatype_type) {
jl_datatype_t *dtv = (jl_datatype_t*)v;
uptrint_t h = 0xda1ada1a;
uintptr_t h = 0xda1ada1a;
// has_typevars always returns 0 on name->primary, so that type
// can exist in the cache. however, interpreter.c mutates its
// typevars' `bound` fields to 0, corrupting the cache. this is
Expand All @@ -1039,9 +1039,9 @@ static uptrint_t jl_object_id_(jl_value_t *tv, jl_value_t *v)
}
if (dt == jl_typename_type)
return bitmix(((jl_typename_t*)v)->uid, 0xa1ada1ad);
if (dt->mutabl) return inthash((uptrint_t)v);
if (dt->mutabl) return inthash((uintptr_t)v);
size_t sz = jl_datatype_size(tv);
uptrint_t h = jl_object_id(tv);
uintptr_t h = jl_object_id(tv);
if (sz == 0) return ~h;
size_t nf = jl_datatype_nfields(dt);
if (nf == 0) {
Expand All @@ -1050,7 +1050,7 @@ static uptrint_t jl_object_id_(jl_value_t *tv, jl_value_t *v)
for (size_t f=0; f < nf; f++) {
size_t offs = jl_field_offset(dt, f);
char *vo = (char*)jl_data_ptr(v) + offs;
uptrint_t u;
uintptr_t u;
if (jl_field_isptr(dt, f)) {
jl_value_t *f = *(jl_value_t**)vo;
u = f==NULL ? 0 : jl_object_id(f);
Expand All @@ -1068,7 +1068,7 @@ static uptrint_t jl_object_id_(jl_value_t *tv, jl_value_t *v)
return h;
}

JL_DLLEXPORT uptrint_t jl_object_id(jl_value_t *v)
JL_DLLEXPORT uintptr_t jl_object_id(jl_value_t *v)
{
return jl_object_id_(jl_typeof(v), v);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

// keep track of llvmcall declarations
#if defined(USE_MCJIT) || defined(USE_ORCJIT)
static std::map<u_int64_t,llvm::GlobalValue*> llvmcallDecls;
static std::map<uint64_t,llvm::GlobalValue*> llvmcallDecls;
#else
static std::set<u_int64_t> llvmcallDecls;
static std::set<uint64_t> llvmcallDecls;
#endif

static std::map<std::string, GlobalVariable*> libMapGV;
Expand Down Expand Up @@ -634,7 +634,7 @@ static jl_cgval_t emit_llvmcall(jl_value_t **args, size_t nargs, jl_codectx_t *c
llvm::raw_string_ostream rtypename(rstring);
rettype->print(rtypename);
#if defined(USE_MCJIT) || defined(USE_ORCJIT)
std::map<u_int64_t,std::string> localDecls;
std::map<uint64_t,std::string> localDecls;
#endif

if (decl != NULL) {
Expand All @@ -643,7 +643,7 @@ static jl_cgval_t emit_llvmcall(jl_value_t **args, size_t nargs, jl_codectx_t *c
// parse string line by line
std::string declstr;
while (std::getline(declarations, declstr, '\n')) {
u_int64_t declhash = memhash(declstr.c_str(), declstr.length());
uint64_t declhash = memhash(declstr.c_str(), declstr.length());
#if defined(USE_MCJIT) || defined(USE_ORCJIT)
auto it = llvmcallDecls.find(declhash);
if (it != llvmcallDecls.end()) {
Expand Down
4 changes: 2 additions & 2 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class FunctionMover : public ValueMaterializer
std::map<Value*, void *>::iterator it;
it = jl_llvm_to_jl_value.find(GV);
if (it != jl_llvm_to_jl_value.end()) {
newGV->setInitializer(Constant::getIntegerValue(GV->getType()->getElementType(),APInt(sizeof(void*)*8,(ptrint_t)it->second)));
newGV->setInitializer(Constant::getIntegerValue(GV->getType()->getElementType(),APInt(sizeof(void*)*8,(intptr_t)it->second)));
newGV->setConstant(true);
}
else if (GV->hasInitializer()) {
Expand Down Expand Up @@ -1082,7 +1082,7 @@ static Value *emit_typeof(Value *tt)
tt = builder.CreateLoad(emit_typeptr_addr(tt), false);
tt = builder.CreateIntToPtr(builder.CreateAnd(
builder.CreatePtrToInt(tt, T_size),
ConstantInt::get(T_size,~(uptrint_t)15)),
ConstantInt::get(T_size,~(uintptr_t)15)),
T_pjlvalue);
return tt;
}
Expand Down
74 changes: 37 additions & 37 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ static const jl_fptr_t id_to_fptrs[] = {
static jl_array_t *tree_literal_values=NULL; // (only used in MODE_AST)
static jl_module_t *tree_enclosing_module=NULL; // (only used in MODE_AST)

static const ptrint_t LongSymbol_tag = 23;
static const ptrint_t LongSvec_tag = 24;
static const ptrint_t LongExpr_tag = 25;
static const ptrint_t LiteralVal_tag = 26;
static const ptrint_t SmallInt64_tag = 27;
static const ptrint_t SmallDataType_tag= 28;
static const ptrint_t Int32_tag = 29;
static const ptrint_t Array1d_tag = 30;
static const ptrint_t Singleton_tag = 31;
static const ptrint_t CommonSym_tag = 32;
static const ptrint_t NearbyGlobal_tag = 33; // a GlobalRef pointing to tree_enclosing_module
static const ptrint_t Null_tag = 253;
static const ptrint_t ShortBackRef_tag = 254;
static const ptrint_t BackRef_tag = 255;

static ptrint_t VALUE_TAGS;
static const intptr_t LongSymbol_tag = 23;
static const intptr_t LongSvec_tag = 24;
static const intptr_t LongExpr_tag = 25;
static const intptr_t LiteralVal_tag = 26;
static const intptr_t SmallInt64_tag = 27;
static const intptr_t SmallDataType_tag= 28;
static const intptr_t Int32_tag = 29;
static const intptr_t Array1d_tag = 30;
static const intptr_t Singleton_tag = 31;
static const intptr_t CommonSym_tag = 32;
static const intptr_t NearbyGlobal_tag = 33; // a GlobalRef pointing to tree_enclosing_module
static const intptr_t Null_tag = 253;
static const intptr_t ShortBackRef_tag = 254;
static const intptr_t BackRef_tag = 255;

static intptr_t VALUE_TAGS;

typedef enum _DUMP_MODES {
// not in the serializer at all, or
Expand Down Expand Up @@ -179,7 +179,7 @@ static uint16_t read_uint16(ios_t *s)

static void writetag(ios_t *s, void *v)
{
write_uint8(s, (uint8_t)(ptrint_t)ptrhash_get(&ser_tag, v));
write_uint8(s, (uint8_t)(intptr_t)ptrhash_get(&ser_tag, v));
}

static void write_as_tag(ios_t *s, uint8_t tag)
Expand Down Expand Up @@ -447,7 +447,7 @@ static void jl_serialize_fptr(ios_t *s, void *fptr)
if (*pbp == HT_NOTFOUND || fptr == NULL)
write_uint16(s, 1);
else
write_uint16(s, *(ptrint_t*)pbp);
write_uint16(s, *(intptr_t*)pbp);
}

static int module_in_worklist(jl_module_t *mod) {
Expand Down Expand Up @@ -494,9 +494,9 @@ static void jl_serialize_datatype(ios_t *s, jl_datatype_t *dt)
tag = 5; // anything else (needs uid assigned later)
if (!internal) {
// also flag this in the backref table as special
uptrint_t *bp = (uptrint_t*)ptrhash_bp(&backref_table, dt);
assert(*bp != (uptrint_t)HT_NOTFOUND);
*bp |= 1; assert(((uptrint_t)HT_NOTFOUND)|1);
uintptr_t *bp = (uintptr_t*)ptrhash_bp(&backref_table, dt);
assert(*bp != (uintptr_t)HT_NOTFOUND);
*bp |= 1; assert(((uintptr_t)HT_NOTFOUND)|1);
}
}
}
Expand Down Expand Up @@ -635,7 +635,7 @@ static void jl_serialize_value_(ios_t *s, jl_value_t *v)

void **bp = ptrhash_bp(&ser_tag, v);
if (*bp != HT_NOTFOUND) {
write_as_tag(s, (uint8_t)(ptrint_t)*bp);
write_as_tag(s, (uint8_t)(intptr_t)*bp);
return;
}
if (jl_is_symbol(v)) {
Expand Down Expand Up @@ -671,7 +671,7 @@ static void jl_serialize_value_(ios_t *s, jl_value_t *v)
}
return;
}
ptrint_t pos = backref_table_numel++;
intptr_t pos = backref_table_numel++;
if (jl_typeof(v) == jl_idtable_type) {
// will need to rehash this, later (after types are fully constructed)
arraylist_push(&reinit_list, (void*)pos);
Expand Down Expand Up @@ -852,9 +852,9 @@ static void jl_serialize_value_(ios_t *s, jl_value_t *v)
if (v == t->instance) {
if (mode == MODE_MODULE) {
// also flag this in the backref table as special
uptrint_t *bp = (uptrint_t*)ptrhash_bp(&backref_table, v);
assert(*bp != (uptrint_t)HT_NOTFOUND);
*bp |= 1; assert(((uptrint_t)HT_NOTFOUND)|1);
uintptr_t *bp = (uintptr_t*)ptrhash_bp(&backref_table, v);
assert(*bp != (uintptr_t)HT_NOTFOUND);
*bp |= 1; assert(((uintptr_t)HT_NOTFOUND)|1);
}
writetag(s, (jl_value_t*)Singleton_tag);
jl_serialize_value(s, t);
Expand Down Expand Up @@ -1203,7 +1203,7 @@ static jl_value_t *jl_deserialize_datatype(ios_t *s, int pos, jl_value_t **loc)
assert(pos > 0);
assert(mode != MODE_MODULE_POSTWORK);
arraylist_push(&flagref_list, loc);
arraylist_push(&flagref_list, (void*)(uptrint_t)pos);
arraylist_push(&flagref_list, (void*)(uintptr_t)pos);
dt->uid = -1; // mark that this type needs a new uid
}

Expand Down Expand Up @@ -1258,7 +1258,7 @@ static jl_value_t *jl_deserialize_value(ios_t *s, jl_value_t **loc)
}
if (tag == BackRef_tag || tag == ShortBackRef_tag) {
assert(tree_literal_values == NULL && mode != MODE_AST);
uptrint_t offs = (tag == BackRef_tag) ? read_int32(s) : read_uint16(s);
uintptr_t offs = (tag == BackRef_tag) ? read_int32(s) : read_uint16(s);
int isdatatype = 0;
if (mode == MODE_MODULE) {
isdatatype = !!(offs & 1);
Expand All @@ -1273,7 +1273,7 @@ static jl_value_t *jl_deserialize_value(ios_t *s, jl_value_t **loc)
assert(bp);
if (isdatatype && loc != NULL) {
arraylist_push(&flagref_list, loc);
arraylist_push(&flagref_list, (void*)(uptrint_t)-1);
arraylist_push(&flagref_list, (void*)(uintptr_t)-1);
}
return (jl_value_t*)bp;
}
Expand Down Expand Up @@ -1603,15 +1603,15 @@ static jl_value_t *jl_deserialize_value_(ios_t *s, jl_value_t *vtag, jl_value_t
}
else if (vtag == (jl_value_t*)Singleton_tag) {
if (mode == MODE_MODULE_POSTWORK) {
uptrint_t pos = backref_list.len;
uintptr_t pos = backref_list.len;
arraylist_push(&backref_list, NULL);
jl_datatype_t *dt = (jl_datatype_t*)jl_deserialize_value(s, NULL);
backref_list.items[pos] = dt->instance;
return dt->instance;
}
jl_value_t *v = (jl_value_t*)jl_gc_alloc_0w();
if (usetable) {
uptrint_t pos = backref_list.len;
uintptr_t pos = backref_list.len;
arraylist_push(&backref_list, (void*)v);
if (mode == MODE_MODULE) {
// TODO: optimize the case where the value can easily be obtained
Expand Down Expand Up @@ -1846,7 +1846,7 @@ static void jl_save_system_image_to_stream(ios_t *f)
jl_serialize_value(f, jl_type_type->name->mt);

// ensure everything in deser_tag is reassociated with its GlobalValue
ptrint_t i=2;
intptr_t i=2;
for (i=2; i < 255; i++) {
jl_serialize_gv(f, deser_tag[i]);
}
Expand Down Expand Up @@ -1943,7 +1943,7 @@ static void jl_restore_system_image_from_stream(ios_t *f)
jl_current_module = jl_base_module; // run start_image in Base

// ensure everything in deser_tag is reassociated with its GlobalValue
ptrint_t i;
intptr_t i;
for (i=2; i < 255; i++) {
jl_deserialize_gv(f, deser_tag[i]);
}
Expand Down Expand Up @@ -2219,14 +2219,14 @@ static void jl_recache_types(void)
}
assert(dt);
if (t != dt) {
jl_set_typeof(dt, (jl_value_t*)(ptrint_t)0x10); // invalidate the old value to help catch errors
jl_set_typeof(dt, (jl_value_t*)(intptr_t)0x10); // invalidate the old value to help catch errors
if ((jl_value_t*)dt == o) {
if (loc) *loc = (jl_value_t*)t;
if (offs > 0) backref_list.items[offs] = t;
}
}
if (t->instance != v) {
jl_set_typeof(v, (jl_value_t*)(ptrint_t)0x20); // invalidate the old value to help catch errors
jl_set_typeof(v, (jl_value_t*)(intptr_t)0x20); // invalidate the old value to help catch errors
if (v == o) {
*loc = t->instance;
if (offs > 0) backref_list.items[offs] = t->instance;
Expand Down Expand Up @@ -2439,14 +2439,14 @@ void jl_init_serializer(void)
NULL
};

ptrint_t i=2;
intptr_t i=2;
while (tags[i-2] != NULL) {
ptrhash_put(&ser_tag, tags[i-2], (void*)i);
deser_tag[i] = (jl_value_t*)tags[i-2];
i += 1;
}
assert(i <= Null_tag);
VALUE_TAGS = (ptrint_t)ptrhash_get(&ser_tag, jl_emptysvec);
VALUE_TAGS = (intptr_t)ptrhash_get(&ser_tag, jl_emptysvec);

i=2;
while (id_to_fptrs[i] != NULL) {
Expand Down
Loading

0 comments on commit 53df511

Please sign in to comment.