mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Minor style patch to exit.c
@ 2020-01-19 11:07 Markus Wichmann
  2020-01-19 11:12 ` Markus Wichmann
  2020-01-19 11:31 ` Szabolcs Nagy
  0 siblings, 2 replies; 21+ messages in thread
From: Markus Wichmann @ 2020-01-19 11:07 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 548 bytes --]

Hi all,

it has often been said that if a LISP programmer were tasked with
catching an elephant, they would build a maze of parentheses in which
the elephant gets lost. If so, then libc_exit_fini() provides a nice
starting point for such a maze, even if it was started in C.

In all seriousness, the logic of the function is to iterate over an
array of function pointers, so why not write down that that's what it
does instead of iterating over some numbers that happen to be
convertible to such? Or is there something I have missed?

Ciao,
Markus

[-- Attachment #2: 0001-Make-libc_exit_fini-easier-to-read.patch --]
[-- Type: text/x-diff, Size: 1127 bytes --]

From 44e09392c72cbd72c1e5b4ec3dea71f9b38e13c8 Mon Sep 17 00:00:00 2001
From: Markus Wichmann <nullplan@gmx.net>
Date: Sun, 19 Jan 2020 11:58:51 +0100
Subject: [PATCH] Make libc_exit_fini() easier to read.

The previous version did have a maze of parentheses here. But the actual
logic of the function is not to iterate over some numbers that happen to
be convertible to pointers, but rather to iterate over an array of
function pointers. So let us use pointer arithmetic correctly.
---
 src/exit/exit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/exit/exit.c b/src/exit/exit.c
index a6869b37..e02ba2be 100644
--- a/src/exit/exit.c
+++ b/src/exit/exit.c
@@ -16,9 +16,9 @@ extern weak hidden void (*const __fini_array_start)(void), (*const __fini_array_

 static void libc_exit_fini(void)
 {
-	uintptr_t a = (uintptr_t)&__fini_array_end;
-	for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)()))
-		(*(void (**)())(a-sizeof(void(*)())))();
+	void (*const *a)() = &__fini_array_end;
+	while (a > &__fini_array_start)
+		(*--a)();
 	_fini();
 }

--
2.17.1


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2020-01-19 21:34 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-19 11:07 [musl] Minor style patch to exit.c Markus Wichmann
2020-01-19 11:12 ` Markus Wichmann
2020-01-19 11:31 ` Szabolcs Nagy
2020-01-19 12:17   ` Markus Wichmann
2020-01-19 13:33   ` Alexander Cherepanov
2020-01-19 14:24     ` Markus Wichmann
2020-01-19 14:49       ` Pascal Cuoq
2020-01-19 15:53       ` Alexander Cherepanov
2020-01-19 16:22         ` Rich Felker
2020-01-19 21:02           ` Alexander Cherepanov
2020-01-19 14:46     ` Alexander Monakov
2020-01-19 16:18       ` Rich Felker
2020-01-19 17:11         ` Alexander Monakov
2020-01-19 17:17           ` Alexander Monakov
2020-01-19 17:19           ` Rich Felker
2020-01-19 17:32             ` Alexander Monakov
2020-01-19 17:38               ` Rich Felker
2020-01-19 19:13                 ` Alexander Monakov
2020-01-19 16:33       ` Alexander Cherepanov
2020-01-19 16:39         ` Rich Felker
2020-01-19 21:34           ` Alexander Cherepanov

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).