File 8481-ycf-Remove-GC-support.patch of Package erlang
From 63367d9f76786fc7b9fdd70df56351f9a8e847fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Backstr=C3=B6m?= <lukas@erlang.org>
Date: Tue, 1 Apr 2025 21:30:18 +0200
Subject: [PATCH] ycf: Remove GC support
The GC support is never used in Erlang/OTP so we remove
it in order to reduce the number of vendored dependencies
we have.
---
erts/lib_src/yielding_c_fun/GNUmakefile | 17 +-
erts/lib_src/yielding_c_fun/Makefile | 25 +-
erts/lib_src/yielding_c_fun/README.md | 15 +-
.../yielding_c_fun/lib/simple_c_gc/.gitignore | 11 -
.../lib/simple_c_gc/.misc/clang_blacklist.txt | 10 -
.../lib/simple_c_gc/GIT_VERSION | 73 ----
.../yielding_c_fun/lib/simple_c_gc/LICENSE | 201 ----------
.../yielding_c_fun/lib/simple_c_gc/Makefile | 121 ------
.../yielding_c_fun/lib/simple_c_gc/README.md | 69 ----
.../lib/simple_c_gc/chained_hash_set.h | 307 ---------------
.../lib/simple_c_gc/simple_c_gc.c | 310 ---------------
.../lib/simple_c_gc/simple_c_gc.h | 57 ---
.../lib/simple_c_gc/sorted_list_set.h | 370 ------------------
.../yielding_c_fun/lib/simple_c_gc/test.c | 53 ---
erts/lib_src/yielding_c_fun/main_target.mk | 11 +-
erts/lib_src/yielding_c_fun/ycf_main.c | 28 +-
erts/lib_src/yielding_c_fun/ycf_utils.c | 13 +-
erts/lib_src/yielding_c_fun/ycf_utils.h | 1 -
18 files changed, 24 insertions(+), 1668 deletions(-)
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/.gitignore
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/.misc/clang_blacklist.txt
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/GIT_VERSION
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/LICENSE
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/Makefile
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/README.md
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/chained_hash_set.h
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/simple_c_gc.c
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/simple_c_gc.h
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/sorted_list_set.h
delete mode 100644 erts/lib_src/yielding_c_fun/lib/simple_c_gc/test.c
diff --git a/erts/lib_src/yielding_c_fun/GNUmakefile b/erts/lib_src/yielding_c_fun/GNUmakefile
index 2706571d06..c887ad2091 100644
--- a/erts/lib_src/yielding_c_fun/GNUmakefile
+++ b/erts/lib_src/yielding_c_fun/GNUmakefile
@@ -46,24 +46,19 @@ ifdef CC_32_BIT
EXTRA_C_FLAGS = -m32 -g -O03 -std=c99 -pedantic -Wall
endif
-ifdef USE_GC
- USE_GC_STRING = -use_gc
-endif
-
ifdef ADD_SAN
V_CC = clang
- EXTRA_C_FLAGS = -std=c99 -Wall -pedantic -g -O00 -fsanitize-blacklist=lib/simple_c_gc/.misc/clang_blacklist.txt -fsanitize=address -fno-omit-frame-pointer
- USE_GC_STRING = -use_gc
+ EXTRA_C_FLAGS = -std=c99 -Wall -pedantic -g -O00 -fsanitize=address -fno-omit-frame-pointer
endif
ifdef MEM_SAN
V_CC = clang
- EXTRA_C_FLAGS = -std=c99 -Wall -pedantic -g -O00 -fsanitize-blacklist=lib/simple_c_gc/.misc/clang_blacklist.txt -fsanitize=memory -fno-omit-frame-pointer
+ EXTRA_C_FLAGS = -std=c99 -Wall -pedantic -g -O00 -fsanitize=memory -fno-omit-frame-pointer
endif
ifdef UB_SAN
V_CC = clang
- EXTRA_C_FLAGS = -std=c99 -Wall -pedantic -g -O00 -fsanitize-blacklist=lib/simple_c_gc/.misc/clang_blacklist.txt -fsanitize=undefined -fno-omit-frame-pointer
+ EXTRA_C_FLAGS = -std=c99 -Wall -pedantic -g -O00 -fsanitize=undefined -fno-omit-frame-pointer
endif
@@ -133,7 +128,7 @@ Makefile: $(YCF_SOURCES)
.PHONY: all clean test run_test_continusly CMakeLists.txt cmake_compile clang_format test_add_san test_mem_san test_modern_cc test_sanitizers test_gcc_clang_tcc clang_tidy test_bmake test_all
test: $(YCF_EXECUTABLE)
- ./test/test.sh $(USE_GC_STRING) ;\
+ ./test/test.sh;\
RESULT=$$? &&\
(exit $$RESULT) &&\
printf "\n\n\033[0;32mALL TESTS PASSED!\033[0m\n\n\n" ||\
@@ -194,13 +189,13 @@ cmake_compile: CMakeLists.txt
cd cmake_mkdir && cmake ..
clang_tidy:
- (ls *.c ; echo lib/simple_c_gc/simple_c_gc.c) | xargs -I{} -n1 clang-tidy -warnings-as-errors=* {} -- $(YCF_INCLUDE_DIRS) $(YCF_CFLAGS)
+ (ls *.c) | xargs -I{} -n1 clang-tidy -warnings-as-errors=* {} -- $(YCF_INCLUDE_DIRS) $(YCF_CFLAGS)
clang_format:
clang-format -style="{BasedOnStyle: LLVM}" -i *.c *.h
clean:
- rm -f lib/simple_c_gc/*.o ./*.o ./*~ core trap parse $(YCF_EXECUTABLE) CMakeLists.txt
+ rm -f ./*.o ./*~ core trap parse $(YCF_EXECUTABLE) CMakeLists.txt
# Produce a CMakeLists.txt to build with cmake
CMakeLists.txt: $(YCF_SOURCES)
diff --git a/erts/lib_src/yielding_c_fun/Makefile b/erts/lib_src/yielding_c_fun/Makefile
index c3bcc7a452..57c13e9bea 100644
--- a/erts/lib_src/yielding_c_fun/Makefile
+++ b/erts/lib_src/yielding_c_fun/Makefile
@@ -16,36 +16,33 @@
# building YCF independently of Erlang/OTP.
#
-./bin/yielding_c_fun.bin: simple_c_gc.o ycf_lexer.o ycf_main.o ycf_node.o ycf_parser.o ycf_printers.o ycf_string.o ycf_symbol.o ycf_utils.o ycf_yield_fun.o
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -o ./bin/yielding_c_fun.bin simple_c_gc.o ycf_lexer.o ycf_main.o ycf_node.o ycf_parser.o ycf_printers.o ycf_string.o ycf_symbol.o ycf_utils.o ycf_yield_fun.o
-
-simple_c_gc.o: ./lib/simple_c_gc/simple_c_gc.c
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -c -o simple_c_gc.o ./lib/simple_c_gc/simple_c_gc.c
+./bin/yielding_c_fun.bin: ycf_lexer.o ycf_main.o ycf_node.o ycf_parser.o ycf_printers.o ycf_string.o ycf_symbol.o ycf_utils.o ycf_yield_fun.o
+ $(CC) -I. $(CFLAGS) -o ./bin/yielding_c_fun.bin ycf_lexer.o ycf_main.o ycf_node.o ycf_parser.o ycf_printers.o ycf_string.o ycf_symbol.o ycf_utils.o ycf_yield_fun.o
ycf_lexer.o: ./ycf_lexer.c
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -c -o ycf_lexer.o ./ycf_lexer.c
+ $(CC) -I. $(CFLAGS) -c -o ycf_lexer.o ./ycf_lexer.c
ycf_main.o: ./ycf_main.c
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -c -o ycf_main.o ./ycf_main.c
+ $(CC) -I. $(CFLAGS) -c -o ycf_main.o ./ycf_main.c
ycf_node.o: ./ycf_node.c
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -c -o ycf_node.o ./ycf_node.c
+ $(CC) -I. $(CFLAGS) -c -o ycf_node.o ./ycf_node.c
ycf_parser.o: ./ycf_parser.c
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -c -o ycf_parser.o ./ycf_parser.c
+ $(CC) -I. $(CFLAGS) -c -o ycf_parser.o ./ycf_parser.c
ycf_printers.o: ./ycf_printers.c
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -c -o ycf_printers.o ./ycf_printers.c
+ $(CC) -I. $(CFLAGS) -c -o ycf_printers.o ./ycf_printers.c
ycf_string.o: ./ycf_string.c
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -c -o ycf_string.o ./ycf_string.c
+ $(CC) -I. $(CFLAGS) -c -o ycf_string.o ./ycf_string.c
ycf_symbol.o: ./ycf_symbol.c
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -c -o ycf_symbol.o ./ycf_symbol.c
+ $(CC) -I. $(CFLAGS) -c -o ycf_symbol.o ./ycf_symbol.c
ycf_utils.o: ./ycf_utils.c
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -c -o ycf_utils.o ./ycf_utils.c
+ $(CC) -I. $(CFLAGS) -c -o ycf_utils.o ./ycf_utils.c
ycf_yield_fun.o: ./ycf_yield_fun.c
- $(CC) -I. -I./lib/simple_c_gc $(CFLAGS) -c -o ycf_yield_fun.o ./ycf_yield_fun.c
+ $(CC) -I. $(CFLAGS) -c -o ycf_yield_fun.o ./ycf_yield_fun.c
diff --git a/erts/lib_src/yielding_c_fun/README.md b/erts/lib_src/yielding_c_fun/README.md
index 8e47fbcacc..5b7ffba63a 100644
--- a/erts/lib_src/yielding_c_fun/README.md
+++ b/erts/lib_src/yielding_c_fun/README.md
@@ -86,8 +86,7 @@ Command Line Parameters
```
Usage: yielding_c_fun [-h]
- yielding_c_fun [-use_gc [-print_gc_info]]
- [-log_max_mem_usage log_file]
+ yielding_c_fun [-log_max_mem_usage log_file]
[(( -f | -frec | -fnoauto ) function_name)...
[-output_file_name output_file]
[-header_file_name header_file]
@@ -101,18 +100,6 @@ Usage: yielding_c_fun [-h]
Print help text
-* `-use_gc`
-
- Use garbage collection. The garbage collection system assumes that
- the C call stack consists of a continuous memory block and is
- therefore not enabled by default even though this assumption is
- valid on all major platforms. YCF does not reclaim any allocated
- memory if the `-use_gc` flag is not set.
-
-* `-print_gc_info`
-
- (For debugging) Print garbage collection information to `stderr`
-
* `-log_max_mem_usage log_file`
(For debugging) Print the peak memory usage of the tool to the file
diff --git a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/.misc/clang_blacklist.txt b/erts/lib_src/yielding_c_fun/lib/simple_c_gc/.misc/clang_blacklist.txt
deleted file mode 100644
index d212057d10..0000000000
--- a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/.misc/clang_blacklist.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-
-[memory]
-
-fun:scgc_mark_reachable_objects_in_region
-fun:reverse_bits
-
-[address]
-
-fun:scgc_mark_reachable_objects_in_region
-fun:reverse_bits
diff --git a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/GIT_VERSION b/erts/lib_src/yielding_c_fun/lib/simple_c_gc/GIT_VERSION
deleted file mode 100644
index 8cd6ceac63..0000000000
--- a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/GIT_VERSION
+++ /dev/null
@@ -1,73 +0,0 @@
-origin https://github.com/kjellwinblad/simple_c_gc.git (fetch)
-origin https://github.com/kjellwinblad/simple_c_gc.git (push)
-commit 76577516b6e9bd8e8f647d869fb19361f42f9f9f
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Wed Sep 25 16:04:40 2019 +0200
-
- Fix more Microsoft VS C/C++ compiler errors
-
-commit 4b2734f051ca1386bb970af6b0308e5f2d338403
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Tue Sep 24 16:36:48 2019 +0200
-
- Make compatible with Microsoft VS C/C++ compiler and fix make test
-
-commit 41e6f3558756d9b6da44ca5247049c23bceadad9
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Mon Sep 23 16:25:55 2019 +0200
-
- Small fix
-
-commit 8fbd03f880a1eb741462c395e689d844f8d58e06
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Mon Sep 23 16:13:56 2019 +0200
-
- Fix compile warnings when compiling on a 32-bit system
-
-commit fc051d92bbef9ad1a22f855bc24b46d4efadda93
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Tue Sep 10 15:14:20 2019 +0200
-
- Add clang-tidy Makefile target
-
-commit c6c3c1adc24f500472c22aad7f467d0a925108f0
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Tue Sep 10 15:07:39 2019 +0200
-
- Add undefined behavior sanitizer and fix undefined behavior
-
-commit c734e684030a24ae694ed1fe7477c0eb5719bc12
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Mon Sep 9 09:06:19 2019 +0200
-
- Improve Makefile and add info support
-
-commit 286c6ace1a71f2b021b76b602d5bfe4813f0b519
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Thu Sep 5 12:08:19 2019 +0200
-
- Make clang_format target .PHONY
-
-commit eacdda4f9c71b5d917111bb9285671739d1cb671
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Thu Sep 5 11:33:03 2019 +0200
-
- Add clang-format make target and reformat files
-
-commit c617afa556535620633117bdd6cc232ecc8c62f2
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Thu Sep 5 11:07:17 2019 +0200
-
- Small fixes
-
-commit fb043e17d6e63100ca89ec41c34f667d35da7fb8
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Thu Sep 5 10:55:18 2019 +0200
-
- Fix compiler warning and make c99 compatible
-
-commit d4b8333a49e62d8ffdbf60ab8382de39209891e2
-Author: Kjell Winblad <kjellwinblad@gmail.com>
-Date: Sat Aug 17 05:59:27 2019 +0200
-
- First version of Simple C GC
diff --git a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/LICENSE b/erts/lib_src/yielding_c_fun/lib/simple_c_gc/LICENSE
deleted file mode 100644
index 261eeb9e9f..0000000000
--- a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/LICENSE
+++ /dev/null
@@ -1,201 +0,0 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/Makefile b/erts/lib_src/yielding_c_fun/lib/simple_c_gc/Makefile
deleted file mode 100644
index 1b326a9988..0000000000
--- a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/Makefile
+++ /dev/null
@@ -1,121 +0,0 @@
-IDIR = .
-CC = cc
-
-ifdef MODERN_CC
- EXTRA_C_FLAGS = -g -O03 -std=c99 -pedantic -Wall
-endif
-
-ifdef CC_32_BIT
- EXTRA_C_FLAGS = -m32 -g -O03 -std=c99 -pedantic -Wall
-endif
-
-ifdef ADD_SAN
- CC = clang
- EXTRA_C_FLAGS = -std=c99 -Wall -pedantic -g -O00 -fsanitize-blacklist=.misc/clang_blacklist.txt -fsanitize=address -fno-omit-frame-pointer
- USE_GC_STRING = -use_gc
-endif
-
-ifdef MEM_SAN
- CC = clang
- EXTRA_C_FLAGS = -std=c99 -Wall -pedantic -g -O00 -fsanitize-blacklist=.misc/clang_blacklist.txt -fsanitize=memory -fno-omit-frame-pointer
-endif
-
-ifdef UB_SAN
- CC = clang
- EXTRA_C_FLAGS = -std=c99 -Wall -pedantic -g -O00 -fsanitize-blacklist=.misc/clang_blacklist.txt -fsanitize=undefined -fno-omit-frame-pointer
-endif
-
-CFLAGS = -I$(IDIR) $(EXTRA_C_FLAGS)
-
-ODIR = .
-LDIR =
-
-_DEPS = bitreversal.h simple_c_gc.h chained_hash_set.h sorted_list_set.h
-DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
-
-_OBJ = simple_c_gc.o test.o
-OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
-C_FILES = $(patsubst %.o,%.c,$(_OBJ))
-
-$(ODIR)/%.o: %.c $(DEPS)
- $(CC) -c -o $@ $< $(CFLAGS)
-
-test.bin: $(OBJ)
- $(CC) -o $@ $^ $(CFLAGS)
-
-
-.PHONY: clean test run_test_continusly CMakeLists.txt cmake_compile clang_format test_add_san test_ub_san test_mem_san test_sanitizers test_modern_cc test_valgrind
-
-test: test.bin
- ./test.bin ;\
- RESULT=$$? &&\
- (exit $$RESULT) &&\
- printf "\n\n\033[0;32mALL TESTS PASSED!\033[0m\n\n\n" ||\
- printf "\n\n\033[0;31mTEST FAILED!\033[0m\n\n\n" &&\
- exit $$RESULT
-
-test_valgrind:
- make clean && \
- make EXTRA_C_FLAGS="-g -O01" && \
- valgrind --undef-value-errors=no ./test.bin ;\
- RESULT=$$? &&\
- (exit $$RESULT) &&\
- printf "\n\n\033[0;32mALL TESTS PASSED!\033[0m\n\n\n" ||\
- printf "\n\n\033[0;31mTEST FAILED!\033[0m\n\n\n" &&\
- exit $$RESULT
-
-test_add_san:
- make clean && \
- make ADD_SAN=1 test
-
-test_mem_san:
- make clean && \
- make MEM_SAN=1 test
-
-test_ub_san:
- make clean && \
- make UB_SAN=1 test
-
-test_sanitizers:
- make test_add_san && \
- make test_mem_san && \
- make test_ub_san
-
-test_modern_cc:
- make clean && \
- make MODERN_CC=1 test
-
-test_32_bit:
- make clean && \
- make CC_32_BIT=1 test && \
- make clean
-
-test_all:
- make test_valgrind && \
- make test_sanitizers && \
- make test_modern_cc && \
- make test_32_bit
-
-run_test_continusly:
- inotifywait -e close_write,moved_to,create -m ./*.c ./*.h | while read -r directory events filename; do gtags ; make test ; done
-
-CMakeLists.txt: $(C_FILES)
- echo "cmake_minimum_required (VERSION 2.6)" > CMakeLists.txt
- echo "project (SIMPLE_C_GC)" >> CMakeLists.txt
- echo "add_executable(cmake.out" >> CMakeLists.txt
- echo $(C_FILES) >> CMakeLists.txt
- echo ")" >> CMakeLists.txt
-
-
-cmake_compile: CMakeLists.txt
- mkdir cmake_mkdir || true
- cd cmake_mkdir && cmake ..
-
-clang_tidy:
- ls *.c | xargs -I{} -n1 clang-tidy -warnings-as-errors=* {} -- $(CFLAGS)
-
-clang_format:
- clang-format -style="{BasedOnStyle: LLVM}" -i *.c *.h
-
-clean:
- rm -f $(ODIR)/*.o *~ core $(IDIR)/*~ test.bin CMakeLists.txt
diff --git a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/README.md b/erts/lib_src/yielding_c_fun/lib/simple_c_gc/README.md
deleted file mode 100644
index c1f6834505..0000000000
--- a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/README.md
+++ /dev/null
@@ -1,69 +0,0 @@
-Simple C GC
-===========
-
-This is the readme file for Simple C GC. Simple C GC is a simple
-garbage collection system for the C programming language inspired by
-[Daniel Holden's article about Cello's garbage collection
-system](http://libcello.org/learn/garbage-collection).
-
-Usage
------
-
-The interface of Simple C GC consists of only two functions:
-
-```C
-/**
- * This function starts code that will be garbage collected
- *
- * @param main The function that will be started and garbage collected
- * @param argc Passed to main
- * @param argv Passed to main
- * @param my_malloc Simple C GC will use this to allocated memory
- * @param my_free Simple C GC will use this to free memory
- */
-int scgc_start_gced_code(int (*main)(int, char *[]),
- int argc,
- char *argv[],
- void* (*my_malloc)( size_t ),
- void (*my_free)( void* ));
-
-/**
- * Allocate a new memory block that will be garbage collected
- *
- * @param size The size of the new memory block
- */
-void* scgc_new(size_t size);
-```
-
-An example that illustrates how these functions can be used in
-practice is located in the `test.c` file.
-
-
-Notes
------
-
-The garbage collector assumes that all data that should be garbage
-collected is pointed to directly or indirectly from the "C stack" and
-that the "C stack" is implemented as a continuous block of memory.
-
-Compile and Test
-----------------
-
- make test
-
-License
--------
-
- Copyright 2019 Kjell Winblad (kjellwinblad@gmail.com, http://winsh.me)
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
\ No newline at end of file
diff --git a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/chained_hash_set.h b/erts/lib_src/yielding_c_fun/lib/simple_c_gc/chained_hash_set.h
deleted file mode 100644
index ee508e5ccc..0000000000
--- a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/chained_hash_set.h
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * %CopyrightBegin%
- *
- * Copyright 2019 Kjell Winblad (kjellwinblad@gmail.com, http://winsh.me).
- * All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * %CopyrightEnd%
- */
-
-/*
- *
- * Author: Kjell Winblad
- *
- */
-
-#ifndef CHAINED_HASH_SET_H
-#define CHAINED_HASH_SET_H
-
-
-#if defined(_MSC_VER)
-#define inline __inline
-#endif
-
-#include "sorted_list_set.h"
-#include <stdint.h>
-
-#define CHAIN_LENGHT_EXPAND_THRESHOLD 2
-#define CHAIN_LENGHT_SHRINK_THRESHOLD 0.5
-/*Must be power of two*/
-#define INITIAL_NUMBER_OF_BUCKETS 4
-
-typedef struct {
- unsigned int keyPosition;
- void *(*extract_key)(void *v, int keyPos);
- unsigned int (*hash_key)(void *key);
- bool (*are_equal)(void *v1, void *v2);
- char *(*to_string)(void *v1);
- void *(*malloc)(size_t size);
- void (*free)(void *ptr);
- unsigned int numberOfBuckets;
- unsigned int expandTreshold;
- unsigned int shrinkTreshold;
- unsigned int size;
- SortedListSetNode **buckets;
-} ChainedHashSet;
-
-/*
- * The reverse_bits function is inspired by:
- * https://stackoverflow.com/questions/746171/efficient-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c
- */
-static const unsigned char BitReverseTable256[] = {
- 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0,
- 0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
- 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4,
- 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
- 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC,
- 0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
- 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA,
- 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
- 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6,
- 0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
- 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1,
- 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
- 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9,
- 0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
- 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD,
- 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
- 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3,
- 0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
- 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7,
- 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
- 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF,
- 0x3F, 0xBF, 0x7F, 0xFF};
-
-static inline uint32_t reverse_bits(uint32_t v) {
- return (((uint32_t)BitReverseTable256[v & 0xff]) << 24) |
- (((uint32_t)BitReverseTable256[(v >> 8) & 0xff]) << 16) |
- (((uint32_t)BitReverseTable256[(v >> 16) & 0xff]) << 8) |
- (((uint32_t)BitReverseTable256[(v >> 24) & 0xff]));
-}
-
-static inline void ch_set_increase_size(ChainedHashSet *set) {
- set->size = set->size + 1;
- if (set->size > set->expandTreshold) {
- unsigned int oldNumberOfBuckets = set->numberOfBuckets;
- unsigned int newNumberOfBuckets = oldNumberOfBuckets * 2;
- unsigned int splitUpMask = reverse_bits(newNumberOfBuckets - 1) ^
- reverse_bits(oldNumberOfBuckets - 1);
- SortedListSetNode **newBuckets =
- set->malloc(sizeof(SortedListSetNode *) * newNumberOfBuckets);
- SortedListSetNode **oldBuckets = set->buckets;
- SortedListSetNode *moveTemp;
- for (unsigned int i = 0; i < oldNumberOfBuckets; i++) {
- moveTemp = sl_set_split_opt(&oldBuckets[i], splitUpMask);
- newBuckets[i] = oldBuckets[i];
- newBuckets[i + oldNumberOfBuckets] = moveTemp;
- }
- set->free(oldBuckets);
- set->buckets = newBuckets;
- set->numberOfBuckets = newNumberOfBuckets;
- set->expandTreshold = newNumberOfBuckets * CHAIN_LENGHT_EXPAND_THRESHOLD;
- set->shrinkTreshold = newNumberOfBuckets * CHAIN_LENGHT_SHRINK_THRESHOLD;
- }
-}
-
-static inline void ch_set_decrease_size(ChainedHashSet *set) {
- set->size = set->size - 1;
- if (set->size < set->shrinkTreshold) {
- unsigned int oldNumberOfBuckets = set->numberOfBuckets;
- unsigned int newNumberOfBuckets = oldNumberOfBuckets / 2;
- SortedListSetNode **newBuckets =
- set->malloc(sizeof(SortedListSetNode *) * newNumberOfBuckets);
- SortedListSetNode **oldBuckets = set->buckets;
- for (unsigned int i = 0; i < newNumberOfBuckets; i++) {
- newBuckets[i] = oldBuckets[i];
- sl_set_concat_opt(&newBuckets[i], oldBuckets[i + newNumberOfBuckets]);
- }
- set->free(oldBuckets);
- set->buckets = newBuckets;
- set->numberOfBuckets = newNumberOfBuckets;
- set->expandTreshold = newNumberOfBuckets * CHAIN_LENGHT_EXPAND_THRESHOLD;
- if (set->numberOfBuckets == INITIAL_NUMBER_OF_BUCKETS) {
- set->shrinkTreshold = 0;
- } else {
- set->shrinkTreshold = newNumberOfBuckets * CHAIN_LENGHT_SHRINK_THRESHOLD;
- }
- }
-}
-
-static inline void ch_set_initialize(ChainedHashSet *set,
- unsigned int keyPosition,
- void *(*extract_key)(void *v, int keyPos),
- unsigned int (*hash_key)(void *k),
- bool (*are_equal)(void *v1, void *v2),
- char *(*to_string)(void *v1),
- void *(*my_malloc)(size_t size),
- void (*my_free)(void *ptr)) {
- set->keyPosition = keyPosition;
- set->extract_key = extract_key;
- set->hash_key = hash_key;
- set->are_equal = are_equal;
- set->to_string = to_string;
- set->malloc = my_malloc;
- set->free = my_free;
- set->numberOfBuckets = INITIAL_NUMBER_OF_BUCKETS;
- set->expandTreshold = set->numberOfBuckets * CHAIN_LENGHT_EXPAND_THRESHOLD;
- set->shrinkTreshold = set->numberOfBuckets * CHAIN_LENGHT_EXPAND_THRESHOLD;
- set->size = 0;
- set->buckets =
- set->malloc(sizeof(SortedListSetNode *) * INITIAL_NUMBER_OF_BUCKETS);
- for (int i = 0; i < INITIAL_NUMBER_OF_BUCKETS; i++) {
- set->buckets[i] = NULL;
- }
-}
-
-static inline ChainedHashSet *ch_set_create(
- unsigned int keyPosition, void *(*extract_key)(void *v, int keyPos),
- unsigned int (*hash_key)(void *k), bool (*are_equal)(void *v1, void *v2),
- char *(*to_string)(void *v1), void *(*my_malloc)(size_t size),
- void (*my_free)(void *ptr)) {
- ChainedHashSet *set = my_malloc(sizeof(ChainedHashSet));
- ch_set_initialize(set, keyPosition, extract_key, hash_key, are_equal,
- to_string, my_malloc, my_free);
- return set;
-}
-
-static inline bool ch_set_insert_opt(ChainedHashSet *set, void *value,
- unsigned int valueSize,
- unsigned int hashValue, bool overwrite) {
- unsigned int bucketIndex = hashValue & (set->numberOfBuckets - 1);
- SortedListSetNode **bucket = &set->buckets[bucketIndex];
- bool oneAdded = sl_set_insert_opt(
- bucket, value, valueSize, reverse_bits(hashValue), set->keyPosition,
- overwrite, set->extract_key, set->are_equal, set->malloc, set->free);
- if (oneAdded) {
- ch_set_increase_size(set);
- }
- return oneAdded;
-}
-
-static inline void ch_set_insert(void *setParam, void *value,
- unsigned int valueSize) {
- ChainedHashSet *set = (ChainedHashSet *)setParam;
- void *key = set->extract_key(value, set->keyPosition);
- unsigned int hashValue = set->hash_key(key);
- ch_set_insert_opt(set, value, valueSize, hashValue, true);
-}
-
-static inline bool ch_set_insert_new(void *setParam, void *value,
- unsigned int valueSize) {
- ChainedHashSet *set = (ChainedHashSet *)setParam;
- void *key = set->extract_key(value, set->keyPosition);
- unsigned int hashValue = set->hash_key(key);
- return ch_set_insert_opt(set, value, valueSize, hashValue, false);
-}
-
-static inline void *ch_set_lookup(void *setParam, void *key) {
- ChainedHashSet *set = (ChainedHashSet *)setParam;
- unsigned int hashValue = set->hash_key(key);
- unsigned int bucketIndex = hashValue & (set->numberOfBuckets - 1);
- SortedListSetNode **bucket = &set->buckets[bucketIndex];
- return sl_set_lookup_opt(bucket, key, reverse_bits(hashValue),
- set->keyPosition, set->extract_key, set->are_equal,
- false, set->malloc);
-}
-
-static inline void ch_set_delete(void *setParam, void *key,
- unsigned int keySize) {
- (void)keySize;
- ChainedHashSet *set = (ChainedHashSet *)setParam;
- unsigned int hashValue = set->hash_key(key);
- unsigned int bucketIndex = hashValue & (set->numberOfBuckets - 1);
- SortedListSetNode **bucket = &set->buckets[bucketIndex];
- bool oneRemoved =
- sl_set_delete_opt(bucket, key, reverse_bits(hashValue), set->keyPosition,
- set->extract_key, set->are_equal, set->free);
- if (oneRemoved) {
- ch_set_decrease_size(set);
- }
-}
-
-static inline void ch_set_traverse(void *setParam,
- void (*traverser)(size_t index, void *v,
- void *context),
- void *context) {
- ChainedHashSet *set = (ChainedHashSet *)setParam;
- unsigned int numberOfBuckets = set->numberOfBuckets;
- SortedListSetNode *itemNode;
- size_t index = 0;
- for (unsigned int i = 0; i < numberOfBuckets; i++) {
- itemNode = set->buckets[i];
- while (itemNode != NULL) {
- traverser(index, (void *)itemNode->value, context);
- index++;
- itemNode = itemNode->next;
- }
- }
-}
-
-static inline void ch_set_free(void *setParam) {
- ChainedHashSet *set = (ChainedHashSet *)setParam;
- unsigned int numberOfBuckets = set->numberOfBuckets;
- for (unsigned int i = 0; i < numberOfBuckets; i++) {
- sl_set_free_opt(&set->buckets[i], set->free);
- }
- set->free(set->buckets);
- set->free(set);
-}
-
-static inline char *ch_set_to_string(void *setParam) {
- ChainedHashSet *set = (ChainedHashSet *)setParam;
- unsigned int numberOfBuckets = set->numberOfBuckets;
- char **bucketStrings = malloc(sizeof(char*)*numberOfBuckets);
- unsigned int *bucketStringSizes = malloc(sizeof(unsigned int)*numberOfBuckets);
- unsigned int totalBucketsStringSize = 0;
- SortedListSet *tempListSet = plain_sl_set_create(
- set->keyPosition, set->extract_key, set->hash_key, set->are_equal,
- set->to_string, set->malloc, set->free);
- for (unsigned int i = 0; i < numberOfBuckets; i++) {
- tempListSet->head = set->buckets[i];
- bucketStrings[i] = sl_set_to_string(tempListSet);
- bucketStringSizes[i] = strlen(bucketStrings[i]);
- totalBucketsStringSize = totalBucketsStringSize + bucketStringSizes[i];
- }
- tempListSet->head = NULL;
- sl_set_free(tempListSet);
- char *resultString =
- set->malloc(totalBucketsStringSize + numberOfBuckets * 3 - 3 + 3);
- resultString[0] = '[';
- unsigned int currentPosition = 1;
- for (unsigned int i = 0; i < numberOfBuckets; i++) {
- sprintf(&resultString[currentPosition], "%s", bucketStrings[i]);
- set->free(bucketStrings[i]);
- currentPosition = currentPosition + bucketStringSizes[i];
- if (i != (numberOfBuckets - 1)) {
- sprintf(&resultString[currentPosition], ",\n ");
- currentPosition = currentPosition + 3;
- }
- }
- sprintf(&resultString[currentPosition], "]");
- free(bucketStrings);
- free(bucketStringSizes);
- return resultString;
-}
-
-static inline void ch_set_print(void *setParam) {
- ChainedHashSet *set = (ChainedHashSet *)setParam;
- char *str = ch_set_to_string(set);
- printf("%s\n", str);
- set->free(str);
-}
-
-static inline bool ch_set_is_concurrent() { return false; }
-
-#endif
diff --git a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/simple_c_gc.c b/erts/lib_src/yielding_c_fun/lib/simple_c_gc/simple_c_gc.c
deleted file mode 100644
index c1f5a50e1b..0000000000
--- a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/simple_c_gc.c
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * %CopyrightBegin%
- *
- * Copyright 2019-2021 Kjell Winblad (kjellwinblad@gmail.com, http://winsh.me).
- * All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * %CopyrightEnd%
- */
-
-/*
- *
- * Author: Kjell Winblad
- *
- */
-
-#include "simple_c_gc.h"
-#include "chained_hash_set.h"
-
-#include <setjmp.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-static bool scgc_print_gc_info = false;
-static ChainedHashSet *scgc_objects;
-static void *scgc_stack_top;
-
-#define SCGC_MIN_ALLOCS_UNTIL_FREE 100
-static int scgc_allocs_until_gc = SCGC_MIN_ALLOCS_UNTIL_FREE;
-static void *(*scgc_user_malloc)(size_t size);
-static void (*scgc_user_free)(void *ptr);
-
-typedef enum { scgc_blank_state, scgc_marked } scgc_object_state;
-
-typedef struct {
- unsigned long magic_number;
- size_t size;
- scgc_object_state state;
- void *data[1];
-} scgc_object;
-
-typedef struct {
- void *address;
- scgc_object *base;
- unsigned long magic_number;
-} scgc_object_ref;
-
-static void *scgc_malloc(size_t size) {
- void *(*my_malloc)(size_t size);
- if (scgc_user_malloc == NULL) {
- my_malloc = malloc;
- } else {
- my_malloc = scgc_user_malloc;
- }
- void *res = my_malloc(size);
- if (res == NULL) {
- printf("GCGC: Allocator returned NULL.\n");
- exit(1);
- }
- return res;
-}
-
-static void scgc_free(void *ptr) {
- void (*my_free)(void *ptr);
- if (scgc_user_free == NULL) {
- my_free = free;
- } else {
- my_free = scgc_user_free;
- }
- my_free(ptr);
-}
-
-static void *scgc_extract_key(void *v, int keyPos) {
- (void)keyPos;
- return v;
-}
-
-static unsigned int scgc_hash_key(void *keyPtr) {
- /* From
- * https://lemire.me/blog/2018/08/15/fast-strongly-universal-64-bit-hashing-everywhere*/
- int64_t x = (intptr_t)*((void **)keyPtr);
- int64_t a = 2348923;
- int64_t b = 3292;
- int64_t c = 9893487421;
- int32_t low = (int)x;
- int32_t high = (int)(x >> 32);
- return (unsigned int)((a * low + b * high + c) >> 32);
-}
-
-static bool scgc_are_equal(void *v1p, void *v2p) {
- scgc_object_ref *v1 = ((scgc_object_ref *)v1p);
- scgc_object_ref *v2 = ((scgc_object_ref *)v2p);
- return v1->address == v2->address;
-}
-
-static char *scgc_to_string(void *vp) {
- scgc_object_ref *v = ((scgc_object_ref *)vp);
- char *str = scgc_malloc(200);
- sprintf(str, "{.address=%p, .base_address=%p, magic_number=%lu}", v->address,
- (void *)v->base, v->magic_number);
- return str;
-}
-
-static void scgc_initialize_global_state() {
- scgc_objects =
- ch_set_create(0, scgc_extract_key, scgc_hash_key, scgc_are_equal,
- scgc_to_string, scgc_malloc, scgc_free);
- srand((int)(intptr_t)scgc_objects * 2654435761);
-}
-
-static void scgc_do_gc(bool no_stack);
-
-static void scgc_destroy_global_state() {
- scgc_do_gc(true);
- ch_set_free(scgc_objects);
-}
-
-static int scgc_start_gced_code_2(int (*main)(int, char *[]), int argc,
- char **argv[]) {
- volatile int noinline = 1;
- volatile char **my_argv = (volatile char **)*argv;
- scgc_stack_top = (void *)my_argv;
- int (*next)(int, char *[]) = noinline ? main : (int (*)(int, char *[]))(NULL);
- {
- int to_return;
- scgc_initialize_global_state();
- to_return = next(argc, (char **)my_argv);
- scgc_destroy_global_state();
- return to_return;
- }
-}
-
-static void scgc_global_set_put(scgc_object_ref ref) {
- ch_set_insert(scgc_objects, &ref, sizeof(scgc_object_ref));
-}
-
-static void scgc_global_set_del(void *key) {
- ch_set_delete(scgc_objects, &key, sizeof(void *));
-}
-
-static scgc_object_ref *scgc_global_set_get(void *key) {
- scgc_object_ref *ret = ch_set_lookup(scgc_objects, &key);
- return ret;
-}
-
-static void scgc_mark_reachable_objects_in_region(void *start, void *end);
-
-static void *scgc_min(void *a, void *b) { return a <= b ? a : b; }
-
-static void *scgc_max(void *a, void *b) { return a > b ? a : b; }
-
-static void ycf_find_stack_bottom_and_mark_conservative_helper(void) {
- volatile void *p = NULL;
- volatile intptr_t stack_bottom = (intptr_t)&p;
- scgc_mark_reachable_objects_in_region(
- scgc_min(scgc_stack_top, (void *)&stack_bottom),
- scgc_max((void *)&stack_bottom, scgc_stack_top));
-}
-
-static void scgc_get_stack_bottom_and_mark() {
- jmp_buf env;
- setjmp(env);
-
- volatile int noinline = 1;
-
- void (*bottom)(void) =
- noinline ? ycf_find_stack_bottom_and_mark_conservative_helper
- : (void (*)(void))(NULL);
-
- bottom();
-}
-
-static void scgc_mark_reachable_objects_in_region(void *start, void *end) {
- void **iter = start;
- void **iter_end = end;
- scgc_object *object;
- while (iter <= iter_end) {
- scgc_object_ref *ref = scgc_global_set_get(*iter);
- if (ref != NULL && ref->base->data == *iter &&
- ref->magic_number == ref->base->magic_number &&
- ref->base->state == scgc_blank_state) {
- object = ref->base;
- object->state = scgc_marked;
- scgc_mark_reachable_objects_in_region(
- &object->data[0], &((char *)object->data)[object->size - 1]);
- }
- iter = iter + 1;
- }
-}
-
-static void scgc_mark_reachable_objects(bool no_stack) {
- void *tmp = NULL;
- if (no_stack) {
- scgc_mark_reachable_objects_in_region(&tmp, &tmp);
- } else {
- scgc_get_stack_bottom_and_mark();
- }
-}
-
-static void scgc_collect_unmarked_traverser(size_t index, void *v,
- void *context) {
- void **objects_to_remove = context;
- scgc_object_ref *ref = v;
- if (ref->base->state == scgc_blank_state) {
- scgc_free(ref->base);
- objects_to_remove[index] = ref->address;
- } else {
- objects_to_remove[index] = NULL;
- }
-}
-
-static void scgc_remove_unmarked_objects() {
- size_t nr_of_candidates = scgc_objects->size;
- void **objects_to_remove = scgc_malloc(sizeof(void *) * nr_of_candidates);
- for (size_t i = 0; i < nr_of_candidates; i++) {
- objects_to_remove[i] = NULL;
- }
- ch_set_traverse(scgc_objects, scgc_collect_unmarked_traverser,
- objects_to_remove);
- for (size_t i = 0; i < nr_of_candidates; i++) {
- if (objects_to_remove[i] != NULL) {
- scgc_global_set_del(objects_to_remove[i]);
- }
- }
- scgc_free(objects_to_remove);
-}
-
-static void scgc_unmark_traverser(size_t index, void *v, void *context) {
- scgc_object_ref *ref = v;
- ref->base->state = scgc_blank_state;
-}
-
-static void scgc_unmark_objects() {
- ch_set_traverse(scgc_objects, scgc_unmark_traverser, NULL);
-}
-
-static void scgc_do_gc(bool no_stack) {
- unsigned int objects_before = scgc_objects->size;
- scgc_mark_reachable_objects(no_stack);
- scgc_remove_unmarked_objects();
- scgc_unmark_objects();
- if (scgc_print_gc_info) {
- unsigned int objects_after = scgc_objects->size;
- unsigned int objects_removed = objects_before - objects_after;
- fprintf(stderr, "GC: before=%u, after=%u, removed=%u\n", objects_before,
- objects_after, objects_removed);
- }
-}
-
-static void scgc_gc() {
- scgc_allocs_until_gc--;
- if (scgc_allocs_until_gc <= 0) {
- scgc_do_gc(false);
- unsigned int objects_after = scgc_objects->size;
- scgc_allocs_until_gc = objects_after * 2;
- if (scgc_allocs_until_gc < SCGC_MIN_ALLOCS_UNTIL_FREE) {
- scgc_allocs_until_gc = SCGC_MIN_ALLOCS_UNTIL_FREE;
- }
- }
-}
-
-/* Public interface */
-
-int scgc_start_gced_code(int (*main)(int, char *[]), int argc, char *argv[],
- void *(*my_malloc)(size_t), void (*my_free)(void *)) {
- volatile int noinline = 1;
- int (*next)(int (*)(int, char *[]), int, char **[]) =
- (noinline ? scgc_start_gced_code_2
- : (int (*)(int (*)(int, char *[]), int, char **[]))(NULL));
- volatile char **my_argv = (volatile char **)argv;
- int res;
- scgc_user_malloc = my_malloc;
- scgc_user_free = my_free;
- if (my_argv == NULL) {
- fprintf(stderr,
- "scgc_start_gced_code: the argv parameter should not be NULL!");
- exit(1);
- }
- res = next(main, argc, (char ***)&my_argv);
- return res;
-}
-
-void *scgc_new(size_t size) {
- scgc_gc();
- scgc_object *new = scgc_malloc(size + sizeof(scgc_object));
- scgc_object_ref new_ref;
- unsigned long magic_number = (unsigned long)rand();
- new->state = scgc_blank_state;
- new->magic_number = magic_number;
- new->size = size;
- new_ref.address = new->data;
- new_ref.base = new;
- new_ref.magic_number = magic_number;
- scgc_global_set_put(new_ref);
- return new->data;
-}
-
-void scgc_enable_print_gc_info() { scgc_print_gc_info = true; }
diff --git a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/simple_c_gc.h b/erts/lib_src/yielding_c_fun/lib/simple_c_gc/simple_c_gc.h
deleted file mode 100644
index 0e9aff84b8..0000000000
--- a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/simple_c_gc.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * %CopyrightBegin%
- *
- * Copyright 2019 Kjell Winblad (kjellwinblad@gmail.com, http://winsh.me).
- * All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * %CopyrightEnd%
- */
-
-/**
- * Pulic interface for Simple C GC.
- *
- * @author Kjell Winblad
- *
- */
-
-#ifndef SIMPLE_C_GC_H
-#define SIMPLE_C_GC_H
-
-#include <stddef.h>
-
-/**
- * This function starts code that will be garbage collected
- *
- * @param main The function that will be started and garbage collected
- * @param argc Passed to main
- * @param argv Passed to main
- * @param my_malloc Simple C GC will use this to allocated memory
- * @param my_free Simple C GC will use this to free memory
- */
-int scgc_start_gced_code(int (*main)(int, char *[]), int argc, char *argv[],
- void *(*my_malloc)(size_t), void (*my_free)(void *));
-
-/**
- * Allocate a new memory block that will be garbage collected
- *
- * @param size The size of the new memory block
- */
-void *scgc_new(size_t size);
-
-/**
- * Enables printing of garbage collection information
- */
-void scgc_enable_print_gc_info(void);
-#endif
diff --git a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/sorted_list_set.h b/erts/lib_src/yielding_c_fun/lib/simple_c_gc/sorted_list_set.h
deleted file mode 100644
index 1c216d2ed9..0000000000
--- a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/sorted_list_set.h
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- * %CopyrightBegin%
- *
- * Copyright 2019 Kjell Winblad (kjellwinblad@gmail.com, http://winsh.me).
- * All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * %CopyrightEnd%
- */
-
-/*
- *
- * Author: Kjell Winblad
- *
- */
-
-#ifndef SORTED_LIST_SET_H
-#define SORTED_LIST_SET_H
-
-#include <limits.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-typedef struct SortedListSetNodeImpl {
- struct SortedListSetNodeImpl *next;
- unsigned int key_hash_value;
- unsigned int valueSize;
- char value[]; /* Flexible size array member */
-} SortedListSetNode;
-
-typedef struct {
- SortedListSetNode *head;
- unsigned int keyPosition;
- void *(*extract_key)(void *v, int keyPos);
- unsigned int (*hash_key)(void *k);
- bool (*are_equal)(void *v1, void *v2);
- char *(*to_string)(void *v1);
- void *(*malloc)(size_t size);
- void (*free)(void *ptr);
-} SortedListSet;
-
-static inline SortedListSet *plain_sl_set_create(
- unsigned int keyPosition, void *(*extract_key)(void *v, int keyPos),
- unsigned int (*hash_key)(void *k), bool (*are_equal)(void *v1, void *v2),
- char *(*to_string)(void *v1), void *(*my_malloc)(size_t size),
- void (*my_free)(void *ptr)) {
- SortedListSet *set = my_malloc(sizeof(SortedListSet));
- set->head = NULL;
- set->keyPosition = keyPosition;
- set->extract_key = extract_key;
- set->hash_key = hash_key;
- set->are_equal = are_equal;
- set->to_string = to_string;
- set->malloc = my_malloc;
- set->free = my_free;
- return set;
-}
-
-static inline int compare_hash_codes(unsigned int code1, unsigned int code2) {
- return code1 - code2;
-}
-
-static inline bool sl_set_insert_opt(SortedListSetNode **root, void *valuePtr,
- unsigned int valueSize,
- unsigned int keyHashValue, int keyPosition,
- bool overwrite,
- void *(*extract_key)(void *v, int keyPos),
- bool (*are_equal)(void *v1, void *v2),
- void *(*my_malloc)(size_t size),
- void (*my_free)(void *ptr)) {
- void *key = extract_key(valuePtr, keyPosition);
- SortedListSetNode *previous = (SortedListSetNode *)root;
- SortedListSetNode *current = previous->next;
- bool oneMore = true;
- int compareResult;
- while (current != NULL) {
- compareResult = compare_hash_codes(current->key_hash_value, keyHashValue);
- if (compareResult < 0) {
- previous = current;
- current = previous->next;
- } else if (compareResult > 0) {
- break;
- } else {
- if (are_equal(extract_key(current->value, keyPosition), key)) {
- if (overwrite) {
- SortedListSetNode *oldCurrent = current;
- current = current->next;
- previous->next = current;
- my_free(oldCurrent);
- oneMore = false;
- break;
- } else {
- return false;
- }
- } else {
- previous = current;
- current = previous->next;
- }
- }
- }
- SortedListSetNode *newNode = my_malloc(sizeof(SortedListSetNode) + valueSize);
- previous->next = newNode;
- newNode->next = current;
- newNode->key_hash_value = keyHashValue;
- memcpy(newNode->value, valuePtr, valueSize);
- newNode->valueSize = valueSize;
- return oneMore;
-}
-
-static inline void sl_set_insert(void *setParam, void *valuePtr,
- unsigned int valueSize) {
- SortedListSet *set = (SortedListSet *)setParam;
- sl_set_insert_opt(&set->head, valuePtr, valueSize,
- set->hash_key(set->extract_key(valuePtr, set->keyPosition)),
- set->keyPosition, true, set->extract_key, set->are_equal,
- set->malloc, set->free);
-}
-
-static inline bool sl_set_insert_new(void *setParam, void *valuePtr,
- unsigned int valueSize) {
- SortedListSet *set = (SortedListSet *)setParam;
- return sl_set_insert_opt(
- &set->head, valuePtr, valueSize,
- set->hash_key(set->extract_key(valuePtr, set->keyPosition)),
- set->keyPosition, false, set->extract_key, set->are_equal, set->malloc,
- set->free);
-}
-
-static inline void *sl_set_lookup_opt(SortedListSetNode **root, void *key,
- unsigned int keyHashValue,
- int keyPosition,
- void *(*extract_key)(void *v, int keyPos),
- bool (*are_equal)(void *v1, void *v2),
- bool copyOut,
- void *(*my_malloc)(size_t size)) {
- SortedListSetNode *previous = (SortedListSetNode *)root;
- SortedListSetNode *current = previous->next;
- int compareResult;
- while (current != NULL) {
- compareResult = compare_hash_codes(current->key_hash_value, keyHashValue);
- if (compareResult < 0) {
- previous = current;
- current = previous->next;
- } else if (compareResult > 0) {
- return NULL;
- } else if (are_equal(extract_key(current->value, keyPosition), key)) {
- if (copyOut) {
- void *toReturn = my_malloc(current->valueSize);
- memcpy(toReturn, current->value, current->valueSize);
- return toReturn;
- } else {
- return current->value;
- }
- } else {
- previous = current;
- current = previous->next;
- }
- }
- return NULL;
-}
-
-static inline void *sl_set_lookup(void *setParam, void *key) {
- SortedListSet *set = (SortedListSet *)setParam;
- return sl_set_lookup_opt(&set->head, key, set->hash_key(key),
- set->keyPosition, set->extract_key, set->are_equal,
- false, set->malloc);
-}
-
-static inline bool sl_set_delete_opt(SortedListSetNode **root, void *key,
- unsigned int keyHashValue, int keyPosition,
- void *(*extract_key)(void *v, int keyPos),
- bool (*are_equal)(void *v1, void *v2),
- void (*my_free)(void *ptr)) {
- SortedListSetNode *previous = (SortedListSetNode *)root;
- SortedListSetNode *current = previous->next;
- int compareResult;
- while (current != NULL) {
- compareResult = compare_hash_codes(current->key_hash_value, keyHashValue);
- if (compareResult < 0) {
- previous = current;
- current = previous->next;
- } else if (compareResult > 0) {
- return false;
- } else if (are_equal(extract_key(current->value, keyPosition), key)) {
- previous->next = current->next;
- my_free(current);
- return true;
- } else {
- previous = current;
- current = previous->next;
- }
- }
- return false;
-}
-
-static inline void sl_set_delete(void *setParam, void *key,
- unsigned int keySize) {
- (void)keySize;
- SortedListSet *set = (SortedListSet *)setParam;
- sl_set_delete_opt(&set->head, key, set->hash_key(key), set->keyPosition,
- set->extract_key, set->are_equal, set->free);
-}
-
-static inline void sl_set_free_opt(SortedListSetNode **root,
- void (*my_free)(void *ptr)) {
- SortedListSetNode *previous = (SortedListSetNode *)root;
- SortedListSetNode *current = previous->next;
- while (current != NULL) {
- previous = current;
- current = current->next;
- my_free(previous);
- }
-}
-
-static inline void sl_set_free(void *setParam) {
- SortedListSet *set = (SortedListSet *)setParam;
- sl_set_free_opt(&set->head, set->free);
- set->free(set);
-}
-
-static inline SortedListSetNode *sl_set_split_opt(SortedListSetNode **root,
- unsigned int splitPattern) {
- SortedListSetNode *previous = (SortedListSetNode *)root;
- SortedListSetNode *current = previous->next;
- while (current != NULL) {
- if (current->key_hash_value & splitPattern) {
- previous->next = NULL;
- return current;
- }
- previous = current;
- current = previous->next;
- }
- return NULL;
-}
-
-static inline void sl_set_concat_opt(SortedListSetNode **root,
- SortedListSetNode *list) {
- SortedListSetNode *previous = (SortedListSetNode *)root;
- SortedListSetNode *current = previous->next;
- while (current != NULL) {
- previous = current;
- current = previous->next;
- }
- previous->next = list;
-}
-
-static inline void sl_set_append_opt(SortedListSetNode **root,
- SortedListSetNode *list) {
- if (list == NULL) {
- return;
- }
- SortedListSetNode *previous = (SortedListSetNode *)root;
- SortedListSetNode *current = previous->next;
- while (current != NULL) {
- previous = current;
- current = previous->next;
- }
- previous->next = list;
-}
-
-static inline void *
-sl_set_fold_opt(SortedListSetNode **root, void *initialValue,
- void *(*f)(void *soFar, void *currentValue)) {
- SortedListSetNode *previous = (SortedListSetNode *)root;
- SortedListSetNode *current = previous->next;
- void *soFar = initialValue;
- while (current != NULL) {
- soFar = f(soFar, current->value);
- current = current->next;
- }
- return soFar;
-}
-
-static inline void *sl_set_fold(SortedListSet *set, void *initialValue,
- void *(*f)(void *soFar, void *currentValue)) {
- return sl_set_fold_opt(&set->head, initialValue, f);
-}
-
-static inline void *_______size_helper(void *soFarParam, void *currentValue) {
- unsigned int *soFar = (unsigned int *)soFarParam;
- (void)currentValue;
- unsigned int prev = *soFar;
- *soFar = prev + 1;
- return soFar;
-}
-
-static inline unsigned int sl_set_size_opt(SortedListSetNode **root) {
- unsigned int size = 0;
- sl_set_fold_opt(root, &size, _______size_helper);
- return size;
-}
-
-static inline unsigned int sl_set_size(SortedListSet *set) {
- return sl_set_size_opt(&set->head);
-}
-
-static inline void sl_set_print(void *setParam) {
- SortedListSet *set = (SortedListSet *)setParam;
- SortedListSetNode *previous = (SortedListSetNode *)set;
- SortedListSetNode *current = previous->next;
- printf("[");
- while (current != NULL) {
- char *string = set->to_string(current->value);
- printf("%s", string);
- set->free(string);
- previous = current;
- current = previous->next;
- if (current != NULL) {
- printf(",");
- }
- }
- printf("]\n");
-}
-
-static inline char *sl_set_to_string(void *setParam) {
- SortedListSet *set = (SortedListSet *)setParam;
- unsigned int numberOfElements = sl_set_size(set);
- char **stringArray = malloc(sizeof(char*)*numberOfElements);
- unsigned int *stringLengths = malloc(sizeof(unsigned int)*numberOfElements);
- SortedListSetNode *previous = (SortedListSetNode *)set;
- SortedListSetNode *current = previous->next;
- unsigned int elementNumber = 0;
- unsigned int totalCharCount = 2;
- if (numberOfElements == 0) {
- char *buffer = (char *)set->malloc(3);
- sprintf(buffer, "[]");
- free(stringArray);
- free(stringLengths);
- return buffer;
- }
- while (current != NULL) {
- stringArray[elementNumber] = set->to_string(current->value);
- stringLengths[elementNumber] = strlen(stringArray[elementNumber]);
- totalCharCount = totalCharCount + stringLengths[elementNumber];
- current = current->next;
- elementNumber++;
- }
- totalCharCount = totalCharCount + numberOfElements;
- char *stringBuffer = set->malloc(totalCharCount);
- stringBuffer[0] = '[';
- unsigned int currentPosition = 1;
- for (unsigned int i = 0; i < numberOfElements; i++) {
- sprintf(&stringBuffer[currentPosition], "%s", stringArray[i]);
- set->free(stringArray[i]);
- currentPosition = currentPosition + stringLengths[i];
- if (i != (numberOfElements - 1)) {
- sprintf(&stringBuffer[currentPosition], ",");
- currentPosition = currentPosition + 1;
- }
- }
- sprintf(&stringBuffer[currentPosition], "]");
- free(stringArray);
- free(stringLengths);
- return stringBuffer;
-}
-
-#endif
diff --git a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/test.c b/erts/lib_src/yielding_c_fun/lib/simple_c_gc/test.c
deleted file mode 100644
index f118db4361..0000000000
--- a/erts/lib_src/yielding_c_fun/lib/simple_c_gc/test.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "simple_c_gc.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-static size_t nr_of_objects_created = 0;
-static size_t nr_of_objects = 0;
-static size_t peek_nr_of_objects = 0;
-
-static void *my_malloc(size_t size) {
- nr_of_objects++;
- nr_of_objects_created++;
- if (nr_of_objects > peek_nr_of_objects) {
- peek_nr_of_objects = nr_of_objects;
- }
- return calloc(1, size);
-}
-
-static void my_free(void *ptr) {
- nr_of_objects--;
- free(ptr);
-}
-
-int my_main(int argc, char *argv[]) {
- if (argc == 2 && strcmp(argv[1], "-enable_gc_info") == 0) {
- scgc_enable_print_gc_info();
- }
- void **my = scgc_new(100);
- FILE *fp = fopen(".tmp_out", "w");
- fprintf(fp, "my %p %p\n", (void *)my, (void *)&my);
- for (int i = 0; i < 100000; i++) {
- my[0] = scgc_new(32);
- my[1] = scgc_new(32);
- my[2] = scgc_new(32);
- ((void **)my[2])[0] = scgc_new(32);
- ((void **)my[2])[1] = scgc_new(32);
- fprintf(fp, "test1 %p\n", ((void **)my[0])[0]);
- fprintf(fp, "test2 %p\n", ((void **)my[1])[0]);
- fprintf(fp, "test3 %p\n", ((void ***)my[2])[0][0]);
- fprintf(fp, "test4 %p\n", ((void ***)my[2])[1][0]);
- }
- fclose(fp);
- return 0;
-}
-
-int main(int argc, char *argv[]) {
- /*Test the gc*/
- scgc_start_gced_code(my_main, argc, argv, my_malloc, my_free);
- fprintf(stderr, "Peek nr of live objects: %zu\n", peek_nr_of_objects);
- fprintf(stderr, "Nr of objects after: %zu\n", nr_of_objects);
- fprintf(stderr, "Nr of objects created: %zu\n", nr_of_objects_created);
- return 0;
-}
diff --git a/erts/lib_src/yielding_c_fun/main_target.mk b/erts/lib_src/yielding_c_fun/main_target.mk
index e7a43bb7d1..3473b060ab 100644
--- a/erts/lib_src/yielding_c_fun/main_target.mk
+++ b/erts/lib_src/yielding_c_fun/main_target.mk
@@ -12,15 +12,11 @@ _create_dirs := $(shell mkdir -p $(YCF_OBJ_DIR) $(YCF_BIN_DIR))
endif
YCF_INCLUDE_DIRS = \
- -I$(YCF_SOURCE_DIR) \
- -I$(YCF_SOURCE_DIR)/lib/simple_c_gc
+ -I$(YCF_SOURCE_DIR)
YCF_HEADERS = $(sort $(shell find $(YCF_SOURCE_DIR) -name '*.h'))
-YCF_EXTRA_SOURCES = \
- $(YCF_SOURCE_DIR)/lib/simple_c_gc/simple_c_gc.c
-
-YCF_SOURCES = $(sort $(wildcard $(YCF_SOURCE_DIR)/*.c) $(YCF_EXTRA_SOURCES))
+YCF_SOURCES = $(sort $(wildcard $(YCF_SOURCE_DIR)/*.c))
YCF_OBJECTS = $(addprefix $(YCF_OBJ_DIR)/,$(notdir $(YCF_SOURCES:.c=.o)))
@@ -29,8 +25,5 @@ YCF_LDFLAGS = $(filter-out -fsanitize%,$(LDFLAGS))
$(YCF_EXECUTABLE): $(YCF_OBJECTS)
$(V_LD) $(YCF_CFLAGS) $(LDFLAGS) $(YCF_OBJECTS) -o $@
-$(YCF_OBJ_DIR)/%.o: $(YCF_SOURCE_DIR)/lib/simple_c_gc/%.c $(YCF_HEADERS)
- $(V_CC) $(YCF_CFLAGS) $(LDFLAGS) $(YCF_INCLUDE_DIRS) -c $< -o $@
-
$(YCF_OBJ_DIR)/%.o: $(YCF_SOURCE_DIR)/%.c $(YCF_HEADERS)
$(V_CC) $(YCF_CFLAGS) $(LDFLAGS) $(YCF_INCLUDE_DIRS) -c $< -o $@
diff --git a/erts/lib_src/yielding_c_fun/ycf_main.c b/erts/lib_src/yielding_c_fun/ycf_main.c
index 1fdf7e1172..801cb6fb57 100644
--- a/erts/lib_src/yielding_c_fun/ycf_main.c
+++ b/erts/lib_src/yielding_c_fun/ycf_main.c
@@ -26,7 +26,6 @@
#include "ycf_utils.h"
#include "ycf_yield_fun.h"
#include "ycf_node.h"
-#include "lib/simple_c_gc/simple_c_gc.h"
#include <stdlib.h>
#include <stdio.h>
@@ -87,7 +86,6 @@ void parse_and_print_ast(const char* file_name){
void print_help_text_and_exit(char* program_name, int error_code) {
printf("Usage: %s [-h]\n"
- " %s [-use_gc [-print_gc_info]]\n"
" [-log_max_mem_usage log_file]\n"
" [(( -f | -frec | -fnoauto | -fextenal) function_name)...\n"
" [-output_file_name output_file]\n"
@@ -98,7 +96,6 @@ void print_help_text_and_exit(char* program_name, int error_code) {
" input_c_file]]\n"
"\n"
"Please see the README.md file for more details.\n",
- program_name,
program_name);
exit(0);
}
@@ -290,25 +287,16 @@ return
int main( int argc, char* argv[] )
{
bool log_max_mem_usage = false;
- bool use_gc = false;
char * log_max_mem_usage_file = NULL;
int i = 1;
if (argc == 1) {
print_help_text_and_exit(argv[0], 0);
}
while(i < argc &&
- (ycf_string_is_equal("-use_gc", argv[i]) ||
- ycf_string_is_equal("-log_max_mem_usage", argv[i]) ||
- ycf_string_is_equal("-print_gc_info", argv[i]) ||
+ (ycf_string_is_equal("-log_max_mem_usage", argv[i]) ||
is_help_option(argv[i]))) {
if (is_help_option(argv[i])) {
print_help_text_and_exit(argv[0], 0);
- } else if (ycf_string_is_equal("-use_gc", argv[i])) {
- use_gc = true;
- i++;
- } else if(ycf_string_is_equal("-print_gc_info", argv[i])) {
- scgc_enable_print_gc_info();
- i++;
} else if(ycf_string_is_equal(argv[i], "-log_max_mem_usage")) {
ycf_enable_memory_tracking();
log_max_mem_usage = true;
@@ -318,18 +306,8 @@ int main( int argc, char* argv[] )
}
}
int nr_of_params_to_remove = i - 1;
- int ret;
- if (!use_gc) {
- ret = ycf_main(argc - nr_of_params_to_remove ,
- argv + nr_of_params_to_remove);
- } else {
- ycf_enable_gc();
- ret = scgc_start_gced_code(ycf_main,
- argc - nr_of_params_to_remove,
- argv + nr_of_params_to_remove,
- ycf_raw_malloc,
- ycf_free);
- }
+ int ret = ycf_main(argc - nr_of_params_to_remove ,
+ argv + nr_of_params_to_remove);
if(log_max_mem_usage){
ycf_malloc_log(log_max_mem_usage_file, "all");
}
diff --git a/erts/lib_src/yielding_c_fun/ycf_utils.c b/erts/lib_src/yielding_c_fun/ycf_utils.c
index 1c51043b41..2b33b67aba 100644
--- a/erts/lib_src/yielding_c_fun/ycf_utils.c
+++ b/erts/lib_src/yielding_c_fun/ycf_utils.c
@@ -28,19 +28,13 @@
#include <stdio.h>
#include "ycf_utils.h"
-#include "lib/simple_c_gc/simple_c_gc.h"
#include <stdint.h>
-bool ycf_use_gc = false;
bool ycf_track_memory = false;
size_t ycf_memory_usage = 0;
size_t ycf_max_memory_usage = 0;
-void ycf_enable_gc(){
- ycf_use_gc = true;
-}
-
void ycf_enable_memory_tracking(){
ycf_track_memory = true;
}
@@ -82,14 +76,9 @@ void* ycf_raw_malloc(size_t size) {
}
void* ycf_malloc(size_t size) {
- if (ycf_use_gc) {
- return scgc_new(size);
- } else {
- return ycf_raw_malloc(size);
- }
+ return ycf_raw_malloc(size);
}
-
void ycf_free(void* to_free) {
if (ycf_track_memory) {
char* to_free_cp = to_free;
diff --git a/erts/lib_src/yielding_c_fun/ycf_utils.h b/erts/lib_src/yielding_c_fun/ycf_utils.h
index d713fafc09..c8936d6f06 100644
--- a/erts/lib_src/yielding_c_fun/ycf_utils.h
+++ b/erts/lib_src/yielding_c_fun/ycf_utils.h
@@ -29,7 +29,6 @@
#include <stdbool.h>
-void ycf_enable_gc(void);
void ycf_enable_memory_tracking(void);
void* ycf_malloc(size_t size);
void ycf_malloc_log(char* log_file, char* log_entry_id);
--
2.43.0