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

[src/snmalloc/ds_core/redblacktree.h] Make free-standing #673

Closed
wants to merge 1 commit into from

Conversation

SamuelMarks
Copy link

@SamuelMarks SamuelMarks commented Sep 6, 2024

Closes #670.

Taking a quick look:

$ rg -IFNth --trim '#include <' | sort -u
#include <array>
#include <atomic>
#include <chrono>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <errno.h>
#include <fcntl.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <new>
#include <sstream>
#include <stddef.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <strings.h>
#include <string_view>
#include <sys/mman.h>
#include <sys/uio.h>
#include <type_traits>
#include <unistd.h>
#include <utility>

I'm not sure how much of this can obviously be removed without looking really wonky in the C++ world.

Maintainers / @SchrodingerZhu - do you just want a C port of this?

@nwf
Copy link
Collaborator

nwf commented Sep 6, 2024

I think I'd prefer that the debugging code in redblacktree.h, which seems to be the sole consumer of <string>, as well as its #include, be made conditional on __STDC_HOSTED__ being nonzero. (See https://en.cppreference.com/w/cpp/freestanding). @mjp41?

ETA: We should also have at least one -ffreestanding CI build, if that's something people care about. :)

@mjp41
Copy link
Member

mjp41 commented Sep 24, 2024

In this case this is just code that is executed by the test harness to unit test the RB tree. I would sooner this be under and #ifdef, so that it isn't compiled with the library just the unit tests.

@mjp41
Copy link
Member

mjp41 commented Sep 24, 2024

I have redone your idea, but with stack allocation in #680, and also copied the original contents into the string.

I would sooner not take a dependence on malloc/free in this code. The std::string did have a dependence on an allocator, which is not nice for allocator debug code.

@mjp41 mjp41 closed this Oct 6, 2024
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.

Is it possible to make snmalloc freestanding?
3 participants