--- EV/EV.xs 2007/11/01 08:10:03 1.30 +++ EV/EV.xs 2007/11/01 11:11:21 1.31 @@ -32,13 +32,15 @@ { int signum; - if (SvIV (sig) > 0) - return SvIV (sig); + SvGETMAGIC (sig); for (signum = 1; signum < SIG_SIZE; ++signum) if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) return signum; + if (SvIV (sig) > 0) + return SvIV (sig); + return -1; } @@ -58,7 +60,7 @@ if (SvTYPE (fh) == SVt_PVGV) return PerlIO_fileno (IoIFP (sv_2io (fh))); - if (SvIOK (fh)) + if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff)) return SvIV (fh); return -1; @@ -108,6 +110,8 @@ SV *sv_self, *sv_events, *sv_status = 0; static SV *sv_events_cache; + fprintf (stderr, "e_cb %p,%x\n", w, revents);//D + sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ if (sv_events_cache) @@ -204,6 +208,9 @@ #define CHECK_REPEAT(repeat) if (repeat < 0.) \ croak (# repeat " value must be >= 0"); +#define CHECK_FD(fh,fd) if ((fd) < 0) \ + croak ("illegal file descriptor or filehandle (either no attached file descriptor or illegal value): %s", SvPV_nolen (fh)); + ///////////////////////////////////////////////////////////////////////////// // XS interface functions @@ -316,10 +323,15 @@ ALIAS: io_ns = 1 CODE: +{ + int fd = sv_fileno (fh); + CHECK_FD (fh, fd); + RETVAL = e_new (sizeof (struct ev_io), cb); RETVAL->fh = newSVsv (fh); - ev_io_set (RETVAL, sv_fileno (RETVAL->fh), events); + ev_io_set (RETVAL, fd, events); if (!ix) ev_io_start (RETVAL); +} OUTPUT: RETVAL @@ -433,10 +445,13 @@ CODE: { int active = w->active; + int fd = sv_fileno (fh); + CHECK_FD (fh, fd); + if (active) ev_io_stop (w); sv_setsv (w->fh, fh); - ev_io_set (w, sv_fileno (w->fh), events); + ev_io_set (w, fd, events); if (active) ev_io_start (w); }