# New Ticket Created by Mike Mattie # Please include the string: [perl #42961] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42961 >
This patch adds const qualifiers to string_cstring_free , and mem_sys_free. In reviewing other commits to the parrot tree I noticed that authors were dropping const qualifiers because it was generating warnings when they passed their pointer to mem_sys_free. const qualifiers are one of the most powerful optimization and debugging tools available in the C language and should be preserved and used thoroughly. This patch changes the signature of the mem_sys_free , and string_cstring_free functions to const <type> const which is the most const qualified form. types that are not already const qualified are automatically promoted to the qualified form. This generates one new warning in memory.c about free discarding qualifiers. The intent has been expressed with a (void*) cast , but the compiler is still warning. This is harmless. I would rather have this one warning , than a tree stripped of const. If someone remembers the magic to muzzle the compiler around free( from ) in memory.c please feel free to amend the patch.
--- HEAD/src/string.c 2007-05-14 08:08:31.000000000 -0700 +++ mine/src/string.c 2007-05-15 11:18:05.000000000 -0700 @@ -1880,7 +1880,7 @@ */ void -string_cstring_free(char *p) +string_cstring_free(const char * const p) { mem_sys_free(p); } --- HEAD/include/parrot/string_funcs.h 2007-05-14 08:08:45.000000000 -0700 +++ mine/include/parrot/string_funcs.h 2007-05-15 11:22:52.000000000 -0700 @@ -83,7 +83,7 @@ PARROT_API STRING *const_string(Interp *, const char *buffer) __attribute__nonnull__(2); PARROT_API char *string_to_cstring(Interp *, STRING *); -PARROT_API void string_cstring_free(char *); +PARROT_API void string_cstring_free(const char * const); PARROT_API void string_pin(Interp *, STRING *); PARROT_API void string_unpin(Interp *, STRING *); PARROT_API STRING *string_bitwise_and(Interp *interp, STRING *s1, --- HEAD/src/gc/memory.c 2007-05-14 08:08:20.000000000 -0700 +++ mine/src/gc/memory.c 2007-05-15 11:46:42.000000000 -0700 @@ -153,13 +153,13 @@ */ void -mem_sys_free(void *from) +mem_sys_free(const void * const from) { #ifdef DETAIL_MEMORY_DEBUG fprintf(stderr, "Freed %p\n", from); #endif if (from) - free(from); + free((void*)from); } void --- HEAD/include/parrot/memory.h 2007-05-14 08:08:45.000000000 -0700 +++ mine/include/parrot/memory.h 2007-05-15 11:51:29.000000000 -0700 @@ -19,7 +19,7 @@ PARROT_API void *mem__sys_realloc(void *, size_t); #define mem_sys_realloc(x,y) (assert(x!=NULL), mem__sys_realloc(x,y)) -PARROT_API void mem_sys_free(void *); +PARROT_API void mem_sys_free(const void * const); void *mem__internal_allocate(size_t, const char *, int); #define mem_internal_allocate(x) mem__internal_allocate(x, __FILE__, __LINE__)
signature.asc
Description: PGP signature