Author: Amaury Forgeot d'Arc <[email protected]>
Branch: remove-PYPY_NOT_MAIN_FILE
Changeset: r57132:d65337bf621c
Date: 2012-07-22 09:30 +0200
http://bitbucket.org/pypy/pypy/changeset/d65337bf621c/

Log:    Move debug_alloc.h into allocator.[ch]

diff --git a/pypy/translator/c/src/allocator.c 
b/pypy/translator/c/src/allocator.c
--- a/pypy/translator/c/src/allocator.c
+++ b/pypy/translator/c/src/allocator.c
@@ -1,6 +1,8 @@
 /* allocation functions */
 #include "common_header.h"
+#include "src/support.h"
 #include <malloc.h>
+#include <stdlib.h>
 
 #if defined(PYPY_USE_TRIVIAL_MALLOC)
   void *PyObject_Malloc(size_t n) { return malloc(n); }
@@ -23,3 +25,64 @@
 #  include "src/obmalloc.c"
 
 #endif
+
+
+/***  tracking raw mallocs and frees for debugging ***/
+
+#ifdef RPY_ASSERT
+
+struct pypy_debug_alloc_s {
+  struct pypy_debug_alloc_s *next;
+  void *addr;
+  const char *funcname;
+};
+
+static struct pypy_debug_alloc_s *pypy_debug_alloc_list = NULL;
+
+void pypy_debug_alloc_start(void *addr, const char *funcname)
+{
+  struct pypy_debug_alloc_s *p = malloc(sizeof(struct pypy_debug_alloc_s));
+  RPyAssert(p, "out of memory");
+  p->next = pypy_debug_alloc_list;
+  p->addr = addr;
+  p->funcname = funcname;
+  pypy_debug_alloc_list = p;
+}
+
+void pypy_debug_alloc_stop(void *addr)
+{
+  struct pypy_debug_alloc_s **p;
+  for (p = &pypy_debug_alloc_list; *p; p = &((*p)->next))
+    if ((*p)->addr == addr)
+      {
+        struct pypy_debug_alloc_s *dying;
+        dying = *p;
+        *p = dying->next;
+        free(dying);
+        return;
+      }
+  RPyAssert(0, "free() of a never-malloc()ed object");
+}
+
+void pypy_debug_alloc_results(void)
+{
+  long count = 0;
+  struct pypy_debug_alloc_s *p;
+  for (p = pypy_debug_alloc_list; p; p = p->next)
+    count++;
+  if (count > 0)
+    {
+      char *env = getenv("PYPY_ALLOC");
+      fprintf(stderr, "debug_alloc.h: %ld mallocs left", count);
+      if (env && *env)
+        {
+          fprintf(stderr, " (most recent first):\n");
+          for (p = pypy_debug_alloc_list; p; p = p->next)
+            fprintf(stderr, "    %p  %s\n", p->addr, p->funcname);
+        }
+      else
+        fprintf(stderr, " (use PYPY_ALLOC=1 to see the list)\n");
+    }
+}
+
+#endif /* RPY_ASSERT */
diff --git a/pypy/translator/c/src/allocator.h 
b/pypy/translator/c/src/allocator.h
--- a/pypy/translator/c/src/allocator.h
+++ b/pypy/translator/c/src/allocator.h
@@ -2,3 +2,24 @@
 void *PyObject_Malloc(size_t n);
 void *PyObject_Realloc(void *p, size_t n);
 void PyObject_Free(void *p);
