… | |
… | |
18 | #include <fcntl.h> |
18 | #include <fcntl.h> |
19 | #include <sched.h> |
19 | #include <sched.h> |
20 | |
20 | |
21 | #if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES |
21 | #if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES |
22 | # include <sys/mman.h> |
22 | # include <sys/mman.h> |
23 | #endif |
|
|
24 | |
|
|
25 | #if !_POSIX_MAPPED_FILES |
|
|
26 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
|
|
27 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
28 | #endif |
23 | #endif |
29 | |
24 | |
30 | /* perl namespace pollution */ |
25 | /* perl namespace pollution */ |
31 | #undef VERSION |
26 | #undef VERSION |
32 | |
27 | |
… | |
… | |
316 | if (req->flags & FLAG_SV2_RO_OFF) |
311 | if (req->flags & FLAG_SV2_RO_OFF) |
317 | SvREADONLY_off (req->sv2); |
312 | SvREADONLY_off (req->sv2); |
318 | |
313 | |
319 | if (!EIO_CANCELLED (req) && req->callback) |
314 | if (!EIO_CANCELLED (req) && req->callback) |
320 | { |
315 | { |
|
|
316 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
317 | SV *sv_result; |
|
|
318 | |
321 | ENTER; |
319 | ENTER; |
322 | SAVETMPS; |
320 | SAVETMPS; |
323 | PUSHMARK (SP); |
321 | PUSHMARK (SP); |
324 | EXTEND (SP, 1); |
322 | EXTEND (SP, 1); |
|
|
323 | |
|
|
324 | /* do not recreate the result IV from scratch each time */ |
|
|
325 | if (expect_true (sv_result_cache)) |
|
|
326 | { |
|
|
327 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
328 | SvIV_set (sv_result, req->result); |
|
|
329 | } |
|
|
330 | else |
|
|
331 | { |
|
|
332 | sv_result = newSViv (req->result); |
|
|
333 | SvREADONLY_on (sv_result); |
|
|
334 | } |
325 | |
335 | |
326 | switch (req->type) |
336 | switch (req->type) |
327 | { |
337 | { |
328 | case EIO_READDIR: |
338 | case EIO_READDIR: |
329 | { |
339 | { |
… | |
… | |
474 | case EIO_LSTAT: |
484 | case EIO_LSTAT: |
475 | case EIO_FSTAT: |
485 | case EIO_FSTAT: |
476 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
486 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
477 | PL_laststatval = req->result; |
487 | PL_laststatval = req->result; |
478 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
488 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
479 | PUSHs (sv_2mortal (newSViv (req->result))); |
489 | PUSHs (sv_result); |
480 | break; |
490 | break; |
481 | |
491 | |
482 | case EIO_READ: |
492 | case EIO_READ: |
483 | { |
493 | { |
484 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
494 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
485 | *SvEND (req->sv2) = 0; |
495 | *SvEND (req->sv2) = 0; |
486 | SvPOK_only (req->sv2); |
496 | SvPOK_only (req->sv2); |
487 | SvSETMAGIC (req->sv2); |
497 | SvSETMAGIC (req->sv2); |
488 | PUSHs (sv_2mortal (newSViv (req->result))); |
498 | PUSHs (sv_result); |
489 | } |
499 | } |
490 | break; |
500 | break; |
491 | |
501 | |
492 | case EIO_DUP2: |
502 | case EIO_DUP2: |
493 | if (req->result > 0) |
503 | if (req->result > 0) |
494 | req->result = 0; |
504 | SvIV_set (sv_result, 0); |
495 | /* FALLTHROUGH */ |
505 | /* FALLTHROUGH */ |
496 | |
506 | |
497 | default: |
507 | default: |
498 | PUSHs (sv_2mortal (newSViv (req->result))); |
508 | PUSHs (sv_result); |
499 | break; |
509 | break; |
500 | } |
510 | } |
501 | |
511 | |
502 | errno = req->errorno; |
512 | errno = req->errorno; |
503 | |
513 | |
504 | PUTBACK; |
514 | PUTBACK; |
505 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
515 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
506 | SPAGAIN; |
516 | SPAGAIN; |
|
|
517 | |
|
|
518 | if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) |
|
|
519 | SvREFCNT_dec (sv_result); |
|
|
520 | else |
|
|
521 | sv_result_cache = sv_result; |
507 | |
522 | |
508 | FREETMPS; |
523 | FREETMPS; |
509 | LEAVE; |
524 | LEAVE; |
510 | |
525 | |
511 | PUTBACK; |
526 | PUTBACK; |
… | |
… | |
588 | { |
603 | { |
589 | create_respipe (); |
604 | create_respipe (); |
590 | } |
605 | } |
591 | |
606 | |
592 | /*****************************************************************************/ |
607 | /*****************************************************************************/ |
|
|
608 | |
|
|
609 | #if !_POSIX_MAPPED_FILES |
|
|
610 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
|
|
611 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
612 | #endif |
593 | |
613 | |
594 | #define MMAP_MAGIC PERL_MAGIC_ext |
614 | #define MMAP_MAGIC PERL_MAGIC_ext |
595 | |
615 | |
596 | static int |
616 | static int |
597 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
617 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
… | |
… | |
662 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
682 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
663 | const_iv (EXDEV) |
683 | const_iv (EXDEV) |
664 | const_iv (ENOSYS) |
684 | const_iv (ENOSYS) |
665 | const_iv (O_RDONLY) |
685 | const_iv (O_RDONLY) |
666 | const_iv (O_WRONLY) |
686 | const_iv (O_WRONLY) |
|
|
687 | const_iv (O_RDWR) |
667 | const_iv (O_CREAT) |
688 | const_iv (O_CREAT) |
668 | const_iv (O_TRUNC) |
689 | const_iv (O_TRUNC) |
|
|
690 | const_iv (O_EXCL) |
|
|
691 | const_iv (O_APPEND) |
669 | #ifndef _WIN32 |
692 | #ifndef _WIN32 |
670 | const_iv (S_IFIFO) |
693 | const_iv (S_IFIFO) |
671 | #endif |
694 | #endif |
672 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
695 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
673 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
696 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |