--- cvsroot/EV/EV.xs 2007/11/01 08:10:03 1.30 +++ cvsroot/EV/EV.xs 2007/11/01 11:11:39 1.32 @@ -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; @@ -204,6 +206,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 +321,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 +443,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); }