From 15ae179b5ad8d9149467746c4c0e942daeac886d Mon Sep 17 00:00:00 2001 From: Christopher Wellons Date: Thu, 9 May 2024 16:09:33 -0400 Subject: [PATCH] Start a contrib/ with libgc and libregex (#127) --- contrib/README.md | 10 ++++ contrib/libgc.c | 72 +++++++++++++++++++++++ contrib/libregex.c | 140 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+) create mode 100644 contrib/README.md create mode 100644 contrib/libgc.c create mode 100644 contrib/libregex.c diff --git a/contrib/README.md b/contrib/README.md new file mode 100644 index 0000000..f83836f --- /dev/null +++ b/contrib/README.md @@ -0,0 +1,10 @@ +# Unsupported w64devkit enhancements + +The files in this directory enhance w64devkit with specially-built +third-party libraries, such as garbage collection and POSIX `regex.h`. +Falling outside the scope of w64devkit, these libraries are not included +in the distribution, but may be situationally useful. + +The header of each file has the instructions for its use. The file itself +is mostly a custom build script, and you will need to obtain the library +sources yourself the usual way. diff --git a/contrib/libgc.c b/contrib/libgc.c new file mode 100644 index 0000000..50ce839 --- /dev/null +++ b/contrib/libgc.c @@ -0,0 +1,72 @@ +#if 0 +# Minimalist, stripped down, w64devkit, static, unity build of Boehm GC. +# Provides an easy-to-use garbage collector weighing ~24KiB. The API is +# two functions: GC_malloc and GC_realloc. Tested with gc 8.2.4. +# +# Place this source file in the Boehm GC source tree root, then invoke +# it with the shell to produce gc.h and libgc.a. +# +# $ sh libgc.c +# +# Philosophy: If the goal is ease-of-use, remove all knobs that are not +# strictly necessary. If performance isn't good enough, don't use garbage +# collection; switch to a region-based allocator. +# +# Ref: https://www.hboehm.info/gc/gc_source/gc-8.2.4.tar.gz +# This is free and unencumbered software released into the public domain. +set -ex + +PREFIX="${PREFIX:-$(gcc -print-sysroot)}" + +${CC:-cc} -c -Iinclude -fwhole-program ${CFLAGS:--Os} libgc.c +${STRIP-strip} -x libgc.o + +mkdir -p "$PREFIX/lib" +rm -f "$PREFIX/lib/libgc.a" +${AR:-ar} -r "$PREFIX/lib/libgc.a" libgc.o + +mkdir -p "$PREFIX/include" +tee "$PREFIX/include/gc.h" < +void *GC_malloc(size_t) __attribute((alloc_size(1), malloc)); +void *GC_realloc(void *, size_t) __attribute((alloc_size(2))); +#endif +EOF +exit 0 +#endif + +#define ALL_INTERIOR_POINTERS +#define DONT_USE_ATEXIT +#define GC_API +#define GC_NO_FINALIZATION +#define GC_TOGGLE_REFS_NOT_NEEDED +#define GC_USE_ENTIRE_HEAP +#define NO_CLOCK +#define NO_DEBUGGING +#define NO_GETENV +#define NO_MSGBOX_ON_ERROR + +#include "allchblk.c" +#include "alloc.c" +#include "blacklst.c" +#include "dbg_mlc.c" +#include "dyn_load.c" +#include "finalize.c" +#include "headers.c" +#include "mach_dep.c" +#include "malloc.c" +#include "mallocx.c" +#include "mark.c" +#include "mark_rts.c" +#include "misc.c" +#include "new_hblk.c" +#include "obj_map.c" +#include "os_dep.c" +#include "ptr_chck.c" +#include "reclaim.c" + +__attribute((used)) void *GC_malloc(size_t); +__attribute((used)) void *GC_realloc(void *, size_t); diff --git a/contrib/libregex.c b/contrib/libregex.c new file mode 100644 index 0000000..14b41bd --- /dev/null +++ b/contrib/libregex.c @@ -0,0 +1,140 @@ +#if 0 +# Stripped down, w64devkit, static, unity build of the PCRE2 POSIX regex +# library. This script builds and installs regex.h and libregex.a inside +# w64devkit. Link with -lregex. It is pretty bulky, nearly 300KiB. +# +# Copy and run this script in the root fo the PCRE source tree. Tested +# with PCRE 10.43. +# +# $ sh libregex.c +# +# Ref: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/regex.h.html +# This is free and unencumbered software released into the public domain. +set -ex + +PREFIX="${PREFIX:-$(gcc -print-sysroot)}" + +cp src/pcre2.h.generic src/pcre2.h +${CC:-cc} -c -fwhole-program ${CFLAGS:--Os} "$0" +${STRIP:-strip} -x libregex.o + +mkdir -p "$PREFIX/lib" +rm -f "$PREFIX/lib/libregex.a" +${AR:-ar} -r "$PREFIX/lib/libregex.a" libregex.o + +mkdir -p "$PREFIX/include" +tee >nul $PREFIX/include/regex.h < + +enum { + REG_EXTENDED = 0x0000, + REG_ICASE = 0x0001, + REG_NEWLINE = 0x0002, + REG_NOTBOL = 0x0004, + REG_NOTEOL = 0x0008, + REG_DOTALL = 0x0010, + REG_NOSUB = 0x0020, + REG_UTF = 0x0040, + REG_STARTEND = 0x0080, + REG_NOTEMPTY = 0x0100, + REG_UNGREEDY = 0x0200, + REG_UCP = 0x0400, + REG_PEND = 0x0800, + REG_NOSPEC = 0x1000, +}; + +enum { + REG_ASSERT = 1, + REG_BADBR, + REG_BADPAT, + REG_BADRPT, + REG_EBRACE, + REG_EBRACK, + REG_ECOLLATE, + REG_ECTYPE, + REG_EESCAPE, + REG_EMPTY, + REG_EPAREN, + REG_ERANGE, + REG_ESIZE, + REG_ESPACE, + REG_ESUBREG, + REG_INVARG, + REG_NOMATCH, +}; + +typedef struct { + void *re_pcre2_code; + void *re_match_data; + char *re_endp; + size_t re_nsub; + size_t re_erroffset; + int re_cflags; +} regex_t; + +typedef int regoff_t; + +typedef struct { + regoff_t rm_so; + regoff_t rm_eo; +} regmatch_t; + +int regcomp(regex_t *, const char *, int); +size_t regerror(int, const regex_t *, char *, size_t); +int regexec(const regex_t *, const char *, size_t, regmatch_t *, int); +void regfree(regex_t *); +EOF +exit 0 +#endif + +#define PCRE2_EXP_DEFN static +#define PCRE2_EXP_DECL static +#define PCRE2POSIX_EXP_DECL +#define PCRE2POSIX_EXP_DEFN __attribute((used)) + +#define HAVE_BUILTIN_MUL_OVERFLOW +#define HAVE_MEMMOVE +#define HEAP_LIMIT 20000000 +#define LINK_SIZE 2 +#define MATCH_LIMIT 10000000 +#define MATCH_LIMIT_DEPTH MATCH_LIMIT +#define MAX_NAME_COUNT 10000 +#define MAX_NAME_SIZE 32 +#define MAX_VARLOOKBEHIND 255 +#define NEWLINE_DEFAULT 2 +#define PARENS_NEST_LIMIT 250 +#define PCRE2_CODE_UNIT_WIDTH 8 +#define PCRE2_STATIC +#define SUPPORT_UNICODE + +#include "src/pcre2posix.h" +#undef regcomp +#undef regexec +#undef regerror +#undef regfree +#define pcre2_regcomp regcomp +#define pcre2_regexec regexec +#define pcre2_regerror regerror +#define pcre2_regfree regfree +#include "src/pcre2posix.c" + +#include "src/pcre2_auto_possess.c" +#include "src/pcre2_chartables.c.dist" +#include "src/pcre2_chkdint.c" +#include "src/pcre2_compile.c" +#include "src/pcre2_context.c" +#include "src/pcre2_extuni.c" +#include "src/pcre2_find_bracket.c" +#include "src/pcre2_match.c" +#include "src/pcre2_match_data.c" +#include "src/pcre2_newline.c" +#include "src/pcre2_ord2utf.c" +#include "src/pcre2_pattern_info.c" +#include "src/pcre2_script_run.c" +#include "src/pcre2_string_utils.c" +#include "src/pcre2_study.c" +#include "src/pcre2_tables.c" +#include "src/pcre2_ucd.c" +#include "src/pcre2_valid_utf.c" +#include "src/pcre2_xclass.c"