Event 0.80

[email protected] (Joshua N Pritikin)
Newsgroups perl.loop
Message-ID <[email protected]>
# This is a patch for Event-0.79 to update it to Event-0.80
# Except that this patch does not include Tutorial.pdf.  YMMV
# 
# To apply this patch:
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network:
# http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch':
# STEP 1: Chdir to the source directory.
# If you have a decent Bourne-type shell:
# STEP 2: Run the shell with this file as input.
# If you don't have such a shell, you may need to manually create/delete
# the files as shown below.
# STEP 3: Run the 'patch' program with this file as input.
#
# These are the commands needed to create/delete files/directories:
#
rm -f 'typemap'
touch 'lib/Event/typemap'
chmod 0444 'lib/Event/typemap'
#
# This command terminates the shell and need not be executed manually.
exit
#
#### End of Preamble ####

#### Patch data follows ####
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/ChangeLog' '/usr/tmp/mp4886.d/new/Event-0.80/ChangeLog'
Index: ./ChangeLog
--- ./ChangeLog	Fri Nov 17 17:11:35 2000
+++ ./ChangeLog	Thu Dec  7 15:16:53 2000
@@ -1,3 +1,30 @@
+2000-12-07  Joshua Pritikin  <[email protected]>
+
+	* Release 0.80.
+
+	* Update Tutorial.pdf to Jochen's latest.
+
+2000-12-06  Joshua Pritikin  <[email protected]>
+
+	* Remove silly warning on $io->poll(T).
+
+	* Fix $DIED doc. ([email protected])
+
+2000-12-05  Joshua Pritikin  <[email protected]>
+
+	* Change C callback prototype to (void(*)(pe_event*))
+ 	at request of Jochen.
+
+2000-12-01  Joshua Pritikin  <[email protected]>
+
+	* Warn if loop without active watchers.
+
+	* Slightly more reliable default_exception_handler.
+
+2000-11-28  Joshua Pritikin  <[email protected]>
+
+	* Inline 0.30 integration ([email protected])
+
 2000-11-17  Joshua Pritikin  <[email protected]>
 
 	* Release 0.79.
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/Event.xs' '/usr/tmp/mp4886.d/new/Event-0.80/Event.xs'
Index: ./Event.xs
--- ./Event.xs	Mon Aug 28 09:52:19 2000
+++ ./Event.xs	Tue Dec  5 16:30:26 2000
@@ -331,6 +331,9 @@ BOOT:
       api.unloop = pe_unloop;
       api.unloop_all = pe_unloop_all;
       api.sv_2interval = sv_2interval;
+      api.events_mask_2sv = events_mask_2sv;
+      api.sv_2events_mask = sv_2events_mask;
+
       apisv = perl_get_sv("Event::API", 1);
       sv_setiv(apisv, (IV)&api);
       SvREADONLY_on(apisv);
@@ -500,6 +503,8 @@ _loop()
 	CODE:
 	pe_check_recovery();
 	pe_reentry();
