Fix current memory issues
This commit is contained in:
41
src/lisp.h
41
src/lisp.h
@ -347,7 +347,7 @@ static inline LispVal *_internal_INTERN_STATIC(const char *name, size_t len) {
|
||||
DECLARE_FUNCTION(sethead, (LispVal * pair, LispVal *head));
|
||||
DECLARE_FUNCTION(settail, (LispVal * pair, LispVal *tail));
|
||||
size_t list_length(LispVal *obj);
|
||||
static inline LispVal *const_list(int len, ...) {
|
||||
static inline LispVal *const_list(bool do_ref, int len, ...) {
|
||||
LispVal *list = Qnil;
|
||||
LispVal *end;
|
||||
va_list args;
|
||||
@ -363,6 +363,9 @@ static inline LispVal *const_list(int len, ...) {
|
||||
refcount_unref(new_end);
|
||||
end = new_end;
|
||||
}
|
||||
if (!do_ref) {
|
||||
refcount_unref(((LispPair *) end)->head);
|
||||
}
|
||||
}
|
||||
va_end(args);
|
||||
return list;
|
||||
@ -418,13 +421,16 @@ struct UnrefListData {
|
||||
void unref_free_list_double_ptr(void *ptr);
|
||||
void unref_double_ptr(void *ptr);
|
||||
void cancel_cleanup(void *handle);
|
||||
#define WITH_PUSH_FRAME(name, detail, inherit, body) \
|
||||
stack_enter(name, detail, inherit); \
|
||||
if (setjmp(the_stack->start) == 0) { \
|
||||
body \
|
||||
} \
|
||||
#define WITH_PUSH_FRAME_NO_REF(name, detail, inherit, body) \
|
||||
stack_enter(name, detail, inherit); \
|
||||
if (setjmp(the_stack->start) == 0) { \
|
||||
body \
|
||||
} \
|
||||
stack_leave();
|
||||
#define WITH_CLEANUP(var, body) \
|
||||
#define WITH_PUSH_FRAME(name, detail, inherit, body) \
|
||||
WITH_PUSH_FRAME_NO_REF(refcount_ref(name), refcount_ref(detail), inherit, \
|
||||
body)
|
||||
#define WITH_CLEANUP_DOUBLE_PTR(var, body) \
|
||||
{ \
|
||||
void *__with_cleanup_cleanup = register_cleanup( \
|
||||
(lisp_cleanup_func_t) & unref_double_ptr, &(var)); \
|
||||
@ -432,6 +438,14 @@ void cancel_cleanup(void *handle);
|
||||
cancel_cleanup(__with_cleanup_cleanup); \
|
||||
refcount_unref(var); \
|
||||
}
|
||||
#define WITH_CLEANUP(var, body) \
|
||||
{ \
|
||||
void *__with_cleanup_cleanup = \
|
||||
register_cleanup(&refcount_unref_as_callback, (var)); \
|
||||
{body}; \
|
||||
cancel_cleanup(__with_cleanup_cleanup); \
|
||||
refcount_unref(var); \
|
||||
}
|
||||
|
||||
DECLARE_FUNCTION(backtrace, (void) );
|
||||
noreturn DECLARE_FUNCTION(throw, (LispVal * signal, LispVal *rest));
|
||||
@ -449,12 +463,13 @@ extern LispVal *Qinvalid_function_error;
|
||||
extern LispVal *Qno_applicable_method_error;
|
||||
|
||||
LispVal *predicate_for_type(LispType type);
|
||||
#define CHECK_TYPE(type, val) \
|
||||
if (TYPEOF(val) != type) { \
|
||||
LispVal *inner_list = const_list(1, predicate_for_type(type)); \
|
||||
LispVal *args = const_list(2, inner_list, Ftype_of(LISPVAL(val))); \
|
||||
refcount_unref(inner_list); \
|
||||
Fthrow(Qtype_error, args); \
|
||||
#define CHECK_TYPE(type, val) \
|
||||
if (TYPEOF(val) != type) { \
|
||||
LispVal *inner_list = const_list(false, 1, predicate_for_type(type)); \
|
||||
LispVal *args = \
|
||||
const_list(true, 2, inner_list, Ftype_of(LISPVAL(val))); \
|
||||
refcount_unref(inner_list); \
|
||||
Fthrow(Qtype_error, args); \
|
||||
}
|
||||
|
||||
extern LispVal *Vobarray;
|
||||
|
Reference in New Issue
Block a user