From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 5/6] remove bytes:: for length checks
Date: Mon, 21 Sep 2015 11:11:11 +0000 [thread overview]
Message-ID: <20150921111112.18873-6-e@80x24.org> (raw)
In-Reply-To: <20150921111112.18873-1-e@80x24.org>
Apparently, my mental model of Perl internals is still incorrect
after all these years. I am but a simple *nix programmer:
everything is a bag of bytes to me.
This fixes a problem with UTF-8 headers from Xapian (via "XHDR
Subject [range]") triggering partial writes and writing an extra
newline to the outputs.
---
lib/PublicInbox/Filter.pm | 2 +-
lib/PublicInbox/GitCatFile.pm | 2 +-
lib/PublicInbox/NNTP.pm | 6 +++---
public-inbox-nntpd | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lib/PublicInbox/Filter.pm b/lib/PublicInbox/Filter.pm
index 84df0e7..cab6aad 100644
--- a/lib/PublicInbox/Filter.pm
+++ b/lib/PublicInbox/Filter.pm
@@ -233,7 +233,7 @@ sub replace_body {
sub recheck_type_ok {
my ($part) = @_;
my $s = $part->body;
- ((bytes::length($s) < 0x10000) &&
+ ((length($s) < 0x10000) &&
($s =~ /\A([\P{XPosixPrint}\f\n\r\t]+)\z/))
}
diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm
index dd3f291..48ae673 100644
--- a/lib/PublicInbox/GitCatFile.pm
+++ b/lib/PublicInbox/GitCatFile.pm
@@ -41,7 +41,7 @@ sub cat_file {
my ($self, $object, $sizeref) = @_;
$object .= "\n";
- my $len = bytes::length($object);
+ my $len = length($object);
$self->_cat_file_begin;
my $written = syswrite($self->{out}, $object);
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index fb93330..2b580d1 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -771,9 +771,9 @@ sub do_more ($$) {
if (MSG_MORE && !$self->{write_buf_size}) {
my $n = send($self->{sock}, $data, MSG_MORE);
if (defined $n) {
- my $dlen = bytes::length($data);
+ my $dlen = length($data);
return 1 if $n == $dlen; # all done!
- $data = bytes::substr($data, $n, $dlen - $n);
+ $data = substr($data, $n, $dlen - $n);
}
}
$self->do_write($data);
@@ -813,7 +813,7 @@ again:
}
return $self->close if $r < 0;
- my $len = bytes::length($self->{rbuf});
+ my $len = length($self->{rbuf});
return $self->close if ($len >= LINE_MAX);
}
diff --git a/public-inbox-nntpd b/public-inbox-nntpd
index 0395e98..674ecad 100644
--- a/public-inbox-nntpd
+++ b/public-inbox-nntpd
@@ -172,13 +172,13 @@ sub sockname {
my ($s) = @_;
my $n = getsockname($s) or return;
my ($port, $addr);
- if (bytes::length($n) >= 28) {
+ if (length($n) >= 28) {
require Socket6;
($port, $addr) = Socket6::unpack_sockaddr_in6($n);
} else {
($port, $addr) = Socket::sockaddr_in($n);
}
- if (bytes::length($addr) == 4) {
+ if (length($addr) == 4) {
$n = Socket::inet_ntoa($addr)
} else {
$n = '['.Socket6::inet_ntop(Socket6::AF_INET6(), $addr).']';
--
EW
next prev parent reply other threads:[~2015-09-21 11:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-21 11:11 [PATCH 0/6] more NNTP server updates Eric Wong
2015-09-21 11:11 ` [PATCH 1/6] msgmap: minor cleanup to move constant declaration Eric Wong
2015-09-21 11:11 ` [PATCH 2/6] nntp: speed up XHDR Xref for rtin Eric Wong
2015-09-21 11:11 ` [PATCH 3/6] nntp: speed up xover slightly Eric Wong
2015-09-21 11:11 ` [PATCH 4/6] t/nntpd.t: improve test runnability Eric Wong
2015-09-21 11:11 ` Eric Wong [this message]
2015-09-21 11:11 ` [PATCH 6/6] nntp: proper UTF-8 support (hopefully?) Eric Wong
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=20150921111112.18873-6-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).