From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30637 invoked from network); 1 Jul 2023 07:43:51 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 1 Jul 2023 07:43:51 -0000 Received: (qmail 3920 invoked by uid 550); 1 Jul 2023 07:43:48 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 3882 invoked from network); 1 Jul 2023 07:43:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688197415; x=1690789415; h=to:subject:message-id:date:from:reply-to:mime-version:from:to:cc :subject:date:message-id:reply-to; bh=yrlaoqkV1y+T62W1GXdxiBOyluNCmc1RrXYPKhnksfg=; b=OdujQOIP8ueEk6ASqTmqQuGdm+R2aUWLViOyNnA9V/E0fgxYxW//09MyJX5qOUpFMB nvBt6LGMG5j5FY3wVwqiccxki/3VoSZN3FB5F9LP4z/aUqjn2vu/y8eY7Wyxauf+s+LB pIvLaCrOUpd9KlpGNZRzIOpBsqhXIRq+DOdMqKGQcVHHXF0AQSdWhDbhpxKi/pd7RxUA T3+n2nnmPAIG8gAzuWZwf+wbookDT2Nsvhm/nzLcMK7ZBHeM4S8ZsnI5WK9GMnv9QQG3 j5bd5o7CQCpGzhGHxixqn3cCokfo5HjVbc3WziEwamPbAOqrTlidFtLX/c4LGGQhgaOh NZmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688197415; x=1690789415; h=to:subject:message-id:date:from:reply-to:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yrlaoqkV1y+T62W1GXdxiBOyluNCmc1RrXYPKhnksfg=; b=b4sUYRMrYRboJNZ9DisURS2l6PgAfwaBAuutffmdb41OnVz56DR4riTUnTsGuaWnHG bw5Q8tSyOZ3bVCuvs4+Dc64gLSa2BfZrGzEyyF/tl4oeNmvv1H4YkuYqvs1qz/3BxmeZ XUCgmJAj9PO3vfumHQNRRqtviR9HRkjxc3WrrP0gaoUtt+PYZgafub6wqeTOxQxl61Lv LjsHk6bzX8FGuaE0gVfi2syivO2IcJ8l/lQPktXVnZ9vsMeoF+FgX353Yshmmnhdcc3W xy1pQDWIR4e6+X7qpu8C2XFyr5iPjMxO5nNKj7j9oocIKlYROLl7hYI2ALnVIHvxDZLc bV8Q== X-Gm-Message-State: AC+VfDy6HcJ71t4x3XveSKG1XN/Rm9HyxCa9atBKji0CmlT42Afw+OwI Q3uW1A3BYewX7kC4HTwXlc6KuVhsCAWbjx6TJ79Swko8RrY= X-Google-Smtp-Source: ACHHUZ7YMQ5qVT3s5+qqKG/gXqM2APguG6XPia1E/C9n729g4G56MRUMBJJC1ImPEuEffI/8h0mES9NscdiPuVIYmRY= X-Received: by 2002:a4a:4186:0:b0:565:a01c:e380 with SMTP id x128-20020a4a4186000000b00565a01ce380mr4536813ooa.4.1688197415361; Sat, 01 Jul 2023 00:43:35 -0700 (PDT) MIME-Version: 1.0 From: zxuiji Date: Sat, 1 Jul 2023 08:43:23 +0100 Message-ID: To: musl@lists.openwall.com Content-Type: text/plain; charset="UTF-8" Subject: [musl] C89 Compatible techniques for emulating certain C++ behaviours 1. template x.h: #define A #define B #include "y.h" y.h: /* Template, expects A, B, ... */ ... #undef A #undef B 2. Inheritance /* x.h */ #define T void typedef struct { #include "struct_buffer_members.h" ... }; struct_buffer_members.h size_t pad; /* Node size, stored to avoid duplicate functions */ size_t cap; /* Total size of the buffer */ uint len; uint pos; T *top; #undef T 3. __INCLUDE_LEVEL__ can be used to create a preprocessor for loop x.h: #define END 10 #define INC y.h #include for.h: #ifndef BEGAN #define BEGAN __INCLUDE_LEVEL__ #endif /* Can't concate this but it's still better than nothing */ #define I (BEGAN - __INCLUDE_LEVEL) #if I < END #include INC #undef I #include __FILE__ #endif #undef BEGAN >From here it's more techniques that can be used that you may not be aware of: 1. Thread syncronisation: linked lists, lock must ALWAYS be held by a thread, initialiser gets it 1st. Lock holder is responsible for passing onto another thread, threads just randomly write to a volatile member their ID or the pointer to the link they allocated and expect to be linked, they simply check the "next" link is not equal to itself after each yield they make. 2. setlongjmp etc can be used to emulate threads where none are available, caviets exist however, can possibly create a pre-existing stack copy prior to main() to get default state of globals when __thread_local etc are unavailable 3. Linked lists can have the benefits of arrays typedef struct _link { int i; struct _link *prev_offset, *next_offset; } typedef struct { link *head_offset, *head_removed_offset, *root; struct_buffer _links, _data } link_list_struct; ... /* Examples of offset usage */ link->next = next - link; link->prev = link - prev; link += link->next;