user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] devel/sysdefs-list: cleanup and make partially eval-able
Date: Sat, 16 Sep 2023 21:33:14 +0000	[thread overview]
Message-ID: <20230916213314.2392629-1-e@80x24.org> (raw)

It's stdout can now be placed into a Perl hash, now.

The MAYBE pseudo-macro can now emit hex as well as decimal
output to make some constants look nicer and eliminate some
special cases.

Constants for _SC_AVPHYS_PAGES and _SC_PAGE*SIZE have also been
added in case we dynamically generate BATCH_SIZE for search
indexing

I'm not sure how far I want to go down this route, but it could
open the door to us supporting more things on platforms with
unstable syscall numbers with only a C compiler, but without
relying on needing Inline::C (nor XS and difficult-to-audit
binaries).  This is because a C compiler is readily installed on
more systems than Inline::C (even if packaged) requires an
additional installation step.
---
 devel/sysdefs-list | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/devel/sysdefs-list b/devel/sysdefs-list
index aa7806ae..edac253b 100755
--- a/devel/sysdefs-list
+++ b/devel/sysdefs-list
@@ -11,13 +11,13 @@ use v5.12;
 use File::Temp 0.19;
 use POSIX qw(uname);
 use Config;
-say '$machine='.(POSIX::uname())[-1];
+print STDERR '# $machine='.(POSIX::uname())[-1]."\n";
 my $cc = $ENV{CC} // $Config{cc} // 'cc';
 my @cflags = split(/\s+/, $ENV{CFLAGS} // $Config{ccflags} // '-Wall');
 my $str = do { local $/; <DATA> };
-$str =~ s/^\s*MAYBE\s*(\w+)\s*$/
-#ifdef $1
-	D($1);
+$str =~ s/^\s*MAYBE\s*([DX])\((\w+)\)/
+#ifdef $2
+	$1($2);
 #endif
 /sgxm;
 my $tmp = File::Temp->newdir('sysdefs-list-XXXX', TMPDIR => 1);
@@ -27,8 +27,9 @@ open my $fh, '>', $f or die "open $f $!";
 print $fh $str or die "print $f $!";
 close $fh or die "close $f $!";
 system($cc, '-o', $x, $f, @cflags) == 0 or die "$cc failed \$?=$?";
-say '%Config', map { " $_=$Config{$_}" } qw(ptrsize sizesize lseeksize);
-exec($x);
+print STDERR '# %Config',
+	(map { " $_=$Config{$_}" } qw(ptrsize sizesize lseeksize)), "\n";
+exit(system($x)); # exit is to ensure File::Temp::Dir->DESTROY fires
 __DATA__
 #ifndef _GNU_SOURCE
 #  define _GNU_SOURCE
@@ -50,8 +51,8 @@ __DATA__
 #include <unistd.h>
 #include <stdio.h>
 
-#define STRUCT_BEGIN(t) do { t x; printf(#t" => %zu bytes\n", sizeof(x))
-#define STRUCT_END } while (0)
+#define STRUCT_BEGIN(t) do { t x; printf("'"#t"' => '%zu bytes\n", sizeof(x))
+#define STRUCT_END puts("',"); } while (0)
 
 // prints the struct field name, @offset, and signed/unsigned bit size
 #define PR_NUM(f) do { \
@@ -71,17 +72,20 @@ __DATA__
 	printf("\t.%s @%zu\n", #f, offsetof(typeof(x),f)); \
 } while (0)
 
-#define D(x) printf("$" #x " = %ld;\n", (long)x)
+#define D(x) printf(#x " => %ld,\n", (long)x)
+#define X(x) printf(#x " => 0x%lx,\n", (unsigned long)x)
 
 int main(void)
 {
 	// verify Config{(ptr|size|lseek)size} entries match:
-	printf("sizeof ptr=%zu size_t=%zu off_t=%zu\n",
-		sizeof(void *), sizeof(size_t), sizeof(off_t));
+	printf("'sizeof(ptr)' => %zu,\n", sizeof(void *));
+	printf("'sizeof(size_t)' => %zu,\n", sizeof(size_t));
+	printf("'sizeof(off_t)' => %zu,\n", sizeof(off_t));
+
 #ifdef __linux__
 	D(SYS_epoll_create1);
 	D(SYS_epoll_ctl);
-	MAYBE SYS_epoll_wait
+	MAYBE D(SYS_epoll_wait);
 	D(SYS_epoll_pwait);
 	D(SYS_signalfd4);
 	D(SYS_inotify_init1);
@@ -91,11 +95,11 @@ int main(void)
 	D(SYS_fstatfs);
 	D(SYS_sendmsg);
 	D(SYS_recvmsg);
-#ifdef FS_IOC_GETFLAGS
-	printf("FS_IOC_GETFLAGS=%#lx\nFS_IOC_SETFLAGS=%#lx\n",
-		(unsigned long)FS_IOC_GETFLAGS, (unsigned long)FS_IOC_SETFLAGS);
-#endif
-	MAYBE SYS_renameat2
+
+	MAYBE X(FS_IOC_GETFLAGS);
+	MAYBE X(FS_IOC_SETFLAGS);
+
+	MAYBE D(SYS_renameat2);
 
 	STRUCT_BEGIN(struct epoll_event);
 		PR_NUM(events);
@@ -135,7 +139,10 @@ int main(void)
 	STRUCT_END;
 #endif /* Linux, any other OSes with stable syscalls? */
 	D(SIGWINCH);
-	MAYBE _SC_NPROCESSORS_ONLN
+	MAYBE D(_SC_NPROCESSORS_ONLN);
+	MAYBE D(_SC_AVPHYS_PAGES);
+	MAYBE D(_SC_PAGE_SIZE);
+	MAYBE D(_SC_PAGESIZE);
 
 	STRUCT_BEGIN(struct flock);
 		PR_NUM(l_start);

                 reply	other threads:[~2023-09-16 21:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230916213314.2392629-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).