Skip to content

Commit 15ae179

Browse files
committed
Start a contrib/ with libgc and libregex (#127)
1 parent 089a75b commit 15ae179

File tree

3 files changed

+222
-0
lines changed

3 files changed

+222
-0
lines changed

contrib/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Unsupported w64devkit enhancements
2+
3+
The files in this directory enhance w64devkit with specially-built
4+
third-party libraries, such as garbage collection and POSIX `regex.h`.
5+
Falling outside the scope of w64devkit, these libraries are not included
6+
in the distribution, but may be situationally useful.
7+
8+
The header of each file has the instructions for its use. The file itself
9+
is mostly a custom build script, and you will need to obtain the library
10+
sources yourself the usual way.

contrib/libgc.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#if 0
2+
# Minimalist, stripped down, w64devkit, static, unity build of Boehm GC.
3+
# Provides an easy-to-use garbage collector weighing ~24KiB. The API is
4+
# two functions: GC_malloc and GC_realloc. Tested with gc 8.2.4.
5+
#
6+
# Place this source file in the Boehm GC source tree root, then invoke
7+
# it with the shell to produce gc.h and libgc.a.
8+
#
9+
# $ sh libgc.c
10+
#
11+
# Philosophy: If the goal is ease-of-use, remove all knobs that are not
12+
# strictly necessary. If performance isn't good enough, don't use garbage
13+
# collection; switch to a region-based allocator.
14+
#
15+
# Ref: https://www.hboehm.info/gc/gc_source/gc-8.2.4.tar.gz
16+
# This is free and unencumbered software released into the public domain.
17+
set -ex
18+
19+
PREFIX="${PREFIX:-$(gcc -print-sysroot)}"
20+
21+
${CC:-cc} -c -Iinclude -fwhole-program ${CFLAGS:--Os} libgc.c
22+
${STRIP-strip} -x libgc.o
23+
24+
mkdir -p "$PREFIX/lib"
25+
rm -f "$PREFIX/lib/libgc.a"
26+
${AR:-ar} -r "$PREFIX/lib/libgc.a" libgc.o
27+
28+
mkdir -p "$PREFIX/include"
29+
tee "$PREFIX/include/gc.h" <<EOF
30+
#ifndef GC_H
31+
#define GC_H
32+
// Single-threaded, garbage-collected, zero-initialized memory allocation.
33+
#include <stddef.h>
34+
void *GC_malloc(size_t) __attribute((alloc_size(1), malloc));
35+
void *GC_realloc(void *, size_t) __attribute((alloc_size(2)));
36+
#endif
37+
EOF
38+
exit 0
39+
#endif
40+
41+
#define ALL_INTERIOR_POINTERS
42+
#define DONT_USE_ATEXIT
43+
#define GC_API
44+
#define GC_NO_FINALIZATION
45+
#define GC_TOGGLE_REFS_NOT_NEEDED
46+
#define GC_USE_ENTIRE_HEAP
47+
#define NO_CLOCK
48+
#define NO_DEBUGGING
49+
#define NO_GETENV
50+
#define NO_MSGBOX_ON_ERROR
51+
52+
#include "allchblk.c"
53+
#include "alloc.c"
54+
#include "blacklst.c"
55+
#include "dbg_mlc.c"
56+
#include "dyn_load.c"
57+
#include "finalize.c"
58+
#include "headers.c"
59+
#include "mach_dep.c"
60+
#include "malloc.c"
61+
#include "mallocx.c"
62+
#include "mark.c"
63+
#include "mark_rts.c"
64+
#include "misc.c"
65+
#include "new_hblk.c"
66+
#include "obj_map.c"
67+
#include "os_dep.c"
68+
#include "ptr_chck.c"
69+
#include "reclaim.c"
70+
71+
__attribute((used)) void *GC_malloc(size_t);
72+
__attribute((used)) void *GC_realloc(void *, size_t);

contrib/libregex.c

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#if 0
2+
# Stripped down, w64devkit, static, unity build of the PCRE2 POSIX regex
3+
# library. This script builds and installs regex.h and libregex.a inside
4+
# w64devkit. Link with -lregex. It is pretty bulky, nearly 300KiB.
5+
#
6+
# Copy and run this script in the root fo the PCRE source tree. Tested
7+
# with PCRE 10.43.
8+
#
9+
# $ sh libregex.c
10+
#
11+
# Ref: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/regex.h.html
12+
# This is free and unencumbered software released into the public domain.
13+
set -ex
14+
15+
PREFIX="${PREFIX:-$(gcc -print-sysroot)}"
16+
17+
cp src/pcre2.h.generic src/pcre2.h
18+
${CC:-cc} -c -fwhole-program ${CFLAGS:--Os} "$0"
19+
${STRIP:-strip} -x libregex.o
20+
21+
mkdir -p "$PREFIX/lib"
22+
rm -f "$PREFIX/lib/libregex.a"
23+
${AR:-ar} -r "$PREFIX/lib/libregex.a" libregex.o
24+
25+
mkdir -p "$PREFIX/include"
26+
tee >nul $PREFIX/include/regex.h <<EOF
27+
#pragma once
28+
#include <stddef.h>
29+
30+
enum {
31+
REG_EXTENDED = 0x0000,
32+
REG_ICASE = 0x0001,
33+
REG_NEWLINE = 0x0002,
34+
REG_NOTBOL = 0x0004,
35+
REG_NOTEOL = 0x0008,
36+
REG_DOTALL = 0x0010,
37+
REG_NOSUB = 0x0020,
38+
REG_UTF = 0x0040,
39+
REG_STARTEND = 0x0080,
40+
REG_NOTEMPTY = 0x0100,
41+
REG_UNGREEDY = 0x0200,
42+
REG_UCP = 0x0400,
43+
REG_PEND = 0x0800,
44+
REG_NOSPEC = 0x1000,
45+
};
46+
47+
enum {
48+
REG_ASSERT = 1,
49+
REG_BADBR,
50+
REG_BADPAT,
51+
REG_BADRPT,
52+
REG_EBRACE,
53+
REG_EBRACK,
54+
REG_ECOLLATE,
55+
REG_ECTYPE,
56+
REG_EESCAPE,
57+
REG_EMPTY,
58+
REG_EPAREN,
59+
REG_ERANGE,
60+
REG_ESIZE,
61+
REG_ESPACE,
62+
REG_ESUBREG,
63+
REG_INVARG,
64+
REG_NOMATCH,
65+
};
66+
67+
typedef struct {
68+
void *re_pcre2_code;
69+
void *re_match_data;
70+
char *re_endp;
71+
size_t re_nsub;
72+
size_t re_erroffset;
73+
int re_cflags;
74+
} regex_t;
75+
76+
typedef int regoff_t;
77+
78+
typedef struct {
79+
regoff_t rm_so;
80+
regoff_t rm_eo;
81+
} regmatch_t;
82+
83+
int regcomp(regex_t *, const char *, int);
84+
size_t regerror(int, const regex_t *, char *, size_t);
85+
int regexec(const regex_t *, const char *, size_t, regmatch_t *, int);
86+
void regfree(regex_t *);
87+
EOF
88+
exit 0
89+
#endif
90+
91+
#define PCRE2_EXP_DEFN static
92+
#define PCRE2_EXP_DECL static
93+
#define PCRE2POSIX_EXP_DECL
94+
#define PCRE2POSIX_EXP_DEFN __attribute((used))
95+
96+
#define HAVE_BUILTIN_MUL_OVERFLOW
97+
#define HAVE_MEMMOVE
98+
#define HEAP_LIMIT 20000000
99+
#define LINK_SIZE 2
100+
#define MATCH_LIMIT 10000000
101+
#define MATCH_LIMIT_DEPTH MATCH_LIMIT
102+
#define MAX_NAME_COUNT 10000
103+
#define MAX_NAME_SIZE 32
104+
#define MAX_VARLOOKBEHIND 255
105+
#define NEWLINE_DEFAULT 2
106+
#define PARENS_NEST_LIMIT 250
107+
#define PCRE2_CODE_UNIT_WIDTH 8
108+
#define PCRE2_STATIC
109+
#define SUPPORT_UNICODE
110+
111+
#include "src/pcre2posix.h"
112+
#undef regcomp
113+
#undef regexec
114+
#undef regerror
115+
#undef regfree
116+
#define pcre2_regcomp regcomp
117+
#define pcre2_regexec regexec
118+
#define pcre2_regerror regerror
119+
#define pcre2_regfree regfree
120+
#include "src/pcre2posix.c"
121+
122+
#include "src/pcre2_auto_possess.c"
123+
#include "src/pcre2_chartables.c.dist"
124+
#include "src/pcre2_chkdint.c"
125+
#include "src/pcre2_compile.c"
126+
#include "src/pcre2_context.c"
127+
#include "src/pcre2_extuni.c"
128+
#include "src/pcre2_find_bracket.c"
129+
#include "src/pcre2_match.c"
130+
#include "src/pcre2_match_data.c"
131+
#include "src/pcre2_newline.c"
132+
#include "src/pcre2_ord2utf.c"
133+
#include "src/pcre2_pattern_info.c"
134+
#include "src/pcre2_script_run.c"
135+
#include "src/pcre2_string_utils.c"
136+
#include "src/pcre2_study.c"
137+
#include "src/pcre2_tables.c"
138+
#include "src/pcre2_ucd.c"
139+
#include "src/pcre2_valid_utf.c"
140+
#include "src/pcre2_xclass.c"

0 commit comments

Comments
 (0)