ref: 6bc30379e7b4d6df3325b44c423ebba9d11792cb
parent: ba3463e82ab17be315609c8a1f61357492e8de39
author: Ori Bernstein <[email protected]>
date: Tue Jul 24 16:43:45 EDT 2012
Make the allocator a bit less crashy. Still crashy, but it crashes later.
--- a/alloc.myr
+++ b/alloc.myr
@@ -27,8 +27,8 @@
;;
type slab = struct
- freehd : bin* /* the nodes we're allocating */
next : slab* /* the next slab on the chain */
+ freehd : bin* /* the nodes we're allocating */
nfree : size /* the number of free nodes */
;;
@@ -103,7 +103,7 @@
/* skip past the slab header */
off = align(sizeof(slab), Align)
bnext = nextbin(s castto(bin*), off)
- s.next = bnext
+ s.freehd = bnext
for i = 0; i < bkt.nper; i++
b = bnext
bnext = nextbin(b, bkt.sz)
@@ -121,7 +121,7 @@
s = bkt.slabs
if s == Zslab
s = mkslab(bkt)
- if !s
+ if s == Zslab
die("No memory left")
;;
bkt.slabs = s
@@ -128,8 +128,8 @@
;;
/* grab the first bin on the slab */
- b = s.next
- s.next = b.next
+ b = s.freehd
+ s.freehd = b.next
s.nfree--
if !s.nfree
bkt.slabs = s.next
--- a/hello.myr
+++ b/hello.myr
@@ -3,7 +3,11 @@
const main = {
var x
- x = std.bytealloc(32)
+ var i
+
+ for i = 0; i < 200; i++
+ x = std.bytealloc(32)
+ ;;
std.bytefree(x, 32)
std.write(1, "Hello world\n")
}