[Python-checkins] r51009 - in python/branches/bcannon-sandboxing: Include/Python.h Include/objimpl.h Objects/trackedmalloc.c Python/sysmodule.c configure configure.in pyconfig.h.in

brett.cannon python-checkins at python.org
Tue Aug 1 01:27:48 CEST 2006


Author: brett.cannon
Date: Tue Aug  1 01:27:46 2006
New Revision: 51009

Modified:
   python/branches/bcannon-sandboxing/Include/Python.h
   python/branches/bcannon-sandboxing/Include/objimpl.h
   python/branches/bcannon-sandboxing/Objects/trackedmalloc.c
   python/branches/bcannon-sandboxing/Python/sysmodule.c
   python/branches/bcannon-sandboxing/configure
   python/branches/bcannon-sandboxing/configure.in
   python/branches/bcannon-sandboxing/pyconfig.h.in
Log:
Add needed #ifdef protections.


Modified: python/branches/bcannon-sandboxing/Include/Python.h
==============================================================================
--- python/branches/bcannon-sandboxing/Include/Python.h	(original)
+++ python/branches/bcannon-sandboxing/Include/Python.h	Tue Aug  1 01:27:46 2006
@@ -73,6 +73,13 @@
 #if defined(PYMALLOC_DEBUG) && !defined(WITH_PYMALLOC)
 #error "PYMALLOC_DEBUG requires WITH_PYMALLOC"
 #endif
+
+#ifdef Py_TRACK_MEMORY
+#ifndef HAVE_MALLINFO
+#error "Py_TRACK_MEMORY required HAVE_MALLINFO"
+#endif /* !HAVE_MALLINFO */
+#endif /* Py_TRACK_MEMORY */
+
 #include "pymem.h"
 
 #include "object.h"

Modified: python/branches/bcannon-sandboxing/Include/objimpl.h
==============================================================================
--- python/branches/bcannon-sandboxing/Include/objimpl.h	(original)
+++ python/branches/bcannon-sandboxing/Include/objimpl.h	Tue Aug  1 01:27:46 2006
@@ -94,18 +94,20 @@
    the object gets initialized via PyObject_{Init, InitVar} after obtaining
    the raw memory.
 */
+#ifdef Py_TRACK_MEMORY
 PyAPI_DATA(unsigned long) Py_ProcessMemUsage;
 PyAPI_FUNC(PyObject *) Py_MemoryUsage(PyObject *, PyObject *);
+PyAPI_FUNC(void *) PyObject_TrackedMalloc(const char *, size_t);
+PyAPI_FUNC(void *) PyObject_TrackedRealloc(const char *, void *, size_t);
+PyAPI_FUNC(void) PyObject_TrackedFree(const char *, void *);
+#endif /* Py_TRACK_MEMORY */
+
 PyAPI_FUNC(int) PyMalloc_ManagesMemory(void *);
 PyAPI_FUNC(size_t) PyMalloc_AllocatedSize(void *);
 PyAPI_FUNC(void *) PyObject_Malloc(size_t);
 PyAPI_FUNC(void *) PyObject_Realloc(void *, size_t);
 PyAPI_FUNC(void) PyObject_Free(void *);
 
-PyAPI_FUNC(void *) PyObject_TrackedMalloc(const char *, size_t);
-PyAPI_FUNC(void *) PyObject_TrackedRealloc(const char *, void *, size_t);
-PyAPI_FUNC(void) PyObject_TrackedFree(const char *, void *);
-
 
 /* Macros */
 #ifdef WITH_PYMALLOC

Modified: python/branches/bcannon-sandboxing/Objects/trackedmalloc.c
==============================================================================
--- python/branches/bcannon-sandboxing/Objects/trackedmalloc.c	(original)
+++ python/branches/bcannon-sandboxing/Objects/trackedmalloc.c	Tue Aug  1 01:27:46 2006
@@ -1,5 +1,11 @@
 #include "Python.h"
+
+/* Must come after Python.h for pyconfig.h value to be set. */
+#ifdef Py_TRACK_MEMORY
+
+#ifdef HAVE_MALLINFO
 #include <malloc.h>
+#endif
 
 /*
     Add accountability to memory allocation.
@@ -46,6 +52,8 @@
 + Raise an error during compilation if required functionality (e.g. mallinfo())
   not available for tracking memory, even if requested.
 + Completely convert ElementTree.
++ Add an adjust function to compliment track/untrack for realloc usage (allows
+  for future usage of tracking active object counts)
 */
 
 unsigned long Py_ProcessMemUsage = 0;
@@ -161,7 +169,9 @@
 void *
 PyObject_TrackedMalloc(const char *what, size_t nbytes)
 {
+#ifdef HAVE_MALLINFO
     struct mallinfo before = mallinfo();
+#endif
     void *allocated = NULL;
     size_t used = 0;
 
@@ -174,7 +184,9 @@
 	used = PyMalloc_AllocatedSize(allocated);
     }
     else {
+#ifdef HAVE_MALLINFO
 	used = mallinfo().uordblks - before.uordblks;
+#endif
     }
 
     PyObject_TrackMemory(what, used);
