On Mon Apr 02 17:16:45 2007, stmpeters wrote:
> Here's some additional cleanups for making Parrot a bit more friendly
> to a wider variety of C compilers.
> 

It is always good to actually include the attachment you are sending.

Steve


Index: src/encoding.c
===================================================================
--- src/encoding.c	(revision 17946)
+++ src/encoding.c	(working copy)
@@ -65,7 +65,7 @@
 ENCODING *
 Parrot_new_encoding(Interp *interp)
 {
-    return mem_sys_allocate(sizeof (ENCODING));
+    return mem_allocate_typed(ENCODING);
 }
 
 ENCODING *
@@ -175,10 +175,10 @@
      * loading of encodings from inside threads
      */
     if (!n)
-        all_encodings->enc = mem_sys_allocate(sizeof (One_encoding));
+        all_encodings->enc = mem_allocate_typed(One_encoding);
     else
-        all_encodings->enc = mem_sys_realloc(all_encodings->enc, (n + 1) *
-                sizeof (One_encoding));
+        all_encodings->enc = (One_encoding*)mem_sys_realloc(all_encodings->enc,
+                (n + 1) * sizeof (One_encoding));
     all_encodings->n_encodings++;
     all_encodings->enc[n].encoding = encoding;
     all_encodings->enc[n].name = const_string(interp, encodingname);
