Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setCAllocator #199

Merged
merged 12 commits into from
Apr 19, 2024
Merged

setCAllocator #199

merged 12 commits into from
Apr 19, 2024

Conversation

francisbouvier
Copy link
Member

@francisbouvier francisbouvier commented Mar 20, 2024

Replace custom malloc functions in netsurf libs with a global Zig allocator mimalloc

ℹ️ install mimalloc with make install-submodule && make install-mimalloc

Relates to lightpanda-io/libdom#8
Cause #197

@krichprollsch
Copy link
Member

krichprollsch commented Mar 21, 2024

We must change the modules source url.

$ git submodule update 
Submodule path 'vendor/netsurf/libdom': checked out '6c87ab81ce6c1a0020267dff27b32da83f73e796'
error: Unable to find 79d3303613a5dacb90e1e42129ab0e7ab2068b79 under https://source.netsurf-browser.org/libhubbub.git
Cannot obtain needed object 79d3303613a5dacb90e1e42129ab0e7ab2068b79
error: fetch failed.
fatal: Fetched in submodule path 'vendor/netsurf/libhubbub', but it did not contain 79d3303613a5dacb90e1e42129ab0e7ab2068b79. Direct fetching of that commit failed.
$ git submodule set-url vendor/netsurf/libhubbub [email protected]:lightpanda-io/libhubbub.git
$ git submodule set-url vendor/netsurf/libparserutils [email protected]:lightpanda-io/libparserutils.git
$ git submodule set-url vendor/netsurf/libwapcaplet [email protected]:lightpanda-io/libwapcaplet.gi

I push a commit.

@krichprollsch
Copy link
Member

The tests crash on my laptop:

$ make test
Testing...
steps [2/4] zig test Debug native... LLD Link... Generate Union: OK
Generate Tuple: OK
Segmentation fault at address 0x0
/usr/local/zig-0.12.0-dev.1773+8a8fd47d2/lib/std/mem/Allocator.zig:86:29: 0xc74638 in allocBytesWithAlignment__anon_184136 (test)
    return self.vtable.alloc(self.ptr, len, ptr_align, ret_addr);
                            ^
/usr/local/zig-0.12.0-dev.1773+8a8fd47d2/lib/std/mem/Allocator.zig:211:40: 0xc409ba in allocWithSizeAndAlignment__anon_182964 (test)
    return self.allocBytesWithAlignment(alignment, byte_count, return_address);
                                       ^
/usr/local/zig-0.12.0-dev.1773+8a8fd47d2/lib/std/mem/Allocator.zig:205:75: 0xbfb446 in alignedAlloc__anon_181479 (test)
    const ptr: [*]align(a) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeOf(T), a, n, return_address));
                                                                          ^
/home/pierre/wrk/browsercore/src/calloc.zig:106:35: 0xbfb2c1 in m_alloc (test)
    const buf = alloc.alignedAlloc(u8, al, buf_len) catch |err| switch (err) {
                                  ^
bindings/hubbub/parser.c:779:12: 0x13028eb in dom_hubbub_parser_create (bindings/hubbub/parser.c)
/home/pierre/wrk/browsercore/src/netsurf.zig:1847:37: 0xbef036 in documentHTMLParse__anon_181429 (test)
    err = c.dom_hubbub_parser_create(&params, &parser, &doc);
                                    ^
/home/pierre/wrk/browsercore/src/run_tests.zig:48:39: 0xb8f651 in testExecFn__anon_178441 (test)
    doc = try parser.documentHTMLParse(file.reader(), "UTF-8");
                                      ^
/home/pierre/wrk/browsercore/src/run_tests.zig:87:23: 0xb6f48c in testsAllExecFn (test)
        try testExecFn(alloc, js_env, testFn);
                      ^
/home/pierre/wrk/browsercore/vendor/jsruntime-lib/src/engine.zig:45:18: 0xb6e5e5 in loadEnv__anon_11051 (test)
    try ctxExecFn(alloc, &js_env);
                 ^
/home/pierre/wrk/browsercore/src/run_tests.zig:129:26: 0xb6fef4 in testJSRuntime (test)
    try jsruntime.loadEnv(&arena_alloc, testsAllExecFn);
                         ^
/home/pierre/wrk/browsercore/src/run_tests.zig:95:22: 0xb70353 in main (test)
    try testJSRuntime();
                     ^
/home/pierre/wrk/browsercore/src/test_runner.zig:8:19: 0xb70720 in main (test)
    try tests.main();
                  ^
/usr/local/zig-0.12.0-dev.1773+8a8fd47d2/lib/std/start.zig:585:37: 0xb70ae6 in main (test)
            const result = root.main() catch |err| {
                                    ^
../sysdeps/nptl/libc_start_call_main.h:58:16: 0x7fb756e366c9 in __libc_start_call_main (../sysdeps/x86/libc-start.c)
../csu/libc-start.c:360:3: 0x7fb756e36784 in __libc_start_main_impl (../sysdeps/x86/libc-start.c)
???:?:?: 0xb61020 in ??? (???)
???:?:?: 0x0 in ??? (???)
run test: error: the following command terminated unexpectedly:
/home/pierre/wrk/browsercore/zig-cache/o/8a18626da9a8346948d29d48b51be84f/test 
Build Summary: 2/4 steps succeeded; 1 failed (disable with --summary none)
test transitive failure
└─ run test failure
error: the following build command failed with exit code 1:
/home/pierre/wrk/browsercore/zig-cache/o/dd65a65dd4c0b5ecdb2d8bb615172571/build /usr/local/zig-0.12.0-dev.1773+8a8fd47d2/zig /home/pierre/wrk/browsercore /home/pierre/wrk/browsercore/zig-cache /home/pierre/.cache/zig --seed 0x5d5966cc test -Dengine=v8
Test ERROR

@krichprollsch krichprollsch marked this pull request as draft March 21, 2024 10:10
@krichprollsch krichprollsch self-assigned this Apr 9, 2024
@krichprollsch krichprollsch removed their request for review April 9, 2024 14:26
@krichprollsch krichprollsch marked this pull request as ready for review April 10, 2024 07:29
@krichprollsch
Copy link
Member

krichprollsch commented Apr 16, 2024

The WPT test tests/wpt/dom/events/Event-dispatch-handlers-changed.html stucks the process

fixed by lightpanda-io/libdom#16

francisbouvier and others added 11 commits April 19, 2024 11:46
Replace custom malloc functions in netsurf libs with a global Zig allocator.

Signed-off-by: Francis Bouvier <[email protected]>
By default mimalloc is built to override default allocation functions.
So it is used also by v8.

This change avoid the mimalloc override to keep the native stdlib
functions.
@krichprollsch krichprollsch merged commit 2a94e5a into main Apr 19, 2024
7 checks passed
@krichprollsch krichprollsch deleted the c_alloc branch April 19, 2024 10:05
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.

2 participants