mirror of
https://github.com/Orc/discount.git
synced 2026-09-25 04:10:00 +03:00
1. Add the new amalloc module, which (if enabled with
--enable-amalloc) replaced malloc and its ilk with
versions that attempt to maintain a linked list of
allocated blocks that can be printed to stderr with
the `adump()` function.
2. Clean up a couple more places where I leak memory
during the first level parse.
3. tweak cstring.h to try to chase down places where
the C compiler might optimize EXPAND() into producing
broken code.
This commit is contained in:
@@ -10,16 +10,17 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "amalloc.h"
|
||||
|
||||
/* expandable Pascal-style string.
|
||||
*/
|
||||
#define STRING(type) struct { type *text; int size, alloc; }
|
||||
|
||||
#define RESERVE(x,c) (x).text = malloc(sizeof T(x)[0] * (((x).size=0),((x).alloc=(c))) )
|
||||
#define CREATE(x) RESERVE(x,100)
|
||||
#define EXPAND(x) (x).text[((x).size < (x).alloc \
|
||||
? 0 \
|
||||
: !((x).text = realloc((x).text, sizeof T(x)[0] * ((x).alloc += 100)))), \
|
||||
(x).size++]
|
||||
#define EXPAND(x) ((x).size++)[((x).size < (x).alloc) \
|
||||
? (x).text \
|
||||
: (x).text = realloc((x).text, sizeof T(x)[0] * ((x).alloc += 100))]
|
||||
|
||||
#define DELETE(x) (x).alloc ? (free(T(x)), S(x) = (x).alloc = 0) \
|
||||
: ( S(x) = 0 )
|
||||
|
||||
Reference in New Issue
Block a user