develooper Front page | perl.perl5.porters | Postings from November 2000

[ID 20001128.002] what's the point of example code if it is buggy?

Thread Next
From:
Nicholas Clark
Date:
November 28, 2000 03:21
Subject:
[ID 20001128.002] what's the point of example code if it is buggy?
Message ID:
E140ikr-00076N-00@fruitbat.babyhippo.co.uk

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 <expletive> 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


[Please do not change anything below this line]
-----------------------------------------------------------------
---
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


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About