You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2009/09/10 04:41:23 UTC

svn commit: r813197 - in /lucene/lucy/trunk/core/Lucy/Util: Memory.bp Memory.c

Author: marvin
Date: Thu Sep 10 02:41:23 2009
New Revision: 813197

URL: http://svn.apache.org/viewvc?rev=813197&view=rev
Log:
Commit LUCY-35, adding the Lucy::Util::Memory module.  Introduce MALLOCATE,
CALLOCATE, REALLOCATE, and FREEMEM macros, which resolve to wrapped functions
within Memory.c.

Added:
    lucene/lucy/trunk/core/Lucy/Util/Memory.bp   (with props)
    lucene/lucy/trunk/core/Lucy/Util/Memory.c   (with props)

Added: lucene/lucy/trunk/core/Lucy/Util/Memory.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Util/Memory.bp?rev=813197&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Util/Memory.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Util/Memory.bp Thu Sep 10 02:41:23 2009
@@ -0,0 +1,61 @@
+parcel Lucy;
+
+inert class Lucy::Util::Memory {
+
+    /** Attempt to allocate memory with malloc, but print an error and exit if the
+     * call fails.
+     */
+    inert void*
+    wrapped_malloc(size_t count);
+
+    /** Attempt to allocate memory with calloc, but print an error and exit if the
+     * call fails.
+     */
+    inert void*
+    wrapped_calloc(size_t count, size_t size);
+
+    /** Attempt to allocate memory with realloc, but print an error and exit if 
+     * the call fails.
+     */
+    inert void*
+    wrapped_realloc(void *ptr, size_t size);
+
+    /** Free memory.  (Wrapping is necessary in cases where memory allocated
+     * within the Lucy library has to be freed in an external environment where
+     * "free" may have been redefined.)
+     */
+    inert void
+    wrapped_free(void *ptr);
+}
+
+__C__
+
+#define LUCY_MALLOCATE    lucy_Memory_wrapped_malloc
+#define LUCY_CALLOCATE    lucy_Memory_wrapped_calloc
+#define LUCY_REALLOCATE   lucy_Memory_wrapped_realloc
+#define LUCY_FREEMEM      lucy_Memory_wrapped_free
+
+#ifdef LUCY_USE_SHORT_NAMES
+  #define MALLOCATE                       LUCY_MALLOCATE
+  #define CALLOCATE                       LUCY_CALLOCATE
+  #define REALLOCATE                      LUCY_REALLOCATE
+  #define FREEMEM                         LUCY_FREEMEM
+#endif
+
+__END_C__
+
+/* Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/core/Lucy/Util/Memory.bp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/lucy/trunk/core/Lucy/Util/Memory.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Util/Memory.c?rev=813197&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Util/Memory.c (added)
+++ lucene/lucy/trunk/core/Lucy/Util/Memory.c Thu Sep 10 02:41:23 2009
@@ -0,0 +1,60 @@
+#define C_LUCY_MEMORY
+#include <stdlib.h>
+#include <stdio.h>
+#define LUCY_USE_SHORT_NAMES
+#include "Lucy/Util/Memory.h"
+
+void*
+Memory_wrapped_malloc(size_t count)
+{
+    void *pointer = malloc(count);
+    if (pointer == NULL && count != 0) {
+        fprintf(stderr, "Out of memory.\n");
+        exit(1);
+    }
+    return pointer;
+}
+
+void*
+Memory_wrapped_calloc(size_t count, size_t size)
+{
+    void *pointer = calloc(count, size);
+    if (pointer == NULL && count != 0) {
+        fprintf(stderr, "Out of memory.\n");
+        exit(1);
+    }
+    return pointer;
+}
+
+void*
+Memory_wrapped_realloc(void *ptr, size_t size)
+{
+    void *pointer = realloc(ptr, size);
+    if (pointer == NULL && size != 0) {
+        fprintf(stderr, "Out of memory.\n");
+        exit(1);
+    }
+    return pointer;
+}
+
+void
+lucy_Memory_wrapped_free(void *ptr)
+{
+    free(ptr);
+}
+
+/* Copyright 2009 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Propchange: lucene/lucy/trunk/core/Lucy/Util/Memory.c
------------------------------------------------------------------------------
    svn:eol-style = native