@@ -191,7 +191,7 @@
         ENCODING *encoding)
 {
     if (!all_encodings) {
-        all_encodings = mem_sys_allocate(sizeof (All_encodings));
+        all_encodings = mem_allocate_typed(All_encodings);
         all_encodings->n_encodings = 0;
         all_encodings->enc = NULL;
     }
Index: src/charset.c
===================================================================
--- src/charset.c	(revision 17946)
+++ src/charset.c	(working copy)
@@ -62,7 +62,7 @@
 CHARSET *
 Parrot_new_charset(Interp *interp)
 {
-    return mem_sys_allocate(sizeof (CHARSET));
+    return mem_allocate_typed(CHARSET);
 }
 
 void
@@ -184,10 +184,10 @@
      * loading of charsets from inside threads
      */
     if (!n)
-        all_charsets->set = mem_sys_allocate(sizeof (One_charset));
+        all_charsets->set = mem_allocate_typed(One_charset);
     else
-        all_charsets->set = mem_sys_realloc(all_charsets->set, (n + 1) *
-                sizeof (One_charset));
+        all_charsets->set = (One_charset *)mem_sys_realloc(all_charsets->set,
+                (n + 1) * sizeof (One_charset));
     all_charsets->n_charsets++;
     all_charsets->set[n].charset = charset;
     all_charsets->set[n].name = const_string(interp, charsetname);
@@ -219,7 +219,7 @@
         CHARSET *charset)
 {
     if (!all_charsets) {
-        all_charsets = mem_sys_allocate(sizeof (All_charsets));
+        all_charsets = mem_allocate_typed(All_charsets);
         all_charsets->n_charsets = 0;
         all_charsets->set = NULL;
     }
Index: src/inter_call.c
===================================================================
--- src/inter_call.c	(revision 17946)
+++ src/inter_call.c	(working copy)
@@ -348,7 +348,8 @@
             PMC *elem;
             if (st->key) {
                 st->src.slurp_i++;
-                st->name = parrot_hash_get_idx(interp, PMC_struct_val(st->src.slurp), st->key);
+                st->name = (STRING *)parrot_hash_get_idx(interp,
+                               (Hash *)PMC_struct_val(st->src.slurp), st->key);
                 assert(st->name);
                 elem = VTABLE_get_pmc_keyed_str(interp, st->src.slurp, st->name);
             }
Index: src/exec.c
===================================================================
--- src/exec.c	(revision 17946)
+++ src/exec.c	(working copy)
@@ -69,7 +69,7 @@
     extern PARROT_API int Parrot_exec_rel_count;
 
     Parrot_exec_objfile_t * const obj =
-        mem_sys_allocate_zeroed(sizeof (Parrot_exec_objfile_t));
+        mem_allocate_zeroed_typed(Parrot_exec_objfile_t);
     exec_init(obj);
     Parrot_exec_rel_addr = (char **)mem_sys_allocate_zeroed(4 * sizeof (char *));
     obj->bytecode_header_size =
@@ -206,7 +206,7 @@
         Parrot_exec_symbol_t *new_symbol;
 
         symbol_number = obj->symbol_count;
-        new_symbol = mem_sys_realloc(obj->symbol_table,
+        new_symbol = (Parrot_exec_symbol_t *)mem_sys_realloc(obj->symbol_table,
             (size_t)(obj->symbol_count + 1) * sizeof (Parrot_exec_symbol_t));
         obj->symbol_table = new_symbol;
 
Index: src/interpreter.c
===================================================================
--- src/interpreter.c	(revision 17946)
+++ src/interpreter.c	(working copy)
@@ -208,13 +208,14 @@
             size_t nb = interp->code->base.size / 16;
             if (nb < 8)
                 nb = (size_t)8;
-            pi->branches = mem_sys_allocate(sizeof (Prederef_branch) * nb);
+            pi->branches = (Prederef_branch *)mem_sys_allocate(
+                               sizeof (Prederef_branch) * nb);
             pi->n_allocated = nb;
             pi->n_branches = 0;
         }
         else if (pi->n_branches >= pi->n_allocated) {
             pi->n_allocated = (size_t) (pi->n_allocated * 1.5);
-            pi->branches = mem_sys_realloc(pi->branches,
+            pi->branches = (Prederef_branch *)mem_sys_realloc(pi->branches,
                     sizeof (Prederef_branch) * pi->n_allocated);
         }
         pi->branches[pi->n_branches].offs = offset;
@@ -448,7 +449,7 @@
 
     if (!interp->code->prederef.code) {
         size_t N = interp->code->base.size;
-        void **temp = prederef_arena;
+        void **temp = (void **)prederef_arena;
         opcode_t *pc = interp->code->base.data;
 
         interp->code->prederef.code = temp;
@@ -815,7 +816,8 @@
         return;
     /* function or CG core - prepare func_table */
     if (!interp->evc_func_table) {
-        interp->evc_func_table = mem_sys_allocate(sizeof (void *) * n);
+        interp->evc_func_table = (op_func_t *)mem_sys_allocate(
+                                     sizeof (op_func_t) * n);
         for (i = 0; i < n; ++i)
             interp->evc_func_table[i] = (op_func_t)
                 D2FPTR(((void**)lib->op_func_table)[CORE_OPS_check_events__]);
@@ -874,10 +876,10 @@
     }
 
     if (!interp->all_op_libs)
-        interp->all_op_libs = mem_sys_allocate(
+        interp->all_op_libs = (op_lib_t **)mem_sys_allocate(
                 sizeof (op_lib_t *) * (interp->n_libs + 1));
     else
-        interp->all_op_libs = mem_sys_realloc(interp->all_op_libs,
+        interp->all_op_libs = (op_lib_t **)mem_sys_realloc(interp->all_op_libs,
                 sizeof (op_lib_t *) * (interp->n_libs + 1));
 
     init_func = get_op_lib_init(0, 0, lib_pmc);
@@ -905,20 +907,20 @@
     core = PARROT_CORE_OPLIB_INIT(1);
 
     assert(interp->op_count == core->op_count);
-    new_evc_func_table = mem__sys_realloc(interp->evc_func_table,
-            sizeof (void *) * n_tot);
+    new_evc_func_table = (op_func_t *)mem__sys_realloc(interp->evc_func_table,
+            sizeof (op_func_t) * n_tot);
     if (core->flags & OP_FUNC_IS_ALLOCATED) {
-        new_func_table = mem_sys_realloc(core->op_func_table,
-                sizeof (void *) * n_tot);
-        new_info_table = mem_sys_realloc(core->op_info_table,
+        new_func_table = (op_func_t *)mem_sys_realloc(core->op_func_table,
+                sizeof (op_func_t) * n_tot);
+        new_info_table = (op_info_t *)mem_sys_realloc(core->op_info_table,
                 sizeof (op_info_t) * n_tot);
     }
     else {
         /*
          * allocate new op_func and info tables
          */
-        new_func_table = mem_sys_allocate(sizeof (void *) * n_tot);
-        new_info_table = mem_sys_allocate(sizeof (op_info_t) * n_tot);
+        new_func_table = (op_func_t *)mem_sys_allocate(sizeof (op_func_t) * n_tot);
+        new_info_table = (op_info_t *)mem_sys_allocate(sizeof (op_info_t) * n_tot);
         /* copy old */
         for (i = 0; i < n_old; ++i) {
             new_func_table[i] = interp->op_func_table[i];
@@ -975,7 +977,7 @@
         size_t n_old, size_t n_new, oplib_init_f init_func)
 {
     op_lib_t *cg_lib, *new_lib;
-    void **ops_addr = NULL;
+    op_func_t *ops_addr = NULL;
     size_t i, n_tot;
 #if 0
     /* related to CG and CGP ops issue below */
@@ -988,14 +990,14 @@
     cg_lib = init_func(1);
 
     if (cg_lib->flags & OP_FUNC_IS_ALLOCATED) {
-        ops_addr = mem_sys_realloc(cg_lib->op_func_table,
-                n_tot * sizeof (void *));
+        ops_addr = (op_func_t *)mem_sys_realloc(cg_lib->op_func_table,
+                n_tot * sizeof (op_func_t));
     }
     else {
-        ops_addr = mem_sys_allocate(n_tot * sizeof (void *));
+        ops_addr = (op_func_t *)mem_sys_allocate(n_tot * sizeof (op_func_t));
         cg_lib->flags = OP_FUNC_IS_ALLOCATED;
         for (i = 0; i < n_old; ++i)
-            ops_addr[i] = ((void **)cg_lib->op_func_table)[i];
+            ops_addr[i] = cg_lib->op_func_table[i];
     }
     /*
      * XXX running CG and CGP ops currently works only via the wrapper
@@ -1031,8 +1033,8 @@
         new_init_func = get_op_lib_init(0, 0, lib_variant);
         new_lib = new_init_func(1);
         for (i = n_old; i < n_tot; ++i)
-            ops_addr[i] = ((void **)new_lib->op_func_table)[i - n_old];
-        new_lib->op_func_table = (void *) ops_addr;
+            ops_addr[i] = (new_lib->op_func_table)[i - n_old];
+        new_lib->op_func_table = ops_addr;
         new_lib->op_count = n_tot;
         new_init_func((long) ops_addr);
     }
@@ -1040,7 +1042,7 @@
         /* if not install wrappers */
         /* fill new entries with the wrapper op */
         for (i = n_old; i < n_tot; ++i)
-            ops_addr[i] = ((void **)cg_lib->op_func_table)[CORE_OPS_wrapper__];
+            ops_addr[i] = (cg_lib->op_func_table)[CORE_OPS_wrapper__];
     }
     /*
      * if we are running this core, update event check ops
@@ -1048,13 +1050,13 @@
     if ((int)interp->run_core == cg_lib->core_type) {
         for (i = n_old; i < n_tot; ++i)
             interp->evc_func_table[i] =
-                (op_func_t)D2FPTR(ops_addr[CORE_OPS_check_events__]);
-        interp->save_func_table = (void *) ops_addr;
+                (op_func_t)ops_addr[CORE_OPS_check_events__];
+        interp->save_func_table = ops_addr;
     }
     /*
      * tell the cg_core about the new jump table
      */
-    cg_lib->op_func_table = (void *) ops_addr;
+    cg_lib->op_func_table = ops_addr;
     cg_lib->op_count = n_tot;
     init_func((long) ops_addr);
 }
@@ -1082,7 +1084,7 @@
 /*
 
 =item C<static void
-notify_func_table(Parrot_Interp interp, void* table, int on)>
+notify_func_table(Parrot_Interp interp, op_func_t* table, int on)>
 
 Tell the interpreter's running core about the new function table.
 
@@ -1091,7 +1093,7 @@
 */
 
 static void
-notify_func_table(Parrot_Interp interp, void* table, int on)
+notify_func_table(Parrot_Interp interp, op_func_t* table, int on)
 {
     oplib_init_f init_func = get_op_lib_init(1, interp->run_core, NULL);
     op_lib_t *lib = init_func(1);
Index: src/exceptions.c
===================================================================
--- src/exceptions.c	(revision 17946)
+++ src/exceptions.c	(working copy)
@@ -317,7 +317,7 @@
     struct Parrot_cont * cc;
 
     PMC * const handler
-        = stack_peek(interp, interp->dynamic_env, &type);
+        = (PMC *)stack_peek(interp, interp->dynamic_env, &type);
 
     if (! handler
             || type != STACK_ENTRY_PMC
@@ -378,7 +378,7 @@
 
 /*
 
-=item C<void *
+=item C<opcode_t *
 throw_exception(Interp *interp, PMC *exception, void *dest)>
 
 Throw the exception.
@@ -387,10 +387,10 @@
 
 */
 
-void *
+opcode_t *
 throw_exception(Interp *interp, PMC *exception, void *dest)
 {
-    void *address;
+    opcode_t *address;
 
     PMC * const handler = find_exception_handler(interp, exception);
     if (!handler)
@@ -409,7 +409,7 @@
 
 /*
 
-=item C<void *
+=item C<opcode_t *
 rethrow_exception(Interp *interp, PMC *exception)>
 
 Rethrow the exception.
@@ -418,11 +418,11 @@
 
 */
 
-void *
+opcode_t *
 rethrow_exception(Interp *interp, PMC *exception)
 {
     PMC *handler;
-    void *address;
+    opcode_t *address;
 
     if (exception->vtable->base_type != enum_class_Exception)
         PANIC("Illegal rethrow");
@@ -585,7 +585,7 @@
         interp->exc_free_list = the_exception->prev;
     }
     else
-        the_exception = mem_sys_allocate(sizeof (*the_exception));
+        the_exception = mem_allocate_typed(Parrot_exception);
     the_exception->prev = interp->exceptions;
     the_exception->resume = NULL;
     the_exception->msg = NULL;
@@ -749,7 +749,7 @@
 Parrot_init_exceptions(Interp *interp) {
     int i;
 
-    interp->exception_list = mem_sys_allocate(
+    interp->exception_list = (PMC **)mem_sys_allocate(
             sizeof (PMC*) * (E_LAST_PYTHON_E + 1));
     for (i = 0; i <= E_LAST_PYTHON_E; ++i) {
         PMC * const ex = pmc_new(interp, enum_class_Exception);
Index: include/parrot/oplib.h
===================================================================
--- include/parrot/oplib.h	(revision 17946)
+++ include/parrot/oplib.h	(working copy)
@@ -31,7 +31,7 @@
     int      patch_version;
     size_t      op_count;
     op_info_t * op_info_table;
-    void *      op_func_table;
+    op_func_t * op_func_table;
     int (*op_code)(const char * name, int full);
 } op_lib_t;
 
Index: include/parrot/events.h
===================================================================
--- include/parrot/events.h	(revision 17946)
+++ include/parrot/events.h	(working copy)
@@ -78,8 +78,8 @@
 PARROT_API void Parrot_schedule_interp_event(Parrot_Interp, parrot_event*);
 PARROT_API void Parrot_schedule_interp_qentry(Parrot_Interp, struct QUEUE_ENTRY* entry);
 
-#define CHECK_EVENTS(i, n)  Parrot_do_check_events(i, n)
-#define HANDLE_EVENTS(i, n) Parrot_do_handle_events(i, 1, n)
+#define CHECK_EVENTS(i, n)  (opcode_t *)Parrot_do_check_events(i, n)
+#define HANDLE_EVENTS(i, n) (opcode_t *)Parrot_do_handle_events(i, 1, n)
 
 PARROT_API void Parrot_init_signals(void);
 PARROT_API void Parrot_init_events(Parrot_Interp);
Index: include/parrot/memory.h
===================================================================
--- include/parrot/memory.h	(revision 17946)
+++ include/parrot/memory.h	(working copy)
@@ -41,6 +41,9 @@
 #define mem_sys_memcopy memcpy
 #define mem_sys_memmove memmove
 
+#define mem_allocate_typed(type)    (type *)mem_sys_allocate(sizeof(type))
+#define mem_allocate_zeroed_typed(type) (type *)mem_sys_allocate_zeroed(sizeof(type))
+
 #endif /* PARROT_MEMORY_H_GUARD */
 
 /*
Index: include/parrot/exceptions.h
===================================================================
--- include/parrot/exceptions.h	(revision 17946)
+++ include/parrot/exceptions.h	(working copy)
@@ -169,8 +169,8 @@
  */
 PARROT_API void push_exception(Parrot_Interp, PMC *);
 PARROT_API void pop_exception(Parrot_Interp);
-PARROT_API void * throw_exception(Parrot_Interp, PMC *, void *);
-PARROT_API void * rethrow_exception(Parrot_Interp, PMC *);
+PARROT_API opcode_t * throw_exception(Parrot_Interp, PMC *, void *);
+PARROT_API opcode_t * rethrow_exception(Parrot_Interp, PMC *);
 
 PARROT_API size_t handle_exception(Parrot_Interp);
 

Reply via email to