unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/4] syscall: golf + more idiomatic buffer initialization
Date: Mon, 18 Apr 2022 09:50:04 +0000	[thread overview]
Message-ID: <20220418095004.466-5-e@80x24.org> (raw)
In-Reply-To: <20220418095004.466-1-e@80x24.org>

While `vec' is useful for user-supplied buffers to avoid excess
memory traffic, but provides no benefit when we need to allocate
our own buffers as we do in nodatacow_fh, since Perl can't elide
memset(ptr, 0, len).  So just use the idiomatic `"\0" x $LEN' here.
---
 lib/PublicInbox/Syscall.pm | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm
index cc282f9f..22b779ad 100644
--- a/lib/PublicInbox/Syscall.pm
+++ b/lib/PublicInbox/Syscall.pm
@@ -390,12 +390,10 @@ sub rename_noreplace ($$) {
 	}
 }
 
-sub nodatacow_fh {
-	return if !defined($SYS_fstatfs);
-	my $buf = '';
-	vec($buf, 120 * 8 - 1, 1) = 0;
+sub nodatacow_fh ($) {
 	my ($fh) = @_;
-	syscall($SYS_fstatfs, fileno($fh), $buf) == 0 or
+	my $buf = "\0" x 120;
+	syscall($SYS_fstatfs // return, fileno($fh), $buf) == 0 or
 		return warn("fstatfs: $!\n");
 	my $f_type = unpack('l!', $buf); # statfs.f_type is a signed word
 	return if $f_type != 0x9123683E; # BTRFS_SUPER_MAGIC

      parent reply	other threads:[~2022-04-18  9:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-18  9:50 [PATCH 0/4] lei: finish wiring up pure-Perl stuff for Linux Eric Wong
2022-04-18  9:50 ` [PATCH 1/4] lei: clobber recvmsg buffer on errors Eric Wong
2022-04-18  9:50 ` [PATCH 2/4] syscall: more idiomatic cmsghdr space allocation Eric Wong
2022-04-18  9:50 ` [PATCH 3/4] lei: wire up pure Perl sendmsg/recvmsg for Linux users Eric Wong
2022-04-18  9:50 ` Eric Wong [this message]

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: https://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=20220418095004.466-5-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.
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).