Skip to content

Commit

Permalink
intval=int: fixed several ptr<->intval casts
Browse files Browse the repository at this point in the history
See GH #1145
  • Loading branch information
Reini Urban committed Nov 22, 2014
1 parent 891dd90 commit e963637
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions include/parrot/parrot.h
Expand Up @@ -135,8 +135,8 @@ typedef struct parrot_interp_t Interp;
# endif /* PTR_SIZE == LONG_SIZE */
#endif /* PTR_SIZE == INTVAL_SIZE */
#define PTR2INTVAL(p) INTVAL2PTR(INTVAL, (p))
#define PTR2UINTVAL(p) UINTVAL2PTR(UINTVAL, (p))
#define PTR2ULONG(p) UINTVAL2PTR(unsigned long, (p))
#define PTR2UINTVAL(p) UINTVAL2PTR(UINTVAL, (p))
#define PTR2ULONG(p) UINTVAL2PTR(unsigned long, (p))

/*
* some compilers don't like lvalue casts, so macroize them
Expand Down Expand Up @@ -194,7 +194,7 @@ typedef void (*funcptr_t)(void);

/* define macros for converting between data and function pointers. As it
* turns out, ANSI C does appear to permit you to do this conversion if you
* convert the value to an integer (well, a value type large enough to hold
* convert the value to a long (well, a value type large enough to hold
* a pointer) in between. Believe it or not, this even works on TenDRA (tcc).
*/
#define D2FPTR(x) UINTVAL2PTR(funcptr_t, PTR2ULONG(x))
Expand Down
2 changes: 1 addition & 1 deletion src/ops/core.ops
Expand Up @@ -609,7 +609,7 @@ inline op set_addr(invar PMC, invar LABEL) {

inline op get_addr(out INT, invar PMC) {
void * const ptr = VTABLE_get_pointer(interp, $2);
$1 = (INTVAL)ptr;
$1 = PTR2INTVAL(ptr);
}

=back
Expand Down
4 changes: 2 additions & 2 deletions src/pmc/addrregistry.pmc
Expand Up @@ -135,7 +135,7 @@ Returns true if the hash size is not zero.
value = Parrot_hash_get(INTERP, hash, key);

if (value)
return (INTVAL)value;
return PTR2INTVAL(value);

return 0;
}
Expand Down Expand Up @@ -217,7 +217,7 @@ reaches 0, delete the entry.
VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
Hash *hash;
GET_ATTR_pmc_registry(INTERP, SELF, hash);
Parrot_hash_put(INTERP, hash, key, (void *)value);
Parrot_hash_put(INTERP, hash, key, INTVAL2PTR(void *, value));
}

VTABLE void delete_keyed(PMC *key) {
Expand Down
4 changes: 2 additions & 2 deletions src/pmc/class.pmc
Expand Up @@ -1445,7 +1445,7 @@ Returns whether the class is or inherits from C<*class>.
b = Parrot_hash_get_bucket(INTERP, _class->isa_cache,
(void *)classobj);
if (b)
return (INTVAL)b->value;
return PTR2INTVAL(b->value);
}

