home.social

#elif — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #elif, aggregated by home.social.

  1. As it happens, we still use CVS in our operating system project (there are reasons for doing this, but migration to git would indeed make sense).

    While working on our project, we occasionally have to do a full checkout of the whole codebase, which is several gigabytes. Over time, this operation has gotten very, very, very slow - I mean "2+ hours to perform a checkout" slow.

    This was getting quite ridiculous. Even though it's CVS, it shouldn't crawl like this. A quick build of CVS with debug symbols and sampling the "cvs server" process with Linux perf showed something peculiar: The code was spending the majority of the time inside one function.

    So what is this get_memnode() function? Turns out this is a support function from Gnulib that enables page-aligned memory allocations. (NOTE: I have no clue why CVS thinks doing page-aligned allocations is beneficial here - but here we are.)

    The code in question has support for three different backend allocators:
    1. mmap
    2. posix_memalign
    3. malloc

    Sounds nice, except that both 1 and 3 use a linked list to track the allocations. The get_memnode() function is called when deallocating memory to find out the original pointer to pass to the backend deallocation function: The node search code appears as:

    for (c = *p_next; c != NULL; p_next = &c->next, c = c->next)
    if (c->aligned_ptr == aligned_ptr)
    break;

    The get_memnode() function is called from pagealign_free():

    #if HAVE_MMAP
    if (munmap (aligned_ptr, get_memnode (aligned_ptr)) < 0)
    error (EXIT_FAILURE, errno, "Failed to unmap memory");
    #elif HAVE_POSIX_MEMALIGN
    free (aligned_ptr);
    #else
    free (get_memnode (aligned_ptr));
    #endif

    This is an O(n) operation. CVS must be allocating a huge number of small allocations, which will result in it spending most of the CPU time in get_memnode() trying to find the node to remove from the list.

    Why should we care? This is "just CVS" after all. Well, Gnulib is used in a lot of projects, not just CVS. While pagealign_alloc() is likely not the most used functionality, it can still end up hurting performance in many places.

    The obvious easy fix is to prefer the posix_memalign method over the other options (I quickly made this happen for my personal CVS build by adding tactical #undef HAVE_MMAP). Even better, the list code should be replaced with something more sensible. In fact, there is no need to store the original pointer in a list; a better solution is to allocate enough memory and store the pointer before the calculated aligned pointer. This way, the original pointer can be fetched from the negative offset of the pointer passed to pagealign_free(). This way, it will be O(1).

    I tried to report this to the Gnulib project, but I have trouble reaching gnu.org services currently. I'll be sure to do that once things recover.

    #opensource #development #bugstories

  2. Concerto Candlelight degli EliF Natale

    14 dicembre 2025 18:00:00 CET - GMT+1 - Tempio Romanico di San Francesco, 01012, Capranica, Italia

    mobilizon.it/events/e8ae221d-f

  3. Tor Cervara Jazz

    11 aprile 2026 21:00:00 CEST - GMT+2 - Ristorante da Peppe a Tor Cervara, 00155, Roma, Italia

    mobilizon.it/events/ec3ce0e6-d

  4. San Silvestro 2025

    31 dicembre 2025 21:00:00 CET - GMT+1 - Da Antonio, Pizza Gastronomica, 01030, Vasanello, Italy

    mobilizon.it/events/3d5050e5-4

  5. Christmas in Jazz

    December 19, 2025, 8:30:00 PM CET - GMT+1 - Crash Vibes & Wines, 00198, Rome, Italy

    mobilizon.it/events/904caf03-7

  6. Degustazioni Funky

    26 novembre 2025 18:30:00 CET - GMT+1 - Tempio Romanico di San Francesco, 01012, Capranica, Italia

    mobilizon.it/events/81413367-c

  7. So einige Künstler:innen habe ich über ihre Auftritte in Inas Nacht kennengelernt. Auch Elif - und schon allein dafür hätte es sich gelohnt, die Sendung zu schauen: Elif - Auf halber Strecke

    fediserve.de/preview.php?v=mBU…

    #Musik #MusikZurNacht #Elif

  8. @ranvel to be more specific, for a given folder PREFIX, this is my ncurses config:

    ./configure --prefix="$PREFIX" --enable-widec

    and this is my nano config:

    ./configure --prefix="$PREFIX" --disable-nls --enable-utf8 --enable-year2038 NCURSESW_CFLAGS="-I$PREFIX/include" NCURSESW_LIBS="-L$PREFIX/lib -lncursesw"

    With ncurses 6.5 and nano 8.5, that leads to a bunch of linker failures for imports with "$NCURSES60" suffix... which comes from Apple's SDK. And if you look at nano src, you can find this:

    /* Prefer wide ncurses over normal ncurses over curses. */
    #if defined(HAVE_NCURSESW_NCURSES_H)
    #include <ncursesw/ncurses.h>
    #elif defined(HAVE_NCURSES_H)
    #include <ncurses.h>
    #else
    #include <curses.h>
    #endif

    So unless you define HAVE_NCURSESW_NCURSES_H, it will include the wrong header. And while HAVE_NCURSES_H shows up in configure, HAVE_NCURSESW_NCURSES_H does not...

  9. If you're getting the __has_feature error in Unreal, just change that line to #elif 0. Takes 3 seconds, works even in Program Files, no need to bother with downgrading to a particular version of MSVC or whatever people usually recommend as the fix.

  10. Ok I'm confused. What's the relationship between /#Firefox and ?

    Servo was made by Mozilla, right? And today is used in Firefox? And Verso is hoping to one day be a browser we can use? So is this like a lower level fork of Firefox?

    Explain Like I'm Five!

    servo.org/blog/2024/09/11/buil

    github.com/versotile-org/verso

  11. Tor Cervara Jazz

    11 aprile 2026 21:00:00 CEST - GMT+2 - Ristorante da Peppe a Tor Cervara, 00155, Roma, Italia

    mobilizon.it/events/ec3ce0e6-d

  12. Discover how conditional compilation directives can enhance your C programming skills. Learn to use #ifdef, #ifndef, #undef, #if, #else, #elif, and #endif to create more flexible and efficient code. Unlock the power of the C preprocessor!

    teguhteja.id/conditional-compi

  13. Recursive inclusion is possible in C, and more surprisingly it even makes sense in some cases. In fact it provides an easy way to do code unrolling of small code snippets:

    #if !defined(DO_I) || (DO_I < DO_BOUND)# include "do-incr.c"DO_BODY# include __FILE__#endif#undef DO_I

    Here this uses two macros that have to be defined beforehand, DO_BOUND and DO_BODY, and one macro DO_I for a hexadecimal loop counter that is maintained by the include file "do-incr.c". If we hold the above recursive code in some file "doit.c" (plus some extras, see below) we can use this as simply as in

    #define DO_BODY [DO_I] = DO_I,#define DO_BOUND 0x17unsigned array[] = {# include "doit.c"};#undef DO_BODY#undef DO_BOUND

    do generate the intialization of an array,

    unsigned array[] = {[0x0000] = 0x0000,[0x0001] = 0x0001,...[0x0016] = 0x0016,[0x0017] = 0x0017,};

    or with an additional macro DO_NAME (DO_I without a hex prefix) as

    #define ENAME_(X) enum_ ## X#define ENAME(X) ENAME_(X)#define DO_BODY ENAME(DO_NAME) = DO_I,#define DO_BOUND 197enum {# include "doit.c"};#undef DO_BODY#undef DO_BOUND

    for the declaration of an enumeration type

    enum fun {enum_0000 = 0x0000,enum_0001 = 0x0001,...enum_00C4 = 0x00C4,enum_00C5 = 0x00C5,};

    Here the given limit of 197 is in fact a limit that is imposed by gcc for which I was testing this. They restrict the depth of inclusion to 200, unless you raise that limit with the command line option -fmax-include-depth.

    Note also, that the recursive line #include __FILE__ uses a macro to specify the file name because #include lines are indeed evaluated by the preprocessor if necessary.

    Recursion is only reasonable if we have a stop condition, so to handle this the include file "do-incr.c" is crucial. Since in standard C we have no way to evaluate the line of a #define while processing it, we have to ensure that we can change the value of DO_I. That file looks something like

    #ifndef DO_I# undef  DO_I0# define DO_I0 0# undef  DO_I1# define DO_I1 0# undef  DO_I2# define DO_I2 0# undef  DO_I3# define DO_I3 0# define DO_I DO_HEX(DO_NAME)#elif DO_HEX(DO_I0) == 0# undef DO_I0# define DO_I0 1#elif DO_HEX(DO_I0) == 1# undef DO_I0# define DO_I0 2...#elif DO_HEX(DO_I0) == 0xF# undef DO_I0# define DO_I0 0# include "do-incr1.c"#endif

    As you may have guessed, this uses macros DO_I0, DO_I1, DO_I2, and DO_I3 as hexdigits of a 16 bit number, and includes another file "do-incr1.c" if the digit DO_I0 overflows.

    I hope that if you are interested in this technique, you will be able to join the dots in the above code. To be complete, here are the macros that join the digits to make a hexnumber (DO_HEX) and to make a name component (DO_NAME):

    #ifndef DO_HEX# define DO_HEX_(X) 0x ## X# define DO_HEX(X) DO_HEX_(X)# define DO_NAME_(A, B, C, D) A ## B ## C ## D# define DO_NAME_IIII(A, B, C, D) DO_NAME_(D, C, B, A)# define DO_NAME DO_NAME_IIII(DO_I0, DO_I1, DO_I2, DO_I3)#endif

    https://gustedt.wordpress.com/2024/05/30/include-__file__/

    #define #elif #endif #undef