troydhanson / uthash

C macros for hash tables and more
Other
4.18k stars 926 forks source link

Disabling utstring specific features #147

Closed silvioprog closed 6 years ago

silvioprog commented 6 years ago

Hello dudes.

Many GNU libraries allows to enable/disable any specific or extended features via building system to generate smaller libraries even disabling the compiler optimizations. For example, in libcurl building, you can do ./configure --disable-cookies before making it using make install -- it will generate and install a smaller libcurl without cookies support; in libmicrohttpd, you can use ./configure --disable-httpupgrade --disable-sendfile before make install-strip and it will generate/install the smallest libmicrohttp without HTTP-Upgrade/SendFile support. And so on.

So, what do you think about to use this same approach in utstring? For example (notice UTSTRING_FIND_DISABLED):

#ifndef UTSTRING_FIND_DISABLED

/*******************************************************************************
 * begin substring search functions                                            *
 ******************************************************************************/
/* Build KMP table from left to right. */
UTSTRING_UNUSED static void _utstring_BuildTable(

... the find feature stuff ...

    return V_FindPosition;
}
/*******************************************************************************
 * end substring search functions                                              *
 ******************************************************************************/

#endif /* UTSTRING_FIND_DISABLED */

then a programmer could do:

#define UTSTRING_FIND_DISABLED 1
#include <utstring.h>

int main() {
...

or passing -DUTSTRING_FIND_DISABLED=1 in their building system.

I tested it in a library and the final generated static library was 17.8 kB using UTSTRING_FIND_DISABLED 1 against 22.4 kB in original way, even without informing any compiler optimization.

It would be very helpful a way to disable the utstring-find feature allowing utstring to be used for who that just wants as a stream structure replacement.

Quuxplusone commented 6 years ago

When you say "without informing [enabling?] any compiler optimization", that's a signal that your results aren't applicable to the real world. If you care about codegen size, you need to turn on -O3, at which point you'll see the unused functions disappear.

silvioprog commented 6 years ago

[enabling?]

Yes.

that's a signal that your results aren't applicable to the real world

Even in debug mode? The libraries that allows to disable specific features allows less symbols at debugging time.

Quuxplusone commented 6 years ago

The examples you give from libcurl and microhttpd have nothing to do with debugging; they're locking down certain unsafe features for security reasons.

silvioprog commented 6 years ago

+1 Indeed. I tested enabling the compiler optimizations and the symbols disappears. Really makes no sense to add UTSTRING_FIND_DISABLED.