Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.84k stars 524 forks source link

what's the point of example code if it is buggy? #2907

Closed p5pRT closed 20 years ago

p5pRT commented 23 years ago

Migrated from rt.perl.org#4792 (status was 'resolved')

Searchable as RT4792$

p5pRT commented 23 years ago

From @nwc10

Created by @nwc10

What's the \ point of example code if it's buggy? Not only do some of the perlipc code fail to compile in the first place\, but even when you fix those bugs two have subtle precedence bugs w.r.t. "or" versus "||" and scalar/list context.

Bugs remaining

1​: I've no idea what the missing text after "We'll" should be​:

  a time. Multithreaded servers are covered in Chapter 6 of   the Camel.

  Here's the code. We'll

  #!/usr/bin/perl -w

2​: The example that follows uses Net​::hostent. It's not working becuse   Net​::hostent in bleadperl is shagged.

3​: Net​::hostent doesn't have a regression test to detected that it's shagged.

Hopefully I'll get a chance to fix 2 and 3 tomorrow.

Nicholas Clark

*** pod/perlipc.pod.orig Tue Nov 7 00​:12​:07 2000 --- pod/perlipc.pod Tue Nov 28 10​:58​:41 2000 *************** *** 660\,673 ****   BEGIN { $ENV{PATH} = '/usr/ucb​:/bin' }   use Socket;   use Carp; ! $EOL = "\015\012";  
  sub logmsg { print "$0 $$​: @​_ at "\, scalar localtime\, "\n" }  
  my $port = shift || 2345;   my $proto = getprotobyname('tcp');  
