[uim-commit] r2578 - branches/r5rs/sigscheme
yamaken at freedesktop.org
yamaken at freedesktop.org
Wed Dec 14 11:24:22 PST 2005
Author: yamaken
Date: 2005-12-14 11:24:19 -0800 (Wed, 14 Dec 2005)
New Revision: 2578
Added:
branches/r5rs/sigscheme/alloc.c
Modified:
branches/r5rs/sigscheme/Makefile.am
branches/r5rs/sigscheme/error.c
branches/r5rs/sigscheme/sigscheme.h
branches/r5rs/sigscheme/sigschemeinternal.h
branches/r5rs/sigscheme/storage-gc.c
Log:
* sigscheme/alloc.c
- New file
- (uintptr_t): New type
- (scm_malloc, scm_calloc, scm_realloc): Moved from error.c
- (scm_malloc_aligned): Moved from storage-gc.c
* sigscheme/error.c
- (SCM_ERRMSG_UNHANDLED_EXCEPTION, SCM_ERRMSG_MEMORY_EXHAUSTED,
SCM_ASSERT_ALLOCATED): Move to sigscheme.h
- (ASSERT_ALLOCATED): Move to sigschemeinternal.h
- (scm_malloc, scm_calloc, scm_realloc): Move to alloc.c
* sigscheme/sigscheme.h
- (SCM_ERRMSG_UNHANDLED_EXCEPTION, SCM_ERRMSG_MEMORY_EXHAUSTED,
SCM_ASSERT_ALLOCATED): Moved from error.c
- (scm_malloc, scm_calloc, scm_realloc, scm_malloc_aligned): Moved
from sigschemeinternal.h
- (scm_malloc_aligned): Moved the decl from storage-gc.c
* sigscheme/sigschemeinternal.h
- (ASSERT_ALLOCATED): Moved from error.c
- (scm_malloc, scm_calloc, scm_realloc): Move to sigscheme.c
* sigscheme/storage-gc.c
- (scm_malloc_aligned): Move to alloc.c
* sigscheme/Makefile.am
- (libsscm_la_SOURCES): Add alloc.c
Modified: branches/r5rs/sigscheme/Makefile.am
===================================================================
--- branches/r5rs/sigscheme/Makefile.am 2005-12-14 18:59:51 UTC (rev 2577)
+++ branches/r5rs/sigscheme/Makefile.am 2005-12-14 19:24:19 UTC (rev 2578)
@@ -52,7 +52,7 @@
EXTRA_DIST = $(FUNC_TABLES) $(BUILD_FUNCTBL_SOURCES)
libsscm_la_SOURCES = \
- storage.c debug.c \
+ alloc.c storage.c debug.c \
storage-gc.c \
storage-symbol.c \
storage-continuation.c \
Copied: branches/r5rs/sigscheme/alloc.c (from rev 2577, branches/r5rs/sigscheme/error.c)
===================================================================
--- branches/r5rs/sigscheme/error.c 2005-12-14 18:59:51 UTC (rev 2577)
+++ branches/r5rs/sigscheme/alloc.c 2005-12-14 19:24:19 UTC (rev 2578)
@@ -0,0 +1,125 @@
+/*===========================================================================
+ * FileName : alloc.c
+ * About : memory allocators
+ *
+ * Copyright (C) 2005 by Kazuki Ohta (mover at hct.zaq.ne.jp)
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of authors nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+===========================================================================*/
+
+/*=======================================
+ System Include
+=======================================*/
+#include <stdlib.h>
+#include <assert.h>
+
+/*=======================================
+ Local Include
+=======================================*/
+#include "sigscheme.h"
+#include "sigschemeinternal.h"
+
+/*=======================================
+ File Local Macro Definitions
+=======================================*/
+#if 1
+/* FIXME: replace with C99-independent stdint.h */
+typedef unsigned long uintptr_t;
+#endif
+
+/*=======================================
+ File Local Type Definitions
+=======================================*/
+
+/*=======================================
+ Variable Declarations
+=======================================*/
+
+/*=======================================
+ File Local Function Declarations
+=======================================*/
+
+/*=======================================
+ Function Implementations
+=======================================*/
+/* FIXME: ensure safety in a portable way */
+void *scm_malloc_aligned(size_t size)
+{
+ void *p;
+
+#if HAVE_POSIX_MEMALIGN
+ /*
+ * Cited from manpage of posix_memalign(3) of glibc:
+ *
+ * CONFORMING TO
+ * The function valloc() appeared in 3.0 BSD. It is documented as being
+ * obsolete in BSD 4.3, and as legacy in SUSv2. It no longer occurs in
+ * SUSv3. The function memalign() appears in SunOS 4.1.3 but not in
+ * BSD 4.4. The function posix_memalign() comes from POSIX 1003.1d.
+ */
+ posix_memalign(&p, 16, size);
+ if (!p)
+ ERR("memory exhausted");
+#else
+ p = scm_malloc(size);
+ /* heaps must be aligned to sizeof(ScmCell) */
+ assert(!((uintptr_t)p % sizeof(ScmCell)));
+#endif
+
+ return p;
+}
+
+void *scm_malloc(size_t size)
+{
+ void *p;
+
+ p = malloc(size);
+ ASSERT_ALLOCATED(p);
+
+ return p;
+}
+
+void *scm_calloc(size_t number, size_t size)
+{
+ void *p;
+
+ p = calloc(number, size);
+ ASSERT_ALLOCATED(p);
+
+ return p;
+}
+
+void *scm_realloc(void *ptr, size_t size)
+{
+ void *p;
+
+ p = realloc(ptr, size);
+ ASSERT_ALLOCATED(p);
+
+ return p;
+}
Modified: branches/r5rs/sigscheme/error.c
===================================================================
--- branches/r5rs/sigscheme/error.c 2005-12-14 18:59:51 UTC (rev 2577)
+++ branches/r5rs/sigscheme/error.c 2005-12-14 19:24:19 UTC (rev 2578)
@@ -55,13 +55,6 @@
#define SCM_BACKTRACE_HEADER "**** BACKTRACE ****\n"
#define SCM_BACKTRACE_SEP "------------------------------\n"
-#define SCM_ERRMSG_UNHANDLED_EXCEPTION "unhandled exception"
-#define SCM_ERRMSG_MEMORY_EXHAUSTED "memory exhausted"
-
-#define SCM_ASSERT_ALLOCATED(p) \
- ((p) || (Scm_FatalError(SCM_ERRMSG_MEMORY_EXHAUSTED), 1))
-#define ASSERT_ALLOCATED SCM_ASSERT_ALLOCATED
-
/*=======================================
Variable Declarations
=======================================*/
@@ -151,36 +144,6 @@
va_end(va);
}
-void *scm_malloc(size_t size)
-{
- void *p;
-
- p = malloc(size);
- ASSERT_ALLOCATED(p);
-
- return p;
-}
-
-void *scm_calloc(size_t number, size_t size)
-{
- void *p;
-
- p = calloc(number, size);
- ASSERT_ALLOCATED(p);
-
- return p;
-}
-
-void *scm_realloc(void *ptr, size_t size)
-{
- void *p;
-
- p = realloc(ptr, size);
- ASSERT_ALLOCATED(p);
-
- return p;
-}
-
#if SCM_USE_SRFI34
static int srfi34_providedp(void)
{
Modified: branches/r5rs/sigscheme/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/sigscheme.h 2005-12-14 18:59:51 UTC (rev 2577)
+++ branches/r5rs/sigscheme/sigscheme.h 2005-12-14 19:24:19 UTC (rev 2578)
@@ -55,6 +55,9 @@
/*=======================================
Macro Declarations
=======================================*/
+#define SCM_ERRMSG_UNHANDLED_EXCEPTION "unhandled exception"
+#define SCM_ERRMSG_MEMORY_EXHAUSTED "memory exhausted"
+
#ifdef __GNUC__
#define SCM_NOINLINE __attribute__((noinline))
#define SCM_NORETURN __attribute__((noreturn))
@@ -88,6 +91,9 @@
#define SCM_ASSERT(cond) \
((cond) || SigScm_Die("assertion failed", __FILE__, __LINE__))
+#define SCM_ASSERT_ALLOCATED(p) \
+ ((p) || (Scm_FatalError(SCM_ERRMSG_MEMORY_EXHAUSTED), 1))
+
#define SCM_ERROBJP(obj) (NFALSEP(ScmOp_error_objectp(obj)))
#define SCM_SYMBOL_BOUNDP(sym) (!SCM_EQ(SCM_SYMBOL_VCELL(sym), SCM_UNBOUND))
@@ -383,6 +389,12 @@
void Scm_RegisterProcedureVariadicTailRec5(const char *name, ScmObj (*func)(ScmObj, ScmObj, ScmObj, ScmObj, ScmObj, ScmObj, ScmEvalState*));
#endif
+/* alloc.c */
+void *scm_malloc_aligned(size_t size);
+void *scm_malloc(size_t size);
+void *scm_calloc(size_t number, size_t size);
+void *scm_realloc(void *ptr, size_t size);
+
/* storage.c */
ScmObj Scm_NewCons(ScmObj a, ScmObj b);
ScmObj Scm_NewInt(int val);
Modified: branches/r5rs/sigscheme/sigschemeinternal.h
===================================================================
--- branches/r5rs/sigscheme/sigschemeinternal.h 2005-12-14 18:59:51 UTC (rev 2577)
+++ branches/r5rs/sigscheme/sigschemeinternal.h 2005-12-14 19:24:19 UTC (rev 2578)
@@ -283,8 +283,11 @@
/* Symbol Name Hash Size */
#define NAMEHASH_SIZE 1024
+/* error handlings */
#define SCM_ERR_HEADER "Error: "
+#define ASSERT_ALLOCATED SCM_ASSERT_ALLOCATED
+
/*=======================================
String Mutation Assertion
=======================================*/
@@ -428,9 +431,6 @@
/* error.c */
void SigScm_InitError(void);
-void *scm_malloc(size_t size);
-void *scm_calloc(size_t number, size_t size);
-void *scm_realloc(void *ptr, size_t size);
void Scm_ThrowException(ScmObj errorobj) SCM_NORETURN;
void SigScm_ShowErrorHeader(void);
void Scm_ErrorObj(const char *func_name, const char *msg, ScmObj obj) SCM_NORETURN;
Modified: branches/r5rs/sigscheme/storage-gc.c
===================================================================
--- branches/r5rs/sigscheme/storage-gc.c 2005-12-14 18:59:51 UTC (rev 2577)
+++ branches/r5rs/sigscheme/storage-gc.c 2005-12-14 19:24:19 UTC (rev 2578)
@@ -60,8 +60,6 @@
#include <stdlib.h>
#include <setjmp.h>
-#include <assert.h>
-
/*=======================================
Local Include
=======================================*/
@@ -118,8 +116,6 @@
=======================================*/
static ScmObj **locate_protected_var(ScmObj *var);
-void *scm_malloc_aligned(size_t size);
-
static void initialize_heap(size_t size, size_t alloc_threshold,
int n_max, int n_init);
static void add_heap(void);
@@ -266,33 +262,6 @@
/*============================================================================
Heap Allocator & Garbage Collector
============================================================================*/
-/* FIXME: ensure safety in a portable way */
-void *scm_malloc_aligned(size_t size)
-{
- void *p;
-
-#if HAVE_POSIX_MEMALIGN
- /*
- * Cited from manpage of posix_memalign(3) of glibc:
- *
- * CONFORMING TO
- * The function valloc() appeared in 3.0 BSD. It is documented as being
- * obsolete in BSD 4.3, and as legacy in SUSv2. It no longer occurs in
- * SUSv3. The function memalign() appears in SunOS 4.1.3 but not in
- * BSD 4.4. The function posix_memalign() comes from POSIX 1003.1d.
- */
- posix_memalign(&p, 16, size);
- if (!p)
- ERR("memory exhausted");
-#else
- p = scm_malloc(size);
- /* heaps must be aligned to sizeof(ScmCell) */
- assert(!((uintptr_t)p % sizeof(ScmCell)));
-#endif
-
- return p;
-}
-
static void initialize_heap(size_t size, size_t alloc_threshold,
int n_max, int n_init)
{
More information about the uim-commit
mailing list