chriso / intern

Fast, efficient string interning
MIT License
90 stars 6 forks source link

Consider adding mechanism for user-defined allocation/hashing #1

Open sbseltzer opened 7 years ago

sbseltzer commented 7 years ago

This is a nice library. Thanks for making it!

A number of other C libraries I've used include facilities for users optionally specifying their own allocation and hashing methods. This can be quite useful for testing and portability. Perhaps you could consider adding something like this?

chriso commented 7 years ago

It's not something I need personally, but I'd be happy to accept a PR if it's useful for somebody else.

You could allow compile-time function names to be passed via config.h.

sbseltzer commented 7 years ago

Thanks for the response! I was considering working on a PR with that plus unit tests, as I usually get nervous when I don't see unit tests with something. Libraries that intern stuff are nice to test with malloc/free wrappers to ensure memory management works as expected on all platforms, but for now I can settle for using valgrind.

I'm hoping to use this for a very cross-platform project so if I come across portability problems that are simple to fix I'll probably fork and submit a PR.

chriso commented 7 years ago

There's good coverage of the library in ./tests.c that passes valgrind and clang's analysis tools without errors (although I haven't checked recently). You can run the tests using:

$ mkdir build && cd build
$ cmake ..
$ make check

I'd be happy to accept any portability fixes but I imagine CMake does a good job already.