+        if (!ActiveWatchers)
+          warn("Event: loop without active watchers");
 	while (ExitLevel >= LoopLevel && ActiveWatchers) {
 	  ENTER;
 	  SAVETMPS;
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/MANIFEST' '/usr/tmp/mp4886.d/new/Event-0.80/MANIFEST'
Index: ./MANIFEST
--- ./MANIFEST	Mon Nov 13 13:25:15 2000
+++ ./MANIFEST	Tue Nov 28 13:44:41 2000
@@ -34,6 +34,7 @@ demo/repeat.t
 demo/semaphore.pm
 lib/Event.pm
 lib/Event.pod
+lib/Event/typemap
 lib/Event/EventAPI.h
 lib/Event/MakeMaker.pm
 lib/Event/Watcher.pm
@@ -68,6 +69,5 @@ t/timeout_cb.t
 t/timer.t
 t/unconfigured.t
 t/var.t
-typemap
 util/bench.pl
 util/filehandle.txt
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/Makefile.PL' '/usr/tmp/mp4886.d/new/Event-0.80/Makefile.PL'
Index: ./Makefile.PL
--- ./Makefile.PL	Tue Jun 13 11:24:23 2000
+++ ./Makefile.PL	Tue Nov 28 13:44:41 2000
@@ -11,6 +11,7 @@ push @Safe, CC => 'insure', LD => 'insur
 my @opt=(PREREQ_PM => { Test => 1 },
 	 VERSION_FROM	=> "./lib/Event.pm",
 	 NAME      	=> "Event",
+	 TYPEMAPS       => ['./lib/Event/typemap'],
 	 INC		=> '-Ic -Ilib/Event',
 	 H		=> [glob("c/*"), glob("*.h"), "lib/Event/EventAPI.h"],
 	 @Safe,
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/c/ev.c' '/usr/tmp/mp4886.d/new/Event-0.80/c/ev.c'
Index: ./c/ev.c
--- ./c/ev.c	Tue Jun 13 11:24:23 2000
+++ ./c/ev.c	Tue Dec  5 09:13:06 2000
@@ -287,7 +287,7 @@ static void pe_event_invoke(pe_event *ev
 	}
     } else {
 	assert(ev->callback);
-	(* (void(*)(void*,pe_event*)) ev->callback)(ev->ext_data, ev);
+	(* (void(*)(pe_event*)) ev->callback)(ev);
     }
 
     LEAVE;
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/c/io.c' '/usr/tmp/mp4886.d/new/Event-0.80/c/io.c'
Index: ./c/io.c
--- ./c/io.c	Tue Aug 29 12:50:12 2000
+++ ./c/io.c	Wed Dec  6 17:04:31 2000
@@ -126,7 +126,7 @@ static void pe_io_reset_handle(pe_watche
 WKEYMETH(_io_poll) {
     pe_io *io = (pe_io*)ev;
     if (nval) {
-	int nev = sv_2events_mask(nval, PE_R|PE_W|PE_E);
+	int nev = sv_2events_mask(nval, PE_R|PE_W|PE_E|PE_T);
 	if (io->timeout) nev |=  PE_T;
 	else             nev &= ~PE_T;
 	if (io->poll != nev) {
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/c/typemap.c' '/usr/tmp/mp4886.d/new/Event-0.80/c/typemap.c'
Index: ./c/typemap.c
--- ./c/typemap.c	Tue Jun 13 11:24:24 2000
+++ ./c/typemap.c	Tue Dec  5 16:26:33 2000
@@ -34,7 +34,7 @@ static SV *wrap_watcher(void *ptr, HV *s
     return ref;
 }
 
-static SV *watcher_2sv(pe_watcher *wa) { /**SLOW IS OKAY**/
+SV *watcher_2sv(pe_watcher *wa) { /**SLOW IS OKAY**/
     assert(!WaDESTROYED(wa));
     if (!wa->mysv) {
 	wa->mysv = wrap_watcher(wa, wa->vtbl->stash, 0);
@@ -47,7 +47,7 @@ static SV *watcher_2sv(pe_watcher *wa) {
     return SvREFCNT_inc(sv_2mortal(wa->mysv));
 }
 
-static void* sv_2watcher(SV *sv) {
+void* sv_2watcher(SV *sv) {
     MAGIC *mg;
     SV *origsv = sv;
     if (!sv || !SvROK(sv))
@@ -74,7 +74,7 @@ static void* sv_2watcher(SV *sv) {
   is deallocated (or, more likely, recycled).
 */
 
-static SV *event_2sv(pe_event *ev) { /**MAKE FAST**/
+SV *event_2sv(pe_event *ev) { /**MAKE FAST**/
     if (!ev->mysv) {
 	SV *rv = newSV(0);
 	SV *sv = newSVrv(rv,0);
@@ -91,7 +91,7 @@ static SV *event_2sv(pe_event *ev) { /**
     return SvREFCNT_inc(sv_2mortal(ev->mysv));
 }
 
-static void *sv_2event(SV *sv) {
+void *sv_2event(SV *sv) {
     void *ptr;
     assert(sv);
     assert(SvROK(sv));
@@ -106,7 +106,7 @@ static void *sv_2event(SV *sv) {
 #define VERIFYINTERVAL(name, f) \
  STMT_START { double ign; sv_2interval(name, f, &ign); } STMT_END
 
-static int sv_2interval(char *label, SV *in, double *out) {
+int sv_2interval(char *label, SV *in, double *out) {
     SV *sv = in;
     if (!sv) return 0;
     if (SvGMAGICAL(sv))
@@ -137,7 +137,7 @@ static int sv_2interval(char *label, SV 
     return 1;
 }
 
-static SV* events_mask_2sv(int mask) {
+SV* events_mask_2sv(int mask) {
     STRLEN len;
     SV *ret = newSV(0);
     SvUPGRADE(ret, SVt_PVIV);
@@ -151,7 +151,7 @@ static SV* events_mask_2sv(int mask) {
     return ret;
 }
 
-static int sv_2events_mask(SV *sv, int bits) {
+int sv_2events_mask(SV *sv, int bits) {
     if (SvPOK(sv)) {
 	UV got=0;
 	int xx;
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/lib/Event.pm' '/usr/tmp/mp4886.d/new/Event-0.80/lib/Event.pm'
Index: ./lib/Event.pm
--- ./lib/Event.pm	Fri Nov 17 17:11:16 2000
+++ ./lib/Event.pm	Tue Dec  5 09:19:58 2000
@@ -13,7 +13,7 @@ use Carp;
 eval { require Carp::Heavy; };  # work around perl_call_pv bug XXX
 use vars qw($VERSION @EXPORT_OK
 	    $API $DebugLevel $Eval $DIED $Now);
-$VERSION = '0.79';
+$VERSION = '0.80';
 
 # If we inherit DynaLoader then we inherit AutoLoader; Bletch!
 require DynaLoader;
@@ -64,8 +64,12 @@ sub AUTOLOAD {
 
 sub default_exception_handler {
     my ($run,$err) = @_;
-    my $desc = $run? $run->w->desc : '?';
-    my $m = "Event: trapped error in '$desc': $err";
+    my $desc = '?';
+    my $w;
+    if ($run and ($w = $run->w)) {
+	$desc = "`".$w->desc."'";
+    }
+    my $m = "Event: trapped error in $desc: $err";
     $m .= "\n" if $m !~ m/\n$/;
     warn $m;
     #Carp::cluck "Event: fatal error trapped in '$desc'";
@@ -178,5 +182,29 @@ use vars qw(@ISA);
 package Event;
 require Event::Watcher;
 _load_watcher($_) for qw(idle io signal timer var);
+
+# Provide hints to Inline.pm for usage:
+# use Inline with => 'Event';
+
+sub Inline {
+    my $language = shift;
+    if ($language ne 'C') {
+	warn "Warning: Event.pm does not provide Inline hints for the $language language\n";
+	return
+    }
+
+    require Event::MakeMaker;
+    my $path = $Event::MakeMaker::installsitearch;
+    require Config;
+    my $so = $Config::Config{so};
+
+    return {
+	INC => "-I $path/Event",
+	TYPEMAPS => "$path/Event/typemap",
+	MYEXTLIB => "$path/auto/Event/Event.$so",
+	AUTO_INCLUDE => '#include "EventAPI.h"',
+	BOOT => 'I_EVENT_API("Inline");',
+    };
+}
 
 1;
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/lib/Event.pod' '/usr/tmp/mp4886.d/new/Event-0.80/lib/Event.pod'
Index: ./lib/Event.pod
--- ./lib/Event.pod	Wed Sep  6 11:24:32 2000
+++ ./lib/Event.pod	Thu Dec  7 15:27:45 2000
@@ -131,7 +131,7 @@ customized by passing extra attributes t
 created, watcher objects are "started" and are waiting for events
 (see C<$event-E<gt>start> below).
 
-L<NetServer::Portal> can display watchers in real-time, formatted
+NetServer::Portal can display watchers in real-time, formatted
 similarly to the popular C<top> program.  You may find this a useful
 aide for debugging.
 
@@ -253,7 +253,7 @@ watchers should poll for writes unless y
 Extra attributes: at => $time, interval => $sec, hard => $bool
 
 The C<$time> and C<$sec> are in seconds.  Fractional seconds may be
-used if L<Time::HiRes> is available.  The constructor also accepts an
+used if Time::HiRes is available.  The constructor also accepts an
 C<after> attribute for easier initialization.  It might be useful to
 know the time at the start of today.  You can find it with:
 
@@ -420,7 +420,7 @@ Similar to a C<timeout>.
 
 The maximum number of seconds to spend in a callback.  If a callback
 uses more time then it is aborted.  Defaults to 1 sec.  This feature
-is normally disabled.  See L<Event::Stats>.
+is normally disabled.  See Event::Stats.
 
 =item min => $seconds
 
@@ -569,7 +569,10 @@ Or you can write your own.  The handler 
 If you do not want to continue looping after an error, you can do
 something like this:
 
-  $Event::DIED = sub { die &Event::verbose_exception_handler(@_) };
+  $Event::DIED = sub {
+    Event::verbose_exception_handler(@_);
+    Event::unloop_all();
+  };
 
 =item * Event->add_hooks(key => sub { ... }, ...);
 
@@ -593,7 +596,7 @@ Currently support hooks are detailed as 
 =head1 C API
 
 Event also has a direct API for callbacks written exclusively in C.
-See L<Event::MakeMaker>.
+See Event::MakeMaker.
 
 =head1 WHAT ABOUT THREADS?
 
@@ -680,7 +683,7 @@ There seems to be some sort of bug in th
   Explicit blessing to '' (assuming package main) during global
   destruction.
 
-=head2 WHY MICROSOFT WINDOWS MIGHT BE FASTER THAN UNIX
+=head2 WHY SELECT/POLL SUCKS
 
 This section is concerned with advanced kernel architecture.
 
@@ -716,10 +719,25 @@ Event Loop.  Just start coding!
 
 =head1 ALSO SEE
 
-L<Time::HiRes>, L<NetServer::Portal>, L<IPC::LDT>, L<Event-tcp>,
-and L<Time::Warp>.
+=over 4
+
+=item * Useful and Fun
+
+Time::HiRes, NetServer::Portal, Time::Warp
+
+=item * Message Passing
+
+COPE, IPC::LDT, Event-tcp
 
-While Tk does not yet support Event, L<PerlQt> does.
+=item * GUI
+
+While Tk does not yet support Event, PerlQt does.
+
+=item * C API
+
+Inline
+
+=back
 
 =head1 SUPPORT
 
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/lib/Event/EventAPI.h' '/usr/tmp/mp4886.d/new/Event-0.80/lib/Event/EventAPI.h'
Index: ./lib/Event/EventAPI.h
--- ./lib/Event/EventAPI.h	Tue Aug 29 12:49:36 2000
+++ ./lib/Event/EventAPI.h	Tue Dec  5 16:30:01 2000
@@ -176,7 +176,7 @@ struct pe_event_stats_vtbl {
 };
 
 struct EventAPI {
-#define EventAPI_VERSION 21
+#define EventAPI_VERSION 22
     I32 Ver;
 
     /* EVENTS */
@@ -197,6 +197,7 @@ struct EventAPI {
     pe_signal   *(*new_signal)(HV*, SV*);
 
     /* TIMEABLE */
+    double (*NVtime)();
     void (*tstart)(pe_timeable *);
     void (*tstop)(pe_timeable *);
 
@@ -214,12 +215,13 @@ struct EventAPI {
     void *(*sv_2watcher)(SV *sv);
     SV   *(*event_2sv)(pe_event *ev);
     void *(*sv_2event)(SV *sv);
+    int (*sv_2interval)(char *label, SV *in, double *out);
+    SV (*events_mask_2sv)(int mask);
+    int (*sv_2events_mask)(SV *sv, int bits);
 
     /* EVERYTHING ELSE */
     void (*unloop)(SV *);
-    double (*NVtime)();
     void (*unloop_all)(SV *);
-    int (*sv_2interval)(char *label, SV *in, double *out);
 };
 
 static struct EventAPI *GEventAPI=0;
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/lib/Event/MakeMaker.pm' '/usr/tmp/mp4886.d/new/Event-0.80/lib/Event/MakeMaker.pm'
Index: ./lib/Event/MakeMaker.pm
--- ./lib/Event/MakeMaker.pm	Tue Jun 13 11:24:24 2000
+++ ./lib/Event/MakeMaker.pm	Tue Nov 28 13:44:41 2000
@@ -2,23 +2,29 @@ use strict;
 package Event::MakeMaker;
 use Config;
 use base 'Exporter';
-use vars qw(@EXPORT_OK);
-@EXPORT_OK = qw(&event_args);
+use vars qw(@EXPORT_OK $installsitearch);
+@EXPORT_OK = qw(&event_args $installsitearch);
 
-my $installsitearch = $Config{sitearch};
-$installsitearch =~ s,$Config{prefix},$ENV{PERL5PREFIX}, if
-    exists $ENV{PERL5PREFIX};
+my %opt;
+for my $opt (split /:+/, $ENV{PERL_MM_OPT}) {
+    my ($k,$v) = split /=/, $opt;
+    $opt{$k} = $v;
+}
+
+my $extra = $Config{sitearch};
+$extra =~ s,$Config{prefix},$opt{PREFIX}, if
+    exists $opt{PREFIX};
+
+for my $d ($extra, @INC) {
+    if (-e "$d/Event/EventAPI.h") {
+	$installsitearch = $d;
+	last
+    }
+}
 
 sub event_args {
     my %arg = @_;
-    my $dir;
-    for my $d ($installsitearch, @INC) {
-	if (-e "$d/Event/EventAPI.h") {
-	    $dir = $d;
-	    last
-	}
-    }
-    $arg{INC} .= " -I$dir/Event";
+    $arg{INC} .= " -I$installsitearch/Event";
     %arg;
 }
 
gdiff -up /dev/null '/usr/tmp/mp4886.d/new/Event-0.80/lib/Event/typemap'
Index: ./lib/Event/typemap
--- ./lib/Event/typemap	Wed Dec 31 19:00:00 1969
+++ ./lib/Event/typemap	Tue Nov 28 13:44:41 2000
@@ -0,0 +1,20 @@
+TYPEMAP
+
+pe_watcher *	O_WATCHER
+pe_event *	O_EVENT
+
+INPUT
+
+O_WATCHER
+	$var = ($type) sv_2watcher($arg)
+
+O_EVENT
+	$var = ($type) sv_2event($arg)
+
+OUTPUT
+
+O_WATCHER
+	croak("use watcher_2sv($var)")
+
+O_EVENT
+	croak("use event_2sv($var)")
gdiff -up '/usr/tmp/mp4886.d/old/Event-0.79/t/callback.t' '/usr/tmp/mp4886.d/new/Event-0.80/t/callback.t'
Index: ./t/callback.t
--- ./t/callback.t	Tue Jun 13 11:24:25 2000
+++ ./t/callback.t	Tue Dec  5 09:19:09 2000
@@ -1,7 +1,7 @@
 #!./perl -w
 
 use strict;
-use Test; plan tests => 5;
+use Test; plan tests => 6;
 use Event 0.65;
 
 my $invoked_method=0;
@@ -29,7 +29,12 @@ ok $@, '/Callback/';
 	ok $run->w->desc, 'nomethod';
 	ok $err, '/object method/';
     };
+    my $warn='';
+    local $SIG{__WARN__} = sub {
+	$warn .= $_[0];
+    };
     Event::loop();
+    ok $warn, '/loop without active watchers/';
 }
 
 ok $invoked_method, 3;
#### End of Patch data ####

#### ApplyPatch data follows ####
# Data version        : 1.0
# Date generated      : Thu Dec  7 15:35:30 2000
# Generated by        : makepatch 2.00 (2.0BETA)
# Recurse directories : Yes
# r 'typemap' 234 0
# p 'ChangeLog' 26539 976220213 0100444
# p 'Event.xs' 19023 976051826 0100444
# p 'MANIFEST' 883 975437081 0100444
# p 'Makefile.PL' 571 975437081 0100444
# p 'c/ev.c' 7509 976025586 0100444
# p 'c/io.c' 5344 976140271 0100444
# p 'c/typemap.c' 4417 976051593 0100444
# p 'lib/Event.pm' 4074 976025998 0100444
# p 'lib/Event.pod' 25103 976220865 0100444
# p 'lib/Event/EventAPI.h' 6043 976051801 0100444
# p 'lib/Event/MakeMaker.pm' 3275 975437081 0100444
# c 'lib/Event/typemap' 0 975437081 0100444
# p 't/callback.t' 684 976025949 0100444
#### End of ApplyPatch data ####

#### End of Patch kit [created: Thu Dec  7 15:35:30 2000] ####
#### Checksum: 3571 353285 43032 ####
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.