From 8f550b81085506ab610a30c0dab391262578886e Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 30 Jan 2025 10:38:00 +0100 Subject: [PATCH] [meson] CONFIG_MEMCOUNT separated from CONFIG_DEBUG --- config2.h.in | 3 +++ meson.build | 1 + meson_options.txt | 1 + src/dialogs/info.c | 2 +- src/encoding/brotli.c | 2 +- src/encoding/gzip.c | 2 +- src/encoding/zstd.c | 2 +- src/js/ecmascript.c | 2 +- src/js/mujs.c | 2 +- src/js/quickjs.c | 2 +- src/main/select.c | 8 ++++---- src/terminal/sixel.c | 8 ++++---- src/util/memcount.h | 2 +- src/util/meson.build | 11 +++++++++-- 14 files changed, 30 insertions(+), 18 deletions(-) diff --git a/config2.h.in b/config2.h.in index 0d92a50cb..2722ae97a 100644 --- a/config2.h.in +++ b/config2.h.in @@ -164,6 +164,9 @@ /* Define if you want: Marks support */ #mesondefine CONFIG_MARKS +/* Define if you want: memcount support */ +#mesondefine CONFIG_MEMCOUNT + /* Define if you want: Mimetypes files support */ #mesondefine CONFIG_MIMETYPES diff --git a/meson.build b/meson.build index 1255504a2..744e44a87 100644 --- a/meson.build +++ b/meson.build @@ -62,6 +62,7 @@ conf_data.set('CONFIG_DOM', get_option('html-highlight')) conf_data.set('CONFIG_BACKTRACE', get_option('backtrace')) conf_data.set('CONFIG_NO_ROOT_EXEC', get_option('no-root')) conf_data.set('CONFIG_DEBUG', get_option('withdebug')) +conf_data.set('CONFIG_MEMCOUNT', get_option('memcount')) conf_data.set('CONFIG_FASTMEM', get_option('fastmem')) conf_data.set('CONFIG_OWN_LIBC', get_option('own-libc')) conf_data.set('CONFIG_SMALL', get_option('small')) diff --git a/meson_options.txt b/meson_options.txt index 5bcdcf030..15a5a879f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -33,6 +33,7 @@ option('html-highlight', type: 'boolean', value: false, description: 'HTML highl option('backtrace', type: 'boolean', value: true, description: 'backtrace support') option('no-root', type: 'boolean', value: false, description: 'prevention of usage by root') option('withdebug', type: 'boolean', value: false, description: 'leak debug and internal error checking') +option('memcount', type: 'boolean', value: false, description: 'count memory allocations') option('fastmem', type: 'boolean', value: false, description: 'direct use of system allocation functions, not usable with debug enabled') option('own-libc', type: 'boolean', value: false, description: 'force use of internal functions instead of those of system libc') option('small', type: 'boolean', value: false, description: 'reduce binary size as far as possible (but see the bottom of doc/small.txt!)') diff --git a/src/dialogs/info.c b/src/dialogs/info.c index 9a371ba85..511c394b0 100644 --- a/src/dialogs/info.c +++ b/src/dialogs/info.c @@ -268,7 +268,7 @@ get_resource_info(struct terminal *term, void *data) val = get_number_of_temporary_files(); add_format_to_string(&info, ": %ld.", val); -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT #ifdef CONFIG_BROTLI add_format_to_string(&info, "\nBrotli: calls: %ld active: %ld, size: %ld", get_brotli_total_allocs(), get_brotli_active(), get_brotli_size()); #endif diff --git a/src/encoding/brotli.c b/src/encoding/brotli.c index 1e898a029..768f20b78 100644 --- a/src/encoding/brotli.c +++ b/src/encoding/brotli.c @@ -52,7 +52,7 @@ brotli_open(struct stream_encoded *stream, int fd) if (!data) { return -1; } -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT data->state = BrotliDecoderCreateInstance(el_brotli_alloc, el_brotli_free, NULL); #else data->state = BrotliDecoderCreateInstance(NULL, NULL, NULL); diff --git a/src/encoding/gzip.c b/src/encoding/gzip.c index a39cfa617..47938c290 100644 --- a/src/encoding/gzip.c +++ b/src/encoding/gzip.c @@ -61,7 +61,7 @@ deflate_open(int window_size, struct stream_encoded *stream, int fd) /* Initialize all members of *data, except data->buf[], which * will be initialized on demand by deflate_read. */ copy_struct(&data->deflate_stream, &null_z_stream); -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT data->deflate_stream.zalloc = el_gzip_alloc; data->deflate_stream.zfree = el_gzip_free; #endif diff --git a/src/encoding/zstd.c b/src/encoding/zstd.c index f8d638801..a604f7838 100644 --- a/src/encoding/zstd.c +++ b/src/encoding/zstd.c @@ -49,7 +49,7 @@ zstd_open(struct stream_encoded *stream, int fd) } data->fdread = fd; -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT data->zstd_stream = ZSTD_createDCtx_advanced(el_zstd_mf); #else data->zstd_stream = ZSTD_createDCtx(); diff --git a/src/js/ecmascript.c b/src/js/ecmascript.c index f3178ee18..099bbcdad 100644 --- a/src/js/ecmascript.c +++ b/src/js/ecmascript.c @@ -722,7 +722,7 @@ init_ecmascript_module(struct module *module) #endif } ecmascript_enabled = get_opt_bool("ecmascript.enable", NULL); -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT curl_global_init_mem(CURL_GLOBAL_DEFAULT, el_curl_malloc, el_curl_free, el_curl_realloc, el_curl_strdup, el_curl_calloc); #else curl_global_init(CURL_GLOBAL_DEFAULT); diff --git a/src/js/mujs.c b/src/js/mujs.c index 068251835..427f2adcb 100644 --- a/src/js/mujs.c +++ b/src/js/mujs.c @@ -138,7 +138,7 @@ mujs_get_interpreter(struct ecmascript_interpreter *interpreter) { assert(interpreter); -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT js_State *J = js_newstate(el_mujs_alloc, NULL, 0); #else js_State *J = js_newstate(NULL, NULL, 0); diff --git a/src/js/quickjs.c b/src/js/quickjs.c index 9a1307607..798cb0324 100644 --- a/src/js/quickjs.c +++ b/src/js/quickjs.c @@ -175,7 +175,7 @@ quickjs_init(struct module *module) map_form_elements_rev = attr_create_new_form_elements_map_rev(); //js_module_init_ok = spidermonkey_runtime_addref(); -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT quickjs_runtime = JS_NewRuntime2(&el_quickjs_mf, NULL); #else quickjs_runtime = JS_NewRuntime(); diff --git a/src/main/select.c b/src/main/select.c index ba0f3b913..b51c977f0 100644 --- a/src/main/select.c +++ b/src/main/select.c @@ -860,7 +860,7 @@ enable_libevent(void) return; #endif -#if !defined(EVENT__DISABLE_MM_REPLACEMENT) && defined(CONFIG_DEBUG) +#if !defined(EVENT__DISABLE_MM_REPLACEMENT) && defined(CONFIG_MEMCOUNT) event_set_mem_functions(el_libevent_malloc, el_libevent_realloc, el_libevent_free); #endif @@ -1153,7 +1153,7 @@ select_loop(void (*init)(void)) #if defined(CONFIG_LIBCURL) && defined(CONFIG_LIBEVENT) memset(&g, 0, sizeof(GlobalInfo)); g.evbase = event_base; -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT curl_global_init_mem(CURL_GLOBAL_DEFAULT, el_curl_malloc, el_curl_free, el_curl_realloc, el_curl_strdup, el_curl_calloc); #else curl_global_init(CURL_GLOBAL_DEFAULT); @@ -1176,7 +1176,7 @@ select_loop(void (*init)(void)) #if defined(CONFIG_LIBCURL) && defined(CONFIG_LIBEV) memset(&g, 0, sizeof(GlobalInfo)); g.loop = ev_default_loop(0); -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT curl_global_init_mem(CURL_GLOBAL_DEFAULT, el_curl_malloc, el_curl_free, el_curl_realloc, el_curl_strdup, el_curl_calloc); #else curl_global_init(CURL_GLOBAL_DEFAULT); @@ -1229,7 +1229,7 @@ select_loop(void (*init)(void)) { #if defined(CONFIG_LIBCURL) memset(&g, 0, sizeof(GlobalInfo)); -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT curl_global_init_mem(CURL_GLOBAL_DEFAULT, el_curl_malloc, el_curl_free, el_curl_realloc, el_curl_strdup, el_curl_calloc); #else curl_global_init(CURL_GLOBAL_DEFAULT); diff --git a/src/terminal/sixel.c b/src/terminal/sixel.c index 690bfe868..0ed476400 100644 --- a/src/terminal/sixel.c +++ b/src/terminal/sixel.c @@ -101,7 +101,7 @@ struct sixel_encoder { void *dither_cache; }; -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT static sixel_allocator_t *el_sixel_allocator; static void @@ -858,7 +858,7 @@ add_image_to_document(struct document *doc, struct string *pixels, int lineno, s mem_free(im); return 0; } -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT init_allocator(); status = sixel_decoder_new(&decoder, el_sixel_allocator); #else @@ -943,7 +943,7 @@ copy_frame(struct image *src, struct el_box *box, int cell_width, int cell_heigh mem_free(dest); return NULL; } -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT init_allocator(); status = sixel_decoder_new(&decoder, el_sixel_allocator); #else @@ -1050,7 +1050,7 @@ el_sixel_get_image(char *data, int length, int *outlen) *outlen = 0; #ifdef HAVE_MEMFD_CREATE -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT init_allocator(); status = sixel_encoder_new(&encoder, el_sixel_allocator); #else diff --git a/src/util/memcount.h b/src/util/memcount.h index d63eea54f..1a045b0f3 100644 --- a/src/util/memcount.h +++ b/src/util/memcount.h @@ -1,7 +1,7 @@ #ifndef EL__UTIL_MEMCOUNT_H #define EL__UTIL_MEMCOUNT_H -#ifdef CONFIG_DEBUG +#ifdef CONFIG_MEMCOUNT #ifdef CONFIG_LIBSIXEL #include diff --git a/src/util/meson.build b/src/util/meson.build index d6a4fe605..a3bb469f1 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -6,12 +6,19 @@ endif if conf_data.get('CONFIG_CSS') or conf_data.get('CONFIG_BITTORRENT') srcs += files('scanner.c') endif -if conf_data.get('CONFIG_DEBUG') - srcs += files('memcount.cpp', 'memdebug.c') + +if conf_data.get('CONFIG_MEMCOUNT') + srcs += files('memcount.cpp') endif + +if conf_data.get('CONFIG_DEBUG') + srcs += files('memdebug.c') +endif + if conf_data.get('CONFIG_DOM') srcs += files('scanner.c') endif + if conf_data.get('CONFIG_BITTORRENT') if conf_data.get('CONFIG_OWN_LIBC') or not conf_data.get('CONFIG_OPENSSL') srcs += files('sha1.c')