[svn:parrot] r48358 - in trunk: include/parrot src/gc
bubaflub at svn.parrot.org
bubaflub at svn.parrot.org
Mon Aug 9 20:54:35 UTC 2010
Author: bubaflub
Date: Mon Aug 9 20:54:32 2010
New Revision: 48358
URL: https://trac.parrot.org/parrot/changeset/48358
Log:
Deprecate mem_internal_*alloc functions [TT #1402] Paul_the_Greek++
Modified:
trunk/include/parrot/memory.h
trunk/src/gc/alloc_memory.c
Modified: trunk/include/parrot/memory.h
==============================================================================
--- trunk/include/parrot/memory.h Mon Aug 9 12:32:58 2010 (r48357)
+++ trunk/include/parrot/memory.h Mon Aug 9 20:54:32 2010 (r48358)
@@ -17,20 +17,33 @@
/* Use these macros instead of calling the functions listed below. */
/* They protect against things like passing null to mem__sys_realloc, */
/* which is not portable. */
-#define mem_internal_allocate(x) mem__internal_allocate((x), __FILE__, __LINE__)
-#define mem_internal_allocate_typed(type) \
- (type *)mem__internal_allocate(sizeof (type), __FILE__, __LINE__)
-#define mem_internal_allocate_zeroed(x) mem__internal_allocate_zeroed((x), \
- __FILE__, __LINE__)
+
+/* It was decided that having a second set of memory allocation functions
+ is a waste. These macros were rewritten to use the much more prevalent
+ mem_sys_* functions and then the mem__internal_* functions were
+ eliminated. */
+
+#define mem_internal_allocate(x) mem_sys_allocate(x)
+
+#define mem_internal_allocate_typed(type) (type *)mem_sys_allocate(sizeof (type))
+
+#define mem_internal_allocate_zeroed(x) mem_sys_allocate_zeroed(x)
+
#define mem_internal_allocate_zeroed_typed(type) \
- (type *)mem__internal_allocate_zeroed(sizeof (type), __FILE__, __LINE__)
+ (type *)mem_sys_allocate_zeroed(sizeof (type))
+
#define mem_internal_allocate_n_zeroed_typed(n, type) \
- (type *)mem__internal_allocate_zeroed((n) * sizeof (type), __FILE__, __LINE__)
+ (type *)mem_sys_allocate_zeroed((n) * sizeof (type))
+
+#define mem_internal_realloc(x, y) mem_sys_realloc((x), (y))
+
+#define mem_internal_realloc_zeroed(p, x, y) mem_sys_realloc_zeroed((p), (x), (y))
+
+#define mem_internal_realloc_n_zeroed_typed(p, x, y, type) \
+ (type *)mem_sys_realloc_zeroed((p), (x) * sizeof (type), (y) * sizeof (type))
+
+#define mem_internal_free(x) mem_sys_free(x)
-#define mem_internal_realloc(x, y) mem__internal_realloc((x), (y), __FILE__, __LINE__)
-#define mem_internal_realloc_zeroed(p, x, y) mem__internal_realloc_zeroed((p), (x), (y), __FILE__, __LINE__)
-#define mem_internal_realloc_n_zeroed_typed(p, x, y, type) (type *)mem__internal_realloc_zeroed((p), (x) * sizeof (type), (y) * sizeof (type), __FILE__, __LINE__)
-#define mem_internal_free(x) mem__internal_free((x), __FILE__, __LINE__)
#define mem_sys_memcopy memcpy
#define mem_sys_memmove memmove
@@ -93,47 +106,6 @@
char * mem_sys_strdup(ARGIN(const char *src))
__attribute__nonnull__(1);
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-void * mem__internal_allocate(
- size_t size,
- ARGIN(const char *file),
- int line)
- __attribute__nonnull__(2);
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-void * mem__internal_allocate_zeroed(
- size_t size,
- ARGIN(const char *file),
- int line)
- __attribute__nonnull__(2);
-
-void mem__internal_free(
- ARGFREE(void *from),
- ARGIN(const char *file),
- int line)
- __attribute__nonnull__(2);
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-void * mem__internal_realloc(
- ARGFREE(void *from),
- size_t size,
- ARGIN(const char *file),
- int line)
- __attribute__nonnull__(3);
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-void * mem__internal_realloc_zeroed(
- ARGFREE(void *from),
- size_t size,
- size_t old_size,
- ARGIN(const char *file),
- int line)
- __attribute__nonnull__(4);
-
#define ASSERT_ARGS_mem_sys_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_mem_sys_allocate_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_mem_sys_free __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
@@ -141,16 +113,6 @@
#define ASSERT_ARGS_mem_sys_realloc_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_mem_sys_strdup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(src))
-#define ASSERT_ARGS_mem__internal_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(file))
-#define ASSERT_ARGS_mem__internal_allocate_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(file))
-#define ASSERT_ARGS_mem__internal_free __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(file))
-#define ASSERT_ARGS_mem__internal_realloc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(file))
-#define ASSERT_ARGS_mem__internal_realloc_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(file))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/gc/alloc_memory.c */
Modified: trunk/src/gc/alloc_memory.c
==============================================================================
--- trunk/src/gc/alloc_memory.c Mon Aug 9 12:32:58 2010 (r48357)
+++ trunk/src/gc/alloc_memory.c Mon Aug 9 20:54:32 2010 (r48358)
@@ -64,37 +64,6 @@
/*
-=item C<void * mem__internal_allocate(size_t size, const char *file, int line)>
-
-Calls C<malloc> to allocate memory from the system, Panics if there is no
-memory available. If C<DETAIL_MEMORY_DEBUG> macro is defined, prints
-debug information to C<STDERR>.
-
-=cut
-
-*/
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-void *
-mem__internal_allocate(size_t size, ARGIN(const char *file), int line)
-{
- ASSERT_ARGS(mem__internal_allocate)
- void * const ptr = malloc((size_t)size);
-#ifdef DETAIL_MEMORY_DEBUG
- fprintf(stderr, "Internal malloc %i at %p (%s/%d)\n",
- size, ptr, file, line);
-#else
- UNUSED(file);
- UNUSED(line);
-#endif
- if (!ptr)
- PANIC_OUT_OF_MEM(size);
- return ptr;
-}
-
-/*
-
=item C<void * mem_sys_allocate_zeroed(size_t size)>
Uses C<calloc> to allocate system memory. Guaranteed to succeed, Panics
@@ -122,38 +91,6 @@
/*
-=item C<void * mem__internal_allocate_zeroed(size_t size, const char *file, int
-line)>
-
-Uses C<calloc> to allocate system memory. Guaranteed to succeed, Panics
-otherwise. If C<DETAIL_MEMORY_DEBUG> macro is defined, prints
-debug information to C<STDERR>.
-
-=cut
-
-*/
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-void *
-mem__internal_allocate_zeroed(size_t size, ARGIN(const char *file), int line)
-{
- ASSERT_ARGS(mem__internal_allocate_zeroed)
- void * const ptr = calloc(1, (size_t)size);
-#ifdef DETAIL_MEMORY_DEBUG
- fprintf(stderr, "Internal malloc %i at %p (%s/%d)\n",
- size, ptr, file, line);
-#else
- UNUSED(file);
- UNUSED(line);
-#endif
- if (!ptr)
- PANIC_OUT_OF_MEM(size);
- return ptr;
-}
-
-/*
-
=item C<void * mem_sys_realloc(void *from, size_t size)>
Resizes a chunk of memory. Unlike C<realloc>, it can handle a
@@ -226,81 +163,6 @@
/*
-=item C<void * mem__internal_realloc(void *from, size_t size, const char *file,
-int line)>
-
-Resizes a chunk of system memory. Unlike C<realloc>, it can handle a
-NULL pointer, in which case a new memory block is allocated for the
-requested size. If C<DETAIL_MEMORY_DEBUG> macro is defined, debug
-information is printed to C<STDERR>.
-
-=cut
-
-*/
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-void *
-mem__internal_realloc(ARGFREE(void *from), size_t size,
- ARGIN(const char *file), int line)
-{
- ASSERT_ARGS(mem__internal_realloc)
- void * const ptr = realloc(from, size);
-#ifdef DETAIL_MEMORY_DEBUG
- fprintf(stderr, "internal free of %p (realloc -- %i bytes) (%s/%d)\n",
- from, size, file, line);
- fprintf(stderr, "Internal malloc %i at %p (%s/%d)\n",
- size, ptr, file, line);
-#else
- UNUSED(file);
- UNUSED(line);
-#endif
- if (!ptr)
- PANIC_OUT_OF_MEM(size);
- return ptr;
-}
-
-/*
-
-=item C<void * mem__internal_realloc_zeroed(void *from, size_t size, size_t
-old_size, const char *file, int line)>
-
-Reallocates a given buffer of size C<old_size> to C<size>. If the new size
-is larger then the old size, the difference is filled with zeros. Contains
-debugging information, and can print filename and line number where it is
-used if C<DETAIL_MEMORY_DEBUG> is defined.
-
-=cut
-
-*/
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-void *
-mem__internal_realloc_zeroed(ARGFREE(void *from), size_t size, size_t old_size,
- ARGIN(const char *file), int line)
-{
- ASSERT_ARGS(mem__internal_realloc_zeroed)
- void * const ptr = realloc(from, size);
-#ifdef DETAIL_MEMORY_DEBUG
- fprintf(stderr, "internal free of %p (realloc -- %i bytes) (%s/%d)\n",
- from, size, file, line);
- fprintf(stderr, "Internal malloc %i at %p (%s/%d)\n",
- size, ptr, file, line);
-#else
- UNUSED(file);
- UNUSED(line);
-#endif
- if (!ptr)
- PANIC_OUT_OF_MEM(size);
- if (size > old_size)
- memset((char*)ptr + old_size, 0, size - old_size);
-
- return ptr;
-}
-
-/*
-
=item C<void mem_sys_free(void *from)>
Frees a chunk of memory back to the system.
@@ -323,31 +185,6 @@
/*
-=item C<void mem__internal_free(void *from, const char *file, int line)>
-
-Frees a chunk of memory back to the system. If
-C<DETAIL_MEMORY_DEBUG> macro is defined, prints debug information to
-C<STDERR>.
-
-=cut
-
-*/
-
-void
-mem__internal_free(ARGFREE(void *from), ARGIN(const char *file), int line)
-{
- ASSERT_ARGS(mem__internal_free)
-#ifdef DETAIL_MEMORY_DEBUG
- fprintf(stderr, "Internal free of %p (%s/%d)\n", from, file, line);
-#else
- UNUSED(file);
- UNUSED(line);
-#endif
- free(from);
-}
-
-/*
-
=item C<char * mem_sys_strdup(const char *src)>
Copy a C string to a new block of memory allocated with mem_sys_allocate,
More information about the parrot-commits
mailing list