Skip to content

community improvements#11

Open
rofl0r wants to merge 43 commits into
macournoyer:masterfrom
rofl0r:master
Open

community improvements#11
rofl0r wants to merge 43 commits into
macournoyer:masterfrom
rofl0r:master

Conversation

@rofl0r

@rofl0r rofl0r commented May 2, 2026

Copy link
Copy Markdown

see list of commits

rofl0r and others added 30 commits January 31, 2018 20:06
boehm GC is a highly problematic package, since what it tries to achieve
is not possible in standard C, so it must use all kinds of nasty
platform-specific tricks to get start offset of stack and so on.

for this reason, some or most distributions apply custom settings
or even patches to make it work.

these tweaks are not available when embedding the source of boehm into
the tree and hoping that it will turn out to work well...

windows users are advised to install the version provided by mingw
package manager, while mac os users can use homebrew's version.

closes #6
closes #9
closes #4
the original code used to have a tiny patch on top of peg 0.1.4
overriding all calls to malloc/realloc via a YYMALLOC/YYREALLOC
macro, so that all parts use the same GC (probably boehm).

re-applying this change was overlooked when we updated to latest
peg. meanwhile peg supplies its own YY_MALLOC which we now use
instead.

this caused odd issues such as "TypeError" message when running
the strings.rb test on linux distributions based on musl, which
is generally more sensible to undefined behaviour.
the original commit[0] did not document what was wrong.

[0]: sanchapereira/tinyrb-ist@3098dfe
commit 35207051557c79ea25942c021fb18856c72af8e3
https://github.com/orangeduck/tgc

(removed a couple big files from examples and .git*)
make GC=BOEHM (default) builds tinyrb with boehm GC support
make GC=TGC   builds tinyrb with built-in TGC
make GC=NONE  builds tinyrb against libc's malloc impl (without GC)
the STRING_PUSH macro does not zero-terminate strings, so we must
use the pushed strings with TrString_new which takes a length argument
and takes care of terminating the produced string, unlike TrString_new2
which uses strlen() on the input string, requiring it to be zero-
terminated.
this happened to work in the past by accident, because boehm gc hands
out only zeroed memory.
some members were not properly initialized and relied on the property
of boehm gc that all memory is zeroed by default.
uninitialized memory in the classes[] array caused crashes.
almost certainly other members aren't properly initialized either.
rofl0r and others added 13 commits September 7, 2018 22:55
the alloca call causes issues with clang's address sanitizer:

==951==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffd7
2535e0b at pc 0x0000004615f1 bp 0x7ffd72535dd0 sp 0x7ffd72535580

besides, it was also inefficient since the string has to be copied
into a heap allocated one anyway, and dangerous, since ruby strings
can easily be several MBs, especially when one slurps entire files
into memory, which would then smash the stack.
TrCallSite obj's are allocated implicitly via kv_pushp which in
turn calls realloc. the error slipped through the author's radar
because boehm's malloc and realloc both hand out only zero-initialized
mem.
found by valgrind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants