From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,NO_DNS_FOR_FROM, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from [192.168.12.80] (unknown [182.2.69.4]) by gnuweeb.org (Postfix) with ESMTPSA id 9458B7E2BC; Sun, 20 Mar 2022 16:10:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1647792621; bh=Fh0VdrTyVcmuu1fbFnCw09xbY33ut+5KdzItGns9LLA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=UDWH2yTXo+mP6hTbBLiTND9+j95EqtRwZnOu4V8Qm3EraDZCBxZ8oJrK/8uD3IbEF kXkU6hVvch4eAzmWXrkuQpwe8cagEDlD9TeDyH/dYZwIqHNRhNv4UhuPWvCeL0e0s5 URXml42WYi5SblRqcOA9lY1vEdl93EImerFDctzSBSpBGpzLbDi1Kblum25AhbCh/z lldwTKr+JqmXcZPj4d2O6Dh6xY5jjBceaX4qWLN12DFfeH2bjirdobs1kEVTSuMskg EJ9598aeSPIlQXsylicBn4gAvSYkz7hAKQpGoi9uaITwdXVO80h8NHw0HXWuU21l1z PuSGM7xr3YqBg== Message-ID: Date: Sun, 20 Mar 2022 23:10:14 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [RFC PATCH v1 5/6] tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()` Content-Language: en-US To: Alviro Iskandar Setiawan Cc: Willy Tarreau , "Paul E. McKenney" , Nugraha , Linux Kernel Mailing List , GNU/Weeb Mailing List References: <20220320093750.159991-1-ammarfaizi2@gnuweeb.org> <20220320093750.159991-6-ammarfaizi2@gnuweeb.org> From: Ammar Faizi In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: On 3/20/22 10:50 PM, Alviro Iskandar Setiawan wrote: > This better be simplified like this, so only have 1 malloc() call that > applies to both branches. > > void *realloc(void *old_ptr, size_t new_size) > { > struct nolibc_heap *heap; > void *ret; > > ret = malloc(new_size); > if (__builtin_expect(!ret, 0)) > return NULL; > > if (!old_ptr) > return ret; > > heap = container_of(old_ptr, struct nolibc_heap, user_p); > memcpy(ret, heap->user_p, heap->len); > munmap(heap, heap->len); > return ret; > } That looks better, will take this for the v2. Thanks! -- Ammar Faizi