/* this is effectively what the default PMC's isa_pmc does
Expand Down Expand Up @@ -1475,7 +1475,7 @@ Returns whether the class is or inherits from C<*class>.
if (_class->instantiated) {
PARROT_GC_WRITE_BARRIER(INTERP, SELF);
Parrot_hash_put(INTERP, _class->isa_cache, (void *)classobj,
(void *)retval);
INTVAL2PTR(void *, retval));
}
return retval;

Expand Down
4 changes: 2 additions & 2 deletions src/pmc/imageiofreeze.pmc
Expand Up @@ -237,7 +237,7 @@ check_seen(PARROT_INTERP, ARGIN(PMC *self), ARGIN(PMC *v))
Hash * const seen = (Hash *)VTABLE_get_pointer(interp, PARROT_IMAGEIOFREEZE(self)->seen);
HashBucket * const b = Parrot_hash_get_bucket(interp, seen, v);
if (b)
return (UINTVAL)b->value;
return PTR2UINTVAL(b->value);
else
return 0;
}
Expand Down Expand Up @@ -487,7 +487,7 @@ hasn't been seen yet, it is also pushed onto the todo list.
PARROT_GC_WRITE_BARRIER(INTERP, SELF);
}

Parrot_hash_put(INTERP, seen, v, (void *)id);
Parrot_hash_put(INTERP, seen, v, INTVAL2PTR(void *, id));
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/pmc/lexpad.pmc
Expand Up @@ -163,10 +163,10 @@ register_number_for_get(PARROT_INTERP, ARGMOD(PMC *info), ARGIN(STRING *name),
const HashBucket * const b = register_bucket(interp, info, name);
if (!b)
return -1;
if (((INTVAL)b->value & 3) != reg_type)
if ((PTR2INTVAL(b->value) & 3) != reg_type)
throw_wrong_register_type(interp, name);

return ((INTVAL)b->value) >> 2;
return PTR2INTVAL(b->value) >> 2;
}

/*
Expand All @@ -190,10 +190,10 @@ register_number_for_set(PARROT_INTERP, ARGMOD(PMC *info), ARGMOD(STRING *name),
const HashBucket * const b = register_bucket(interp, info, name);
if (!b)
throw_lexical_not_found(interp, name);
if (((INTVAL)b->value & 3) != reg_type)
if ((PTR2INTVAL(b->value) & 3) != reg_type)
throw_wrong_register_type(interp, name);

return ((INTVAL)b->value) >> 2;
return PTR2INTVAL(b->value) >> 2;
}


Expand Down Expand Up @@ -456,8 +456,8 @@ Get iterator for declared lexicals.
while (VTABLE_get_bool(INTERP, info_iter)) {
STRING * const name = VTABLE_shift_string(INTERP, info_iter);
HashBucket * const b = Parrot_hash_get_bucket(INTERP, hash, name);
INTVAL reg_type = (INTVAL)b->value & 3;
INTVAL reg_idx = ((INTVAL)b->value) >> 2;
INTVAL reg_type = PTR2UINTVAL(b->value) & 3;
INTVAL reg_idx = PTR2UINTVAL(b->value) >> 2;
PMC * value;
switch (reg_type) {
case REGNO_PMC:
Expand Down Expand Up @@ -521,7 +521,7 @@ Returns a number based on the type of the variable named name.
GET_ATTR_lexinfo(INTERP, SELF, info);
b = register_bucket(INTERP, info, name);
if (b)
ret = (INTVAL) b->value & 3;
ret = PTR2INTVAL(b->value) & 3;
RETURN(INTVAL ret);
}

Expand Down
4 changes: 2 additions & 2 deletions src/pmc/nci.pmc
Expand Up @@ -302,7 +302,7 @@ Returns the function pointer as an integer.
Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
if (!nci_info->func)
build_func(INTERP, SELF, nci_info);
return (INTVAL)nci_info->func;
return PTR2INTVAL(nci_info->func);
}

/*
Expand All @@ -318,7 +318,7 @@ Returns the boolean value of the pointer.
VTABLE INTVAL get_bool() :no_wb {
const Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
UNUSED(INTERP)
return (0 != (INTVAL)nci_info->orig_func);
return !!nci_info->orig_func;
}

/*
Expand Down
4 changes: 2 additions & 2 deletions src/pmc/pointer.pmc
Expand Up @@ -117,7 +117,7 @@ Returns the pointer value as an integer.

VTABLE INTVAL get_integer() :no_wb {
UNUSED(INTERP)
return (INTVAL)(PARROT_POINTER(SELF)->pointer);
return PTR2INTVAL(PARROT_POINTER(SELF)->pointer);
}

/*
Expand All @@ -132,7 +132,7 @@ Returns the pointer value as a floating-point number.

VTABLE FLOATVAL get_number() :no_wb {
UNUSED(INTERP)
return (FLOATVAL)(INTVAL)(PARROT_POINTER(SELF)->pointer);
return (FLOATVAL)PTR2ULONG(PARROT_POINTER(SELF)->pointer);
}

/*
Expand Down
8 changes: 4 additions & 4 deletions src/pmc/ptrobj.pmc
Expand Up @@ -77,7 +77,7 @@ Get or set the custom C<clone> function.
return clone(INTERP, SELF, ptr);
else
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_METHOD_NOT_FOUND,
"clone not implemented for PtrObj %x", ptr);
"clone not implemented for PtrObj %p", ptr);
}

METHOD clone_func(PMC *func :optional, INTVAL has_func :opt_flag) :manual_wb {
Expand All @@ -90,7 +90,7 @@ Get or set the custom C<clone> function.
else {
ptrobj_clone_func_t f;
GET_ATTR_clone(INTERP, SELF, f);
func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, (INTVAL)f);
func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, PTR2INTVAL(f));
RETURN(PMC func);
}
}
Expand Down Expand Up @@ -129,7 +129,7 @@ Get or set the custom C<mark> function.
else {
ptrobj_mark_func_t f;
GET_ATTR_mark(INTERP, SELF, f);
func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, (INTVAL)f);
func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, PTR2ULONG(f));
RETURN(PMC func);
}
}
Expand Down Expand Up @@ -168,7 +168,7 @@ Get or set the custom C<destroy> function.
else {
ptrobj_destroy_func_t f;
GET_ATTR_destroy(INTERP, SELF, f);
func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, (INTVAL)f);
func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, PTR2ULONG(f));
RETURN(PMC func);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pmc/structview.pmc
Expand Up @@ -1009,7 +1009,7 @@ Return a C<Ptr> to the C<n>th element of a struct.
}

p = ((char *)p) + elts[n].byte_offset;
ret = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, (INTVAL)p);
ret = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, PTR2ULONG(p));

RETURN(PMC ret);
}
Expand Down
6 changes: 3 additions & 3 deletions src/pmc/sub.pmc
Expand Up @@ -335,11 +335,11 @@ now.> -DRS
*/

VTABLE INTVAL get_integer_keyed(PMC *key) :no_wb {
UNUSED(key)
Parrot_Sub_attributes *sub;
PMC_get_sub(INTERP, SELF, sub);
UNUSED(key)

return (INTVAL) (sub->seg->base.data);
PMC_get_sub(INTERP, SELF, sub);
return PTR2INTVAL(sub->seg->base.data);
}


Expand Down

0 comments on commit e963637

Please sign in to comment.