加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
scratchpad.h 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
luanhailiang 提交于 2012-08-09 20:44 . My mudos
#ifndef _SCRATCHPAD_H
#define _SCRATCHPAD_H
/* Tim Hollebeek
*
* The data must also consist of zero terminated chunks, with lengths in the
* range 0 < len < 256. Longer things can be handled, but they're just
* malloc'ed.
*
* Designed to be used by the compile stack (if pointers get popped off due
* to errors, we don't have to worry about them b/c we'll reclaim the space
* when we throw away the scratchpad; this is another advantage), it could
* be used by other things as well.
*/
#define SCRATCHPAD_SIZE 4096
#define SDEBUG(x)
#define SDEBUG2(x)
#define SCRATCH_MAGIC ((unsigned char)0xbb)
typedef struct sp_block_s {
struct sp_block_s *next, *prev;
char block[2]; /* block[0] must be nonzero, usually SCRATCH_MAGIC */
} sp_block_t;
#define scratch_free_last() \
scr_tail = --scr_last; \
scr_last -= *scr_tail; \
while (!(*scr_last) && scr_tail != scr_last) { \
/* check if the one before was already freed */ \
scr_tail = --scr_last; \
scr_last -= *scr_tail; \
}
extern unsigned char *scr_last;
extern unsigned char *scr_tail;
extern unsigned char *scratch_end;
/*
* scratchpad.c
*/
void scratch_destroy PROT((void));
char *scratch_copy PROT((char *));
char *scratch_alloc PROT((int));
void scratch_free PROT((char *));
char *scratch_join PROT((char *, char *));
char *scratch_join2 PROT((char *, char *));
char *scratch_realloc PROT((char *, int));
char *scratch_copy_string PROT((char *));
char *scratch_large_alloc PROT((int));
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化