+
+/***  tracking raw mallocs and frees for debugging          ***/
+
+#ifndef RPY_ASSERT
+
+#  define OP_TRACK_ALLOC_START(addr, r)   /* nothing */
+#  define OP_TRACK_ALLOC_STOP(addr, r)    /* nothing */
+#  define pypy_debug_alloc_results() /* nothing */
+
+#else /* RPY_ASSERT */
+
+#  define OP_TRACK_ALLOC_START(addr, r)  pypy_debug_alloc_start(addr, \
+                                                                __FUNCTION__)
+#  define OP_TRACK_ALLOC_STOP(addr, r)   pypy_debug_alloc_stop(addr)
+
+void pypy_debug_alloc_start(void*, const char*);
+void pypy_debug_alloc_stop(void*);
+void pypy_debug_alloc_results(void);
+
+#endif /* RPY_ASSERT */
+
diff --git a/pypy/translator/c/src/debug_alloc.h 
b/pypy/translator/c/src/debug_alloc.h
deleted file mode 100644
--- a/pypy/translator/c/src/debug_alloc.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/**************************************************************/
-/***  tracking raw mallocs and frees for debugging          ***/
-
-#ifndef RPY_ASSERT
-
-#  define OP_TRACK_ALLOC_START(addr, r)   /* nothing */
-#  define OP_TRACK_ALLOC_STOP(addr, r)    /* nothing */
-
-#else   /* ifdef RPY_ASSERT */
-
-#  define OP_TRACK_ALLOC_START(addr, r)  pypy_debug_alloc_start(addr, \
-                                                                __FUNCTION__)
-#  define OP_TRACK_ALLOC_STOP(addr, r)   pypy_debug_alloc_stop(addr)
-
-void pypy_debug_alloc_start(void*, const char*);
-void pypy_debug_alloc_stop(void*);
-void pypy_debug_alloc_results(void);
-
-/************************************************************/
-
-
-#ifdef PYPY_MAIN_IMPLEMENTATION_FILE
-
-struct pypy_debug_alloc_s {
-  struct pypy_debug_alloc_s *next;
-  void *addr;
-  const char *funcname;
-};
-
-static struct pypy_debug_alloc_s *pypy_debug_alloc_list = NULL;
-
-void pypy_debug_alloc_start(void *addr, const char *funcname)
-{
-  struct pypy_debug_alloc_s *p = malloc(sizeof(struct pypy_debug_alloc_s));
-  RPyAssert(p, "out of memory");
-  p->next = pypy_debug_alloc_list;
-  p->addr = addr;
-  p->funcname = funcname;
-  pypy_debug_alloc_list = p;
-}
-
-void pypy_debug_alloc_stop(void *addr)
-{
-  struct pypy_debug_alloc_s **p;
-  for (p = &pypy_debug_alloc_list; *p; p = &((*p)->next))
-    if ((*p)->addr == addr)
-      {
-        struct pypy_debug_alloc_s *dying;
-        dying = *p;
-        *p = dying->next;
-        free(dying);
-        return;
-      }
-  RPyAssert(0, "free() of a never-malloc()ed object");
-}
-
-void pypy_debug_alloc_results(void)
-{
-  long count = 0;
-  struct pypy_debug_alloc_s *p;
-  for (p = pypy_debug_alloc_list; p; p = p->next)
-    count++;
-  if (count > 0)
-    {
-      char *env = getenv("PYPY_ALLOC");
-      fprintf(stderr, "debug_alloc.h: %ld mallocs left", count);
-      if (env && *env)
-        {
-          fprintf(stderr, " (most recent first):\n");
-          for (p = pypy_debug_alloc_list; p; p = p->next)
-            fprintf(stderr, "    %p  %s\n", p->addr, p->funcname);
-        }
-      else
-        fprintf(stderr, " (use PYPY_ALLOC=1 to see the list)\n");
-    }
-}
-
-#endif
-
-
-#endif  /* RPY_ASSERT */
diff --git a/pypy/translator/c/src/g_include.h 
b/pypy/translator/c/src/g_include.h
--- a/pypy/translator/c/src/g_include.h
+++ b/pypy/translator/c/src/g_include.h
@@ -45,7 +45,6 @@
 #ifdef HAVE_RTYPER      /* only if we have an RTyper */
 #  include "src/rtyper.h"
 #  include "src/debug_traceback.h"
-#  include "src/debug_alloc.h"
 #  include "src/ll_strtod.h"
 #endif
 
diff --git a/pypy/translator/c/src/main.h b/pypy/translator/c/src/main.h
--- a/pypy/translator/c/src/main.h
+++ b/pypy/translator/c/src/main.h
@@ -59,9 +59,7 @@
 
     exitcode = STANDALONE_ENTRY_POINT(list);
 
-#ifdef RPY_ASSERT
     pypy_debug_alloc_results();
-#endif
 
     if (RPyExceptionOccurred()) {
         /* print the RPython traceback */
diff --git a/pypy/translator/tool/cbuild.py b/pypy/translator/tool/cbuild.py
--- a/pypy/translator/tool/cbuild.py
+++ b/pypy/translator/tool/cbuild.py
@@ -327,7 +327,9 @@
 /* Define on NetBSD to activate all library features */
 #define _NETBSD_SOURCE 1
 /* Define to activate features from IEEE Stds 1003.1-2001 */
-#define _POSIX_C_SOURCE 200112L
+#ifndef _POSIX_C_SOURCE
+#  define _POSIX_C_SOURCE 200112L
+#endif
 /* Define on FreeBSD to activate all library features */
 #define __BSD_VISIBLE 1
 #define __XSI_VISIBLE 700
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to