! ($port) = $port =~ /^(\d+)$/ || die "invalid port";  
  socket(Server\, PF_INET\, SOCK_STREAM\, $proto) || die "socket​: $!";   setsockopt(Server\, SOL_SOCKET\, SO_REUSEADDR\, --- 660\,673 ----   BEGIN { $ENV{PATH} = '/usr/ucb​:/bin' }   use Socket;   use Carp; ! my $EOL = "\015\012";  
  sub logmsg { print "$0 $$​: @​_ at "\, scalar localtime\, "\n" }  
  my $port = shift || 2345;   my $proto = getprotobyname('tcp');  
! ($port) = $port =~ /^(\d+)$/ or die "invalid port";  
  socket(Server\, PF_INET\, SOCK_STREAM\, $proto) || die "socket​: $!";   setsockopt(Server\, SOL_SOCKET\, SO_REUSEADDR\, *************** *** 703\,709 ****   BEGIN { $ENV{PATH} = '/usr/ucb​:/bin' }   use Socket;   use Carp; ! $EOL = "\015\012";  
  sub spawn; # forward declaration   sub logmsg { print "$0 $$​: @​_ at "\, scalar localtime\, "\n" } --- 703\,709 ----   BEGIN { $ENV{PATH} = '/usr/ucb​:/bin' }   use Socket;   use Carp; ! my $EOL = "\015\012";  
  sub spawn; # forward declaration   sub logmsg { print "$0 $$​: @​_ at "\, scalar localtime\, "\n" } *************** *** 711\,717 ****   my $port = shift || 2345;   my $proto = getprotobyname('tcp');  
! ($port) = $port =~ /^(\d+)$/ || die "invalid port";  
  socket(Server\, PF_INET\, SOCK_STREAM\, $proto) || die "socket​: $!";   setsockopt(Server\, SOL_SOCKET\, SO_REUSEADDR\, --- 711\,717 ----   my $port = shift || 2345;   my $proto = getprotobyname('tcp');  
! ($port) = $port =~ /^(\d+)$/ or die "invalid port";  
  socket(Server\, PF_INET\, SOCK_STREAM\, $proto) || die "socket​: $!";   setsockopt(Server\, SOL_SOCKET\, SO_REUSEADDR\, *************** *** 865\,870 **** --- 865\,871 ----   use Carp;  
  BEGIN { $ENV{PATH} = '/usr/ucb​:/bin' } + sub spawn; # forward declaration   sub logmsg { print "$0 $$​: @​_ at "\, scalar localtime\, "\n" }  
  my $NAME = '/tmp/catsock'; *************** *** 899\,904 **** --- 900\,928 ----   print "Hello there\, it's now "\, scalar localtime\, "\n";   exec '/usr/games/fortune' or die "can't exec fortune​: $!";   }; + } + + sub spawn { + my $coderef = shift; + + unless (@​_ == 0 && $coderef && ref($coderef) eq 'CODE') { + confess "usage​: spawn CODEREF"; + } + + my $pid; + if (!defined($pid = fork)) { + logmsg "cannot fork​: $!"; + return; + } elsif ($pid) { + logmsg "begat $pid"; + return; # I'm the parent + } + # else I'm the child -- go spawn + + open(STDIN\, "\<&Client") || die "can't dup client to stdin"; + open(STDOUT\, ">&Client") || die "can't dup client to stdout"; + ## open(STDERR\, ">&STDOUT") || die "can't dup stdout to stderr"; + exit &$coderef();   }  
  As you see\, it's remarkably similar to the Internet domain TCP server\, so

Perl Info ``` Flags: category=docs severity=high Site configuration information for perl v5.7.0: Configured by nick at Thu Nov 23 12:45:11 GMT 2000. Summary of my perl5 (revision 5.0 version 7 subversion 0) configuration: Platform: osname=linux, osvers=2.2.16, archname=i586-linux uname='linux fruitbat 2.2.16 #6 tue aug 1 12:35:02 bst 2000 i586 unknown ' config_args='-Dusedevel -Ubincompat5005 -Uinstallusrbinperl -Dcf_email=nick@talking.bollo.cx -Dperladmin=nick@talking.bollo.cx -Dinc_version_list= -Dinc_version_list_init=0 -de' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.95.2 20000220 (Debian GNU/Linux)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lgdbm -ldbm -ldb -ldl -lm -lc -lcrypt -lutil perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil libc=/lib/libc-2.2.so, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: DEVEL7825 @INC for perl v5.7.0: /usr/local/lib/perl5/5.7.0/i586-linux /usr/local/lib/perl5/5.7.0 /usr/local/lib/perl5/site_perl/5.7.0/i586-linux /usr/local/lib/perl5/site_perl/5.7.0 /usr/local/lib/perl5/site_perl . Environment for perl v5.7.0: HOME=/home/nick LANG=C LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

Lightning flashed\, thunder crashed and Nicholas Clark \nick@&#8203;babyhippo\.co\.uk wh ispered​: Bugs remaining
1​: I've no idea what the missing text after "We'll" should be​:
a time. Multithreaded servers are covered in Chapter 6 of
the Camel.
Here's the code. We'll
#!/usr/bin/perl -w

Looks like the "We'll" can just be removed.

While someone is looking at this\, the first paragraph in this section\, which starts "Once the generic server socket has been created..." needs work as well. Specifically\, this sentence which seems to be missing something​:

"The server blocks in the C\ method\, which eventually an bidirectional connection to the remote client."

-spp

p5pRT commented 23 years ago

From @jhi

On Tue\, Nov 28\, 2000 at 11​:16​:57AM +0000\, Nicholas Clark wrote​:

This is a bug report for perl from nick@​talking.bollo.cx\, generated with the help of perlbug 1.33 running under perl v5.7.0.

----------------------------------------------------------------- [Please enter your report here]

What's the \ point of example code if it's buggy? Not only do some of the perlipc code fail to compile in the first place\, but even when you fix those bugs two have subtle precedence bugs w.r.t. "or" versus "||" and scalar/list context.

Bugs remaining

1​: I've no idea what the missing text after "We'll" should be​:

   a time\.  Multithreaded servers are covered in Chapter 6 of
   the Camel\.

   Here's the code\.  We'll

   \#\!/usr/bin/perl \-w

2​: The example that follows uses Net​::hostent. It's not working becuse Net​::hostent in bleadperl is shagged.

3​: Net​::hostent doesn't have a regression test to detected that it's shagged.

Writing a portable test that still tests anything useful for the gethost* is tough. Remember that the contents or the existence of the /etc/hosts file might be largely irrelevant to to results of the gethost* calls.

p5pRT commented 23 years ago

From @nwc10

On Tue\, Nov 28\, 2000 at 09​:43​:40AM -0600\, Jarkko Hietaniemi wrote​:

On Tue\, Nov 28\, 2000 at 11​:16​:57AM +0000\, Nicholas Clark wrote​:

3​: Net​::hostent doesn't have a regression test to detected that it's shagged.

Writing a portable test that still tests anything useful for the gethost* is tough. Remember that the contents or the existence of the /etc/hosts file might be largely irrelevant to to results of the gethost* calls.

$ cat t/lib/net_hostent.t #!./perl -w BEGIN { $| = 1; print "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use Net​::hostent; $loaded = 1; print "ok 1\n";

It's better than nothing? (cribbed from h2xs)

Nicholas Clark

p5pRT commented 23 years ago

From @jhi

On Tue\, Nov 28\, 2000 at 03​:53​:56PM +0000\, Nicholas Clark wrote​:

On Tue\, Nov 28\, 2000 at 09​:43​:40AM -0600\, Jarkko Hietaniemi wrote​:

On Tue\, Nov 28\, 2000 at 11​:16​:57AM +0000\, Nicholas Clark wrote​:

3​: Net​::hostent doesn't have a regression test to detected that it's shagged.

Writing a portable test that still tests anything useful for the gethost* is tough. Remember that the contents or the existence of the /etc/hosts file might be largely irrelevant to to results of the gethost* calls.

$ cat t/lib/net_hostent.t #!./perl -w BEGIN { $| = 1; print "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use Net​::hostent; $loaded = 1; print "ok 1\n";

It's better than nothing? (cribbed from h2xs)

Well\, it's better than nothing\, but is that enough for your purposes?

p5pRT commented 23 years ago

From @nwc10

On Tue\, Nov 28\, 2000 at 10​:01​:42AM -0600\, Jarkko Hietaniemi wrote​:

Well\, it's better than nothing\, but is that enough for your purposes?

I didn't think I had a "purpose" in mind. I just found it rather scary that we can "ship" modules in the standard library that don't even compile >>without anyone realising\<\<

I guess it's time to run the regression tests and then find lib -type f | xargs ls -ltu to find all that weren't accessed and add placeholder tests to at least verify that they still load.

Nicholas Clark

p5pRT commented 23 years ago

From @simoncozens

On Tue\, Nov 28\, 2000 at 11​:16​:57AM +0000\, Nicholas Clark wrote​:

1​: I've no idea what the missing text after "We'll" should be​:

   a time\.  Multithreaded servers are covered in Chapter 6 of
   the Camel\.

Also\, edition specific material detected; is the above sentence still true for PP3?

p5pRT commented 23 years ago

From @rspier

"NC" == Nicholas Clark \nick@&#8203;ccl4\.org writes​:

NC> On Tue\, Nov 28\, 2000 at 09​:43​:40AM -0600\, Jarkko Hietaniemi wrote​:

On Tue\, Nov 28\, 2000 at 11​:16​:57AM +0000\, Nicholas Clark wrote​:

3​: Net​::hostent doesn't have a regression test to detected that it's shagged.

Writing a portable test that still tests anything useful for the gethost* is tough. Remember that the contents or the existence of the /etc/hosts file might be largely irrelevant to to results of the gethost* calls.

NC> $ cat t/lib/net_hostent.t #!./perl -w BEGIN { $| = 1; print NC> "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use NC> Net​::hostent; $loaded = 1; print "ok 1\n";

NC> It's better than nothing? (cribbed from h2xs)

What about this one? I added some really really simple functionality tests\, just to go a little further than simple compilation. Tested on Win32 and Linux.

#!./perl -w BEGIN { $| = 1; print "1..5\n"; } END {print "not ok 1\n" unless $loaded;} use Net​::hostent; $loaded = 1; print "ok 1\n";

# test basic resolution of localhost \<-> 127.0.0.1 use Socket;

my $h = gethost('localhost'); my $i = gethostbyaddr(inet_aton("127.0.0.1"));

print "not " if inet_ntoa($h->addr) ne "127.0.0.1"; print "ok 2\n";

print "not " if inet_ntoa($i->addr) ne "127.0.0.1"; print "ok 3\n";

# need to skip the name comparisons on Win32 because windows will # return the name of the machine instead of "localhost" when resolving # 127.0.0.1 or even "localhost"

if ($^O eq 'MSWin32') {   print "ok $_ # skipped on win32\n" for (4\,5); } else {   print "not " if $h->name ne "localhost";   print "ok 4\n";

  print "not " if $i->name ne "localhost";   print "ok 5\n"; }

p5pRT commented 23 years ago

From @jhi

NC> "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use NC> Net​::hostent; $loaded = 1; print "ok 1\n";

NC> It's better than nothing? (cribbed from h2xs)

What about this one? I added some really really simple functionality tests\, just to go a little further than simple compilation. Tested on Win32 and Linux.

Looks good.

p5pRT commented 23 years ago

From @jhi

On Tue\, Nov 28\, 2000 at 04​:17​:31PM +0000\, Nicholas Clark wrote​:

On Tue\, Nov 28\, 2000 at 10​:01​:42AM -0600\, Jarkko Hietaniemi wrote​:

Well\, it's better than nothing\, but is that enough for your purposes?

I didn't think I had a "purpose" in mind. I just found it rather scary that we can "ship" modules in the standard library that don't even compile >>without anyone realising\<\<

I can't argue with that...

I guess it's time to run the regression tests and then find lib -type f | xargs ls -ltu to find all that weren't accessed and add placeholder tests to at least verify that they still load.

Nicholas Clark

p5pRT commented 23 years ago

From @nwc10

On Sun\, Dec 03\, 2000 at 12​:21​:03PM +0000\, Simon Cozens wrote​:

On Tue\, Nov 28\, 2000 at 11​:16​:57AM +0000\, Nicholas Clark wrote​:

1​: I've no idea what the missing text after "We'll" should be​:

   a time\.  Multithreaded servers are covered in Chapter 6 of
   the Camel\.

Also\, edition specific material detected; is the above sentence still true for PP3?

Chapter 6 is "subroutines" so that's a no. I can't find multithreaded servers in the index\, or that sentence in a quick skim of chapter 16 "Interprocess Communication" so I don't know where that information is. I also don't have a PP2 here\, so I can't use that as a guide to where to start. Hence no correction patch.

Nicholas Clark