@@ -190,7 +202,9 @@
 void *
 PyObject_TrackedRealloc(const char *what, void *to_resize, size_t new_size)
 {
+#ifdef HAVE_MALLINFO
     struct mallinfo before = mallinfo();
+#endif
     void *allocated = NULL;
     size_t size_delta = 0;
 
@@ -207,7 +221,9 @@
 	size_delta = PyMalloc_AllocatedSize(allocated) - size_delta;
     }
     else {
+#ifdef HAVE_MALLINFO
 	size_delta = mallinfo().uordblks - before.uordblks;
+#endif
     }
 
     PyObject_TrackMemory(what, size_delta);
@@ -221,7 +237,9 @@
 void
 PyObject_TrackedFree(const char *what, void *to_free)
 {
+#ifdef HAVE_MALLINFO
     struct mallinfo before = mallinfo();
+#endif
     size_t freed = 0;
 
     if (PyMalloc_ManagesMemory(to_free)) {
@@ -231,8 +249,12 @@
     PyObject_Free(to_free);
 
     if (!freed) {
+#ifdef HAVE_MALLINFO
 	freed = before.uordblks - mallinfo().uordblks;
+#endif
     }
 
     PyObject_UntrackMemory(what, freed);
 }
+
+#endif /* Py_TRACK_MEMORY */

Modified: python/branches/bcannon-sandboxing/Python/sysmodule.c
==============================================================================
--- python/branches/bcannon-sandboxing/Python/sysmodule.c	(original)
+++ python/branches/bcannon-sandboxing/Python/sysmodule.c	Tue Aug  1 01:27:46 2006
@@ -782,7 +782,9 @@
 #endif
 	{"settrace",	sys_settrace, METH_O, settrace_doc},
 	{"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
+#ifdef Py_TRACK_MEMORY
 	{"memoryusage", Py_MemoryUsage, METH_NOARGS, "XXX"},
+#endif
 	{NULL,		NULL}		/* sentinel */
 };
 

Modified: python/branches/bcannon-sandboxing/configure
==============================================================================
--- python/branches/bcannon-sandboxing/configure	(original)
+++ python/branches/bcannon-sandboxing/configure	Tue Aug  1 01:27:46 2006
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 50891 .
+# From configure.in Revision: 50892 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.59 for python 2.5.
 #
@@ -3791,6 +3791,61 @@
 echo "${ECHO_T}no" >&6
 fi;
 
+echo "$as_me:$LINENO: checking for mallinfo" >&5
+echo $ECHO_N "checking for mallinfo... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <malloc.h>
+int
+main ()
+{
+void *x=mallinfo
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_MALLINFO 1
+_ACEOF
+
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
 
 # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be
 # merged with this chunk of code?
@@ -13744,7 +13799,6 @@
 echo "$as_me:$LINENO: result: $with_doc_strings" >&5
 echo "${ECHO_T}$with_doc_strings" >&6
 
-# Check for Python-specific malloc support
 echo "$as_me:$LINENO: checking for --with-tsc" >&5
 echo $ECHO_N "checking for --with-tsc... $ECHO_C" >&6
 

Modified: python/branches/bcannon-sandboxing/configure.in
==============================================================================
--- python/branches/bcannon-sandboxing/configure.in	(original)
+++ python/branches/bcannon-sandboxing/configure.in	Tue Aug  1 01:27:46 2006
@@ -740,6 +740,13 @@
 fi],
 [AC_MSG_RESULT(no)])
 
+AC_MSG_CHECKING(for mallinfo)
+AC_TRY_COMPILE([#include <malloc.h>], void *x=mallinfo,
+  AC_DEFINE(HAVE_MALLINFO, 1, Define if you have the 'mallinfo' function.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
+
 
 # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be
 # merged with this chunk of code?
@@ -2171,7 +2178,6 @@
 fi
 AC_MSG_RESULT($with_doc_strings)
 
-# Check for Python-specific malloc support
 AC_MSG_CHECKING(for --with-tsc)
 AC_ARG_WITH(tsc,
 [  --with(out)-tsc         enable/disable timestamp counter profile], [

Modified: python/branches/bcannon-sandboxing/pyconfig.h.in
==============================================================================
--- python/branches/bcannon-sandboxing/pyconfig.h.in	(original)
+++ python/branches/bcannon-sandboxing/pyconfig.h.in	Tue Aug  1 01:27:46 2006
@@ -326,6 +326,9 @@
 /* Define this if you have the makedev macro. */
 #undef HAVE_MAKEDEV
 
+/* Define if you have the 'mallinfo' function. */
+#undef HAVE_MALLINFO
+
 /* Define to 1 if you have the `memmove' function. */
 #undef HAVE_MEMMOVE
 


More information about the Python-checkins mailing list