From 076eed43a278203b3f6f72b23219df391e5a9d44 Mon Sep 17 00:00:00 2001 From: "Deomid \"rojer\" Ryabkov" Date: Wed, 2 Jun 2021 09:44:52 +0100 Subject: [PATCH] Make mjs_gc public https://github.com/cesanta/mjs/issues/173 --- mjs.c | 8 ++------ mjs.h | 24 ++++++++++++++++++++++++ mjs_no_common.c | 32 ++++++++++++++++++++++++++------ src/mjs_builtin.c | 1 + src/mjs_gc.h | 7 +------ src/mjs_gc_public.h | 25 +++++++++++++++++++++++++ src/mjs_sources.mk | 1 + 7 files changed, 80 insertions(+), 18 deletions(-) create mode 100644 src/mjs_gc_public.h diff --git a/mjs.c b/mjs.c index 2c5546c..db89985 100644 --- a/mjs.c +++ b/mjs.c @@ -2888,6 +2888,7 @@ struct gc_arena { /* Amalgamated: #include "mjs_core.h" */ /* Amalgamated: #include "mjs_mm.h" */ /* Amalgamated: #include "mjs_internal.h" */ +/* Amalgamated: #include "mjs_gc_public.h" */ #if defined(__cplusplus) extern "C" { @@ -2907,12 +2908,6 @@ struct gc_cell { } head; }; -/* - * Perform garbage collection. - * Pass true to full in order to reclaim unused heap back to the OS. - */ -void mjs_gc(struct mjs *mjs, int full); - MJS_PRIVATE int gc_strings_is_gc_needed(struct mjs *mjs); /* perform gc if not inhibited */ @@ -7251,6 +7246,7 @@ MJS_PRIVATE void mjs_bcode_commit(struct mjs *mjs) { /* Amalgamated: #include "mjs_core.h" */ /* Amalgamated: #include "mjs_dataview.h" */ /* Amalgamated: #include "mjs_exec.h" */ +/* Amalgamated: #include "mjs_gc.h" */ /* Amalgamated: #include "mjs_internal.h" */ /* Amalgamated: #include "mjs_json.h" */ /* Amalgamated: #include "mjs_object.h" */ diff --git a/mjs.h b/mjs.h index 2df17b6..38de54b 100644 --- a/mjs.h +++ b/mjs.h @@ -661,6 +661,30 @@ void mjs_set_ffi_resolver(struct mjs *mjs, mjs_ffi_resolver_t *dlsym); #endif /* MJS_FFI_PUBLIC_H_ */ #ifdef MJS_MODULE_LINES +#line 1 "src/mjs_gc_public.h" +#endif + +#ifndef MJS_GC_PUBLIC_H_ +#define MJS_GC_PUBLIC_H_ + +/* Amalgamated: #include "mjs_core_public.h" */ + +#if defined(__cplusplus) +extern "C" { +#endif /* __cplusplus */ + +/* + * Perform garbage collection. + * Pass true to full in order to reclaim unused heap back to the OS. + */ +void mjs_gc(struct mjs *mjs, int full); + +#if defined(__cplusplus) +} +#endif /* __cplusplus */ + +#endif /* MJS_GC_PUBLIC_H_ */ +#ifdef MJS_MODULE_LINES #line 1 "src/mjs_object_public.h" #endif diff --git a/mjs_no_common.c b/mjs_no_common.c index ee5e2c7..1bdae37 100644 --- a/mjs_no_common.c +++ b/mjs_no_common.c @@ -713,6 +713,30 @@ struct gc_arena { #endif /* MJS_MM_H_ */ #ifdef MJS_MODULE_LINES +#line 1 "src/mjs_gc_public.h" +#endif + +#ifndef MJS_GC_PUBLIC_H_ +#define MJS_GC_PUBLIC_H_ + +/* Amalgamated: #include "mjs_core_public.h" */ + +#if defined(__cplusplus) +extern "C" { +#endif /* __cplusplus */ + +/* + * Perform garbage collection. + * Pass true to full in order to reclaim unused heap back to the OS. + */ +void mjs_gc(struct mjs *mjs, int full); + +#if defined(__cplusplus) +} +#endif /* __cplusplus */ + +#endif /* MJS_GC_PUBLIC_H_ */ +#ifdef MJS_MODULE_LINES #line 1 "src/mjs_gc.h" #endif @@ -722,6 +746,7 @@ struct gc_arena { /* Amalgamated: #include "mjs_core.h" */ /* Amalgamated: #include "mjs_mm.h" */ /* Amalgamated: #include "mjs_internal.h" */ +/* Amalgamated: #include "mjs_gc_public.h" */ #if defined(__cplusplus) extern "C" { @@ -741,12 +766,6 @@ struct gc_cell { } head; }; -/* - * Perform garbage collection. - * Pass true to full in order to reclaim unused heap back to the OS. - */ -void mjs_gc(struct mjs *mjs, int full); - MJS_PRIVATE int gc_strings_is_gc_needed(struct mjs *mjs); /* perform gc if not inhibited */ @@ -2914,6 +2933,7 @@ MJS_PRIVATE void mjs_bcode_commit(struct mjs *mjs) { /* Amalgamated: #include "mjs_core.h" */ /* Amalgamated: #include "mjs_dataview.h" */ /* Amalgamated: #include "mjs_exec.h" */ +/* Amalgamated: #include "mjs_gc.h" */ /* Amalgamated: #include "mjs_internal.h" */ /* Amalgamated: #include "mjs_json.h" */ /* Amalgamated: #include "mjs_object.h" */ diff --git a/src/mjs_builtin.c b/src/mjs_builtin.c index 607f518..6f51e08 100644 --- a/src/mjs_builtin.c +++ b/src/mjs_builtin.c @@ -7,6 +7,7 @@ #include "mjs_core.h" #include "mjs_dataview.h" #include "mjs_exec.h" +#include "mjs_gc.h" #include "mjs_internal.h" #include "mjs_json.h" #include "mjs_object.h" diff --git a/src/mjs_gc.h b/src/mjs_gc.h index 491bdd0..0ef69dd 100644 --- a/src/mjs_gc.h +++ b/src/mjs_gc.h @@ -9,6 +9,7 @@ #include "mjs_core.h" #include "mjs_mm.h" #include "mjs_internal.h" +#include "mjs_gc_public.h" #if defined(__cplusplus) extern "C" { @@ -28,12 +29,6 @@ struct gc_cell { } head; }; -/* - * Perform garbage collection. - * Pass true to full in order to reclaim unused heap back to the OS. - */ -void mjs_gc(struct mjs *mjs, int full); - MJS_PRIVATE int gc_strings_is_gc_needed(struct mjs *mjs); /* perform gc if not inhibited */ diff --git a/src/mjs_gc_public.h b/src/mjs_gc_public.h new file mode 100644 index 0000000..ff60683 --- /dev/null +++ b/src/mjs_gc_public.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2014 Cesanta Software Limited + * All rights reserved + */ + +#ifndef MJS_GC_PUBLIC_H_ +#define MJS_GC_PUBLIC_H_ + +#include "mjs_core_public.h" + +#if defined(__cplusplus) +extern "C" { +#endif /* __cplusplus */ + +/* + * Perform garbage collection. + * Pass true to full in order to reclaim unused heap back to the OS. + */ +void mjs_gc(struct mjs *mjs, int full); + +#if defined(__cplusplus) +} +#endif /* __cplusplus */ + +#endif /* MJS_GC_PUBLIC_H_ */ diff --git a/src/mjs_sources.mk b/src/mjs_sources.mk index acf58f2..7ca12ea 100644 --- a/src/mjs_sources.mk +++ b/src/mjs_sources.mk @@ -32,6 +32,7 @@ MJS_PUBLIC_HEADERS = \ mjs_core_public.h \ mjs_exec_public.h \ mjs_ffi_public.h \ + mjs_gc_public.h \ mjs_object_public.h \ mjs_primitive_public.h \ mjs_string_public.h \