--- IO-AIO/AIO.xs 2010/01/10 23:05:12 1.162 +++ IO-AIO/AIO.xs 2010/05/09 20:42:55 1.165 @@ -22,11 +22,6 @@ # include #endif -#if !_POSIX_MAPPED_FILES -# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) -# define munmap(addr,length) (errno = ENOSYS, -1) -#endif - /* perl namespace pollution */ #undef VERSION @@ -318,11 +313,26 @@ if (!EIO_CANCELLED (req) && req->callback) { + static SV *sv_result_cache; /* caches the result integer SV */ + SV *sv_result; + ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1); + /* do not recreate the result IV from scratch each time */ + if (expect_true (sv_result_cache)) + { + sv_result = sv_result_cache; sv_result_cache = 0; + SvIV_set (sv_result, req->result); + } + else + { + sv_result = newSViv (req->result); + SvREADONLY_on (sv_result); + } + switch (req->type) { case EIO_READDIR: @@ -476,7 +486,7 @@ PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; PL_laststatval = req->result; PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); - PUSHs (sv_2mortal (newSViv (req->result))); + PUSHs (sv_result); break; case EIO_READ: @@ -485,17 +495,17 @@ *SvEND (req->sv2) = 0; SvPOK_only (req->sv2); SvSETMAGIC (req->sv2); - PUSHs (sv_2mortal (newSViv (req->result))); + PUSHs (sv_result); } break; case EIO_DUP2: if (req->result > 0) - req->result = 0; + SvIV_set (sv_result, 0); /* FALLTHROUGH */ default: - PUSHs (sv_2mortal (newSViv (req->result))); + PUSHs (sv_result); break; } @@ -505,6 +515,11 @@ call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); SPAGAIN; + if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) + SvREFCNT_dec (sv_result); + else + sv_result_cache = sv_result; + FREETMPS; LEAVE; @@ -591,6 +606,11 @@ /*****************************************************************************/ +#if !_POSIX_MAPPED_FILES +# define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) +# define munmap(addr,length) (errno = ENOSYS, -1) +#endif + #define MMAP_MAGIC PERL_MAGIC_ext static int @@ -664,8 +684,11 @@ const_iv (ENOSYS) const_iv (O_RDONLY) const_iv (O_WRONLY) + const_iv (O_RDWR) const_iv (O_CREAT) const_iv (O_TRUNC) + const_iv (O_EXCL) + const_iv (O_APPEND) #ifndef _WIN32 const_iv (S_IFIFO) #endif