[Commit] nickle mem.h,1.11,1.12

Keith Packard commit at keithp.com
Sun Jun 29 12:15:29 PDT 2003


Committed by: keithp

Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv29614

Modified Files:
	mem.h 
Log Message:
Set data type after reference in allocate to avoid walking uninit structs

Index: mem.h
===================================================================
RCS file: /local/src/CVS/nickle/mem.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- mem.h	29 May 2003 18:36:35 -0000	1.11
+++ mem.h	29 Jun 2003 18:15:27 -0000	1.12
@@ -60,6 +60,7 @@
 extern void	MemInitialize (void);
 #ifndef HAVE_C_INLINE
 extern void	*MemAllocate (DataType *type, int size);
+extern void	*MemAllocateRef (DataType *type, int size);
 #endif
 extern void	MemFree (void *object, int size);
 extern void	*MemAllocateHuge (DataType *type, int size);
@@ -90,7 +91,7 @@
 
 #define REFERENCE(o)	    STACK_PUSH(MemStack, (o))
 #define ENTER()		    StackPointer    __stackPointer = STACK_TOP(MemStack)
-#define ALLOCATE(type,size) REFERENCE(MemAllocate(type,size))
+#define ALLOCATE(type,size) MemAllocateRef(type,size);
 #define EXIT()		    STACK_RESET(MemStack, __stackPointer)
 #define RETURN(r)	    return (STACK_RETURN (MemStack, __stackPointer, (r)))
 #define NOREFRETURN(r)	    return (EXIT(), (r))
@@ -102,11 +103,11 @@
  */
 
 #ifdef HAVE_C_INLINE
-static inline void *
+static inline struct bfree *
 #else
-void *
+static struct bfree *
 #endif
-MemAllocate (DataType *type, int size)
+_MemAllocateInt (DataType *type, int size)
 {
     int	sizeIndex = 0;
     struct bfree    *new;
@@ -138,11 +139,37 @@
     if (!new)
 	new = MemHunkMore (sizeIndex);
     freeList[sizeIndex] = new->next;
-/*    if (sizeIndex >= 6)
-	memset (new, '\0', size); */
+    return new;
+}
+
+#ifdef HAVE_C_INLINE
+static inline void *
+#else
+void *
+#endif
+MemAllocateRef (DataType *type, int size)
+{
+    struct bfree    *new = _MemAllocateInt (type, size);
+
+    new->type = 0;
+    REFERENCE (new);
     new->type = type;
     return (void *) new;
 }
+
+#ifdef HAVE_C_INLINE
+static inline void *
+#else
+void *
+#endif
+MemAllocate (DataType *type, int size)
+{
+    struct bfree    *new = _MemAllocateInt (type, size);
+
+    new->type = type;
+    return (void *) new;
+}
+
 #endif
 
 #endif /* _MEM_H_ */




More information about the Commit mailing list