[llvm-commits] CVS: poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp PoolAllocator.h
Chris Lattner
lattner at cs.uiuc.edu
Mon Nov 1 22:06:58 PST 2004
Changes in directory poolalloc/runtime/FL2Allocator:
FreeListAllocator.cpp updated: 1.15 -> 1.16
PoolAllocator.h updated: 1.9 -> 1.10
---
Log message:
Add a new function, which will allow us to implement realloc correctly.
---
Diffs of the changes: (+23 -0)
Index: poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp
diff -u poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp:1.15 poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp:1.16
--- poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp:1.15 Mon Nov 1 23:56:24 2004
+++ poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp Tue Nov 2 00:06:47 2004
@@ -324,6 +324,28 @@
free(LAH);
}
+void *poolrealloc(PoolTy *Pool, void *Node, unsigned NumBytes) {
+ // If a null pool descriptor is passed in, this is not a pool allocated data
+ // structure. Hand off to the system realloc.
+ if (Pool == 0) return realloc(Node, NumBytes);
+ if (Node == 0) return poolalloc(Pool, NumBytes);
+ if (NumBytes == 0) {
+ poolfree(Pool, Node);
+ return 0;
+ }
+
+ // FIXME: This is obviously much worse than it could be. In particular, we
+ // never try to expand something in a pool. This might hurt some programs!
+ void *New = poolalloc(Pool, NumBytes);
+ assert(New != 0 && "Our poolalloc doesn't ever return null for failure!");
+
+ // Copy the min of the new and old sizes over.
+ unsigned Size = poolobjsize(Pool, Node);
+ memcpy(New, Node, Size < NumBytes ? Size : NumBytes);
+ poolfree(Pool, Node);
+ return New;
+}
+
unsigned poolobjsize(PoolTy *Pool, void *Node) {
if (Node == 0) return 0;
Index: poolalloc/runtime/FL2Allocator/PoolAllocator.h
diff -u poolalloc/runtime/FL2Allocator/PoolAllocator.h:1.9 poolalloc/runtime/FL2Allocator/PoolAllocator.h:1.10
--- poolalloc/runtime/FL2Allocator/PoolAllocator.h:1.9 Mon Nov 1 23:56:24 2004
+++ poolalloc/runtime/FL2Allocator/PoolAllocator.h Tue Nov 2 00:06:47 2004
@@ -95,6 +95,7 @@
void poolmakeunfreeable(PoolTy *Pool);
void pooldestroy(PoolTy *Pool);
void *poolalloc(PoolTy *Pool, unsigned NumBytes);
+ void *poolrealloc(PoolTy *Pool, void *Node, unsigned NumBytes);
void poolfree(PoolTy *Pool, void *Node);
/// poolobjsize - Reutrn the size of the object at the specified address, in
More information about the llvm-commits
mailing list