mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
Extracted out Debug module.
This commit is contained in:
parent
38dfd02f14
commit
57bb9a7469
9
core/Debug.carp
Normal file
9
core/Debug.carp
Normal file
@ -0,0 +1,9 @@
|
||||
(defmodule Debug
|
||||
|
||||
(defdynamic sanitize-addresses []
|
||||
(add-cflag "-fsanitize=address"))
|
||||
|
||||
(register memory-balance (Fn [] Long))
|
||||
(register reset-memory-balance! (Fn [] ()))
|
||||
|
||||
)
|
@ -3,6 +3,4 @@
|
||||
(register free (Fn [t] ()))
|
||||
(register time (Fn [] Int))
|
||||
(register srand (Fn [Int] ()))
|
||||
(register memory-balance (Fn [] Long))
|
||||
(register reset-memory-balance (Fn [] ()))
|
||||
)
|
||||
|
10
core/core.h
10
core/core.h
@ -37,11 +37,11 @@ void logged_free(void *ptr) {
|
||||
#define CARP_MALLOC(size) logged_malloc(size)
|
||||
#define CARP_FREE(ptr) logged_free(ptr)
|
||||
|
||||
long System_memory_MINUS_balance() {
|
||||
long Debug_memory_MINUS_balance() {
|
||||
return malloc_balance_counter;
|
||||
}
|
||||
|
||||
void System_reset_MINUS_memory_MINUS_balance() {
|
||||
void Debug_reset_MINUS_memory_MINUS_balance_BANG_() {
|
||||
malloc_balance_counter = 0;
|
||||
}
|
||||
|
||||
@ -50,14 +50,14 @@ void System_reset_MINUS_memory_MINUS_balance() {
|
||||
#define CARP_MALLOC(size) malloc(size)
|
||||
#define CARP_FREE(ptr) free(ptr)
|
||||
|
||||
long System_memory_MINUS_balance() {
|
||||
long Debug_memory_MINUS_balance() {
|
||||
printf("Error - calling 'memory-balance' without compiling with LOG_MEMORY enabled.\n");
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void System_reset_MINUS_memory_MINUS_balance() {
|
||||
printf("Error - calling 'reset-memory-balance' without compiling with LOG_MEMORY enabled.\n");
|
||||
void Debug_reset_MINUS_memory_MINUS_balance_BANG_() {
|
||||
printf("Error - calling 'reset-memory-balance!' without compiling with LOG_MEMORY enabled.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@
|
||||
* [1.0] Pattern matching on arguments in macros?
|
||||
|
||||
## Tooling
|
||||
* [0.3] Project setting for turning off bound checks and similar.
|
||||
* [0.3] Errors in the parser or emitter don't stop evaluation, only errors during evaluation?
|
||||
* [0.3] Somehow make it possible to enter ":t foo" at the REPL (can't be done now because each atom is evaluated separately)
|
||||
* [0.3] The (project-set! ...) command should accept args of various types, not just String.
|
||||
|
@ -9,11 +9,16 @@
|
||||
(load "Test.carp")
|
||||
(use Test)
|
||||
|
||||
(load "Debug.carp")
|
||||
(use Debug)
|
||||
|
||||
;;(Debug.sanitize-addresses)
|
||||
|
||||
(defn assert-no-leak [state f descr]
|
||||
(do
|
||||
(reset-memory-balance)
|
||||
(Debug.reset-memory-balance!)
|
||||
(f)
|
||||
(assert-equal state 0l (memory-balance) descr)))
|
||||
(assert-equal state 0l (Debug.memory-balance) descr)))
|
||||
|
||||
(defn scope-1 []
|
||||
(let [s @""]
|
||||
@ -91,6 +96,16 @@
|
||||
d (A.s c)]
|
||||
()))
|
||||
|
||||
(defn setting-1 []
|
||||
(let [s @""]
|
||||
(do (set! &s @"")
|
||||
())))
|
||||
|
||||
(defn setting-2 []
|
||||
(let [s @""]
|
||||
(do (set! &s s)
|
||||
())))
|
||||
|
||||
(defn main []
|
||||
(let []
|
||||
(with-test test
|
||||
@ -106,4 +121,6 @@
|
||||
(assert-no-leak test struct-3 "struct-3 does not leak")
|
||||
(assert-no-leak test struct-4 "struct-4 does not leak")
|
||||
(assert-no-leak test struct-5 "struct-5 does not leak")
|
||||
(assert-no-leak test setting-1 "setting-1 does not leak")
|
||||
;;(assert-no-leak test setting-2 "setting-2 does not leak")
|
||||
(print-test-results test))))
|
||||
|
Loading…
Reference in New Issue
Block a user