… | |
… | |
304 | } |
304 | } |
305 | } |
305 | } |
306 | |
306 | |
307 | static int req_invoke (eio_req *req) |
307 | static int req_invoke (eio_req *req) |
308 | { |
308 | { |
309 | dSP; |
|
|
310 | |
|
|
311 | if (req->flags & FLAG_SV2_RO_OFF) |
309 | if (req->flags & FLAG_SV2_RO_OFF) |
312 | SvREADONLY_off (req->sv2); |
310 | SvREADONLY_off (req->sv2); |
313 | |
311 | |
314 | if (!EIO_CANCELLED (req) && req->callback) |
312 | if (!EIO_CANCELLED (req) && req->callback) |
315 | { |
313 | { |
|
|
314 | dSP; |
|
|
315 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
316 | SV *sv_result; |
|
|
317 | |
316 | ENTER; |
318 | ENTER; |
317 | SAVETMPS; |
319 | SAVETMPS; |
318 | PUSHMARK (SP); |
320 | PUSHMARK (SP); |
319 | EXTEND (SP, 1); |
321 | EXTEND (SP, 1); |
|
|
322 | |
|
|
323 | /* do not recreate the result IV from scratch each time */ |
|
|
324 | if (expect_true (sv_result_cache)) |
|
|
325 | { |
|
|
326 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
327 | SvIV_set (sv_result, req->result); |
|
|
328 | } |
|
|
329 | else |
|
|
330 | { |
|
|
331 | sv_result = newSViv (req->result); |
|
|
332 | SvREADONLY_on (sv_result); |
|
|
333 | } |
320 | |
334 | |
321 | switch (req->type) |
335 | switch (req->type) |
322 | { |
336 | { |
323 | case EIO_READDIR: |
337 | case EIO_READDIR: |
324 | { |
338 | { |
… | |
… | |
469 | case EIO_LSTAT: |
483 | case EIO_LSTAT: |
470 | case EIO_FSTAT: |
484 | case EIO_FSTAT: |
471 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
485 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
472 | PL_laststatval = req->result; |
486 | PL_laststatval = req->result; |
473 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
487 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
474 | PUSHs (sv_2mortal (newSViv (req->result))); |
488 | PUSHs (sv_result); |
475 | break; |
489 | break; |
476 | |
490 | |
477 | case EIO_READ: |
491 | case EIO_READ: |
478 | { |
492 | { |
479 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
493 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
480 | *SvEND (req->sv2) = 0; |
494 | *SvEND (req->sv2) = 0; |
481 | SvPOK_only (req->sv2); |
495 | SvPOK_only (req->sv2); |
482 | SvSETMAGIC (req->sv2); |
496 | SvSETMAGIC (req->sv2); |
483 | PUSHs (sv_2mortal (newSViv (req->result))); |
497 | PUSHs (sv_result); |
484 | } |
498 | } |
485 | break; |
499 | break; |
486 | |
500 | |
487 | case EIO_DUP2: |
501 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
488 | if (req->result > 0) |
502 | if (req->result > 0) |
489 | req->result = 0; |
503 | SvIV_set (sv_result, 0); |
490 | /* FALLTHROUGH */ |
504 | /* FALLTHROUGH */ |
491 | |
505 | |
492 | default: |
506 | default: |
493 | PUSHs (sv_2mortal (newSViv (req->result))); |
507 | PUSHs (sv_result); |
494 | break; |
508 | break; |
495 | } |
509 | } |
496 | |
510 | |
497 | errno = req->errorno; |
511 | errno = req->errorno; |
498 | |
512 | |
499 | PUTBACK; |
513 | PUTBACK; |
500 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
514 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
501 | SPAGAIN; |
515 | SPAGAIN; |
|
|
516 | |
|
|
517 | if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) |
|
|
518 | SvREFCNT_dec (sv_result); |
|
|
519 | else |
|
|
520 | sv_result_cache = sv_result; |
502 | |
521 | |
503 | FREETMPS; |
522 | FREETMPS; |
504 | LEAVE; |
523 | LEAVE; |
505 | |
524 | |
506 | PUTBACK; |
525 | PUTBACK; |
… | |
… | |
601 | errno = old_errno; |
620 | errno = old_errno; |
602 | |
621 | |
603 | mg->mg_obj = 0; /* just in case */ |
622 | mg->mg_obj = 0; /* just in case */ |
604 | |
623 | |
605 | SvREADONLY_off (sv); |
624 | SvREADONLY_off (sv); |
|
|
625 | |
|
|
626 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
627 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
628 | |
606 | SvCUR_set (sv, 0); |
629 | SvCUR_set (sv, 0); |
607 | SvLEN_set (sv, 0); |
|
|
608 | SvPVX (sv) = 0; |
630 | SvPVX (sv) = 0; |
609 | SvOK_off (sv); |
631 | SvOK_off (sv); |
610 | |
632 | |
611 | return 0; |
633 | return 0; |
612 | } |
634 | } |
… | |
… | |
1367 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1389 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1368 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1390 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1369 | if (addr == (void *)-1) |
1391 | if (addr == (void *)-1) |
1370 | XSRETURN_NO; |
1392 | XSRETURN_NO; |
1371 | |
1393 | |
|
|
1394 | sv_force_normal (scalar); |
|
|
1395 | |
1372 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
1396 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
1373 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
1397 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
1374 | ->mg_obj = (SV *)length; |
1398 | ->mg_obj = (SV *)length; |
1375 | |
1399 | |
1376 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
1400 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1401 | |
1377 | if (!(prot & PROT_WRITE)) |
1402 | if (!(prot & PROT_WRITE)) |
1378 | SvREADONLY_on (scalar); |
1403 | SvREADONLY_on (scalar); |
|
|
1404 | |
|
|
1405 | if (SvLEN (scalar)) |
|
|
1406 | Safefree (SvPVX (scalar)); |
1379 | |
1407 | |
1380 | SvPVX (scalar) = (char *)addr; |
1408 | SvPVX (scalar) = (char *)addr; |
1381 | SvCUR_set (scalar, length); |
1409 | SvCUR_set (scalar, length); |
1382 | SvLEN_set (scalar, 0); |
1410 | SvLEN_set (scalar, 0); |
1383 | SvPOK_only (scalar); |
1411 | SvPOK_only (scalar); |