Mac: build passes but runtime fatal error
I'm on my Mac Mini M4, after cloning the code, I ran make && sudo make install, the build passes:
❯ make && sudo make install
gcc -DNDEBUG -O2 -Wall -Wextra -fno-strict-aliasing -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -o src/rdrview.o -c src/rdrview.c
gcc -o rdrview src/content.o src/iterator.o src/node.o src/prep_article.o src/rdrview.o src/readability.o src/readerable.o src/regex.o src/sandbox.o -lcurl -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lxml2 -lz -lpthread -licucore -lm -lm -liconv
ld: warning: ignoring duplicate libraries: '-lm'
Password:
mkdir -p /usr/local/bin
cp -f rdrview /usr/local/bin
mkdir -p /usr/local/share/man/man1
cp -f rdrview.1 /usr/local/share/man/man1
chmod 0644 /usr/local/share/man/man1/rdrview.1
but when I run it, there's a fatal error:
❯ rdrview 'https://github.com/eafer/rdrview'
(null): fatal error in function main(), line 1199
Around that line, code reads:
LIBXML_TEST_VERSION
/* I made a mess mixing xmlMalloc() and malloc(), so play it safe here */
if (xmlMemSetup(free, malloc, realloc, strdup))
fatal();
Is there a related known issue? What may be the probable cause? Thanks in advance.
Initial debugging:
xml2-config --version && xml2-config --cflags && xml2-config --libs)
⎿ 2.9.13
-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lxml2 -lz -lpthread -licucore -lm
This seems to exactly match the version required by LIBXML_TEST_VERSION.
OK, it seems that I could just comment out the two lines about xmlMemSetup, and now it runs perfectly!
rdrview -B cha 'https://github.com/eafer/rdrview' --disable-sandbox
Sharing my trivial script to automate patching this on Mac, after cloning the repo and cd into it:
git apply <<EOF
diff --git a/src/rdrview.c b/src/rdrview.c
index d496bd0..97fb54b 100644
--- a/src/rdrview.c
+++ b/src/rdrview.c
@@ -1195,8 +1195,8 @@ int main(int argc, char *argv[])
LIBXML_TEST_VERSION
/* I made a mess mixing xmlMalloc() and malloc(), so play it safe here */
- if (xmlMemSetup(free, malloc, realloc, strdup))
- fatal();
+ // if (xmlMemSetup(free, malloc, realloc, strdup))
+ // fatal();
set_cleanup_handlers();
parse_arguments(argc, argv);
EOF
make && sudo make install
My use case is to use it with chawan per https://chawan.net/doc/cha/troubleshooting.html (question: Why does $WEBSITE look awful?), the config needs to be changed to
[page]
' r' = "pager.externFilterSource('rdrview -Hu \"$CHA_URL\" --disable-sandbox')"
Note that --disable-sandbox has some risks documented here.
Hi, thanks for the report. I've never tested this on a Mac so I guess it's not surprising that there are some issues. The line in question is there just in case xmlMalloc() and malloc() are different incompatible functions, which I hope will never happen in practice. So there's no problem with commenting it out as long as everything works for you.
I still want to figure out why it fails when I have the time, so I'm leaving this open.
I'm happy to help if you need me to conduct some testing on Mac to further investigate the cause, or any other aspects of rdrview on Mac.
xmlMemSetup is meant to accept custom allocation functions, C standard allocation functions shouldn't have issues. Now it just fails without further info, maybe I should check the issue with upstream.
xmlMemSetup is meant to accept custom allocation functions, C standard allocation functions shouldn't have issues.
I understand what it's for, the problem is that there are some points in the code where I irresponsibly called stdlib free() on something allocated by xmlMalloc(). I would be surprised if xmlMalloc() was anything other than just malloc(), but I don't want to risk it.
I'm happy to help if you need me to conduct some testing on Mac
Thanks!
After failing to sign up for https://gitlab.gnome.org/GNOME/libxml2 to report the issue, I realized that I should try newer libxml2 instead, and it worked without the patch! Sorry I didn't try this first.
Reproducing the failure with the mac systam libxml2:
❯ make clean && make && ./rdrview
#...most output omitted...
(null): fatal error in function main(), line 1199
Use homebrew libxml2 and works:
❯ brew install libxml2
#...most output omitted...with hints on configuring the env vars
❯ export PATH="/opt/homebrew/opt/libxml2/bin:$PATH"
❯ xml2-config --version && xml2-config --cflags && xml2-config --libs
2.13.8
-I/opt/homebrew/opt/libxml2/include/libxml2
-L/opt/homebrew/opt/libxml2/lib -lxml2 -lz -L/opt/homebrew/opt/icu4c@77/lib -licuuc -liconv
make clean && make && ./rdrview -B cha 'https://github.com/eafer/rdrview' --disable-sandbox
# works!
Huh, so you think this was an actual bug in libxml2? Weird.
xmlMemSetup was disabled by Apple in their libxml2 build since macOS 15.4: https://developer.apple.com/documentation/macos-release-notes/macos-15_4-release-notes
Ah, thanks! I guess I'll put some version checks on macos and only use malloc/free over there.
@utensil I just pushed a patch for this, when you can let me know if it fixed your problem.
Sorry for the delay due to weekend, I just tried the latest git commit, without and with brew-installed libxml2, both build pass and work.
But there is a wall of warnings for without brew-installed libxml2, they are basically warning: 'xmlMalloc' macro redefined [-Wmacro-redefined].
I've attached tha build log as build.txt (without brew-installed libxml2).
Thanks. I think this should silence the warnings. When you can let me know if it worked.