1 | #ifndef SCHMORP_PERL_H_ |
1 | #ifndef SCHMORP_PERL_H_ |
2 | #define SCHMORP_PERL_H_ |
2 | #define SCHMORP_PERL_H_ |
3 | |
3 | |
4 | /* WARNING |
4 | /* WARNING |
5 | * This header file is a shared resource between many modules. |
5 | * This header file is a shared resource between many modules. |
|
|
6 | * perl header files MUST already be included. |
6 | */ |
7 | */ |
7 | |
8 | |
8 | #include <signal.h> |
9 | #include <signal.h> |
9 | #include <errno.h> |
10 | #include <errno.h> |
10 | |
11 | |
11 | #ifndef _WIN32 |
12 | #if defined(WIN32 ) || defined(_MINIX) |
|
|
13 | # define SCHMORP_H_PREFER_SELECT 1 |
|
|
14 | #endif |
|
|
15 | |
|
|
16 | #if !SCHMORP_H_PREFER_SELECT |
12 | # include <poll.h> |
17 | # include <poll.h> |
13 | #endif |
18 | #endif |
14 | |
19 | |
15 | /* useful stuff, used by schmorp mostly */ |
20 | /* useful stuff, used by schmorp mostly */ |
16 | |
21 | |
… | |
… | |
44 | # endif |
49 | # endif |
45 | # ifndef IS_PADCONST |
50 | # ifndef IS_PADCONST |
46 | # define IS_PADCONST(v) 0 |
51 | # define IS_PADCONST(v) 0 |
47 | # endif |
52 | # endif |
48 | #endif |
53 | #endif |
|
|
54 | |
|
|
55 | /* use NV for 32 bit perls as it allows larger offsets */ |
|
|
56 | #if IVSIZE >= 8 |
|
|
57 | typedef IV VAL64; |
|
|
58 | # define SvVAL64(sv) SvIV (sv) |
|
|
59 | # define newSVval64(i64) newSViv (i64) |
|
|
60 | #else |
|
|
61 | typedef NV VAL64; |
|
|
62 | # define SvVAL64(sv) SvNV (sv) |
|
|
63 | # define newSVval64(i64) newSVnv (i64) |
|
|
64 | #endif |
|
|
65 | |
|
|
66 | /* typemap for the above */ |
|
|
67 | /* |
|
|
68 | VAL64 T_VAL64 |
|
|
69 | |
|
|
70 | INPUT |
|
|
71 | |
|
|
72 | T_VAL64 |
|
|
73 | $var = ($type)SvVAL64 ($arg); |
|
|
74 | |
|
|
75 | OUTPUT |
|
|
76 | |
|
|
77 | T_VAL64 |
|
|
78 | $arg = newSVval64 ($var); |
|
|
79 | */ |
49 | |
80 | |
50 | /* 5.11 */ |
81 | /* 5.11 */ |
51 | #ifndef CxHASARGS |
82 | #ifndef CxHASARGS |
52 | # define CxHASARGS(cx) (cx)->blk_sub.hasargs |
83 | # define CxHASARGS(cx) (cx)->blk_sub.hasargs |
53 | #endif |
84 | #endif |
… | |
… | |
327 | } |
358 | } |
328 | |
359 | |
329 | #endif |
360 | #endif |
330 | |
361 | |
331 | #if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
362 | #if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
|
|
363 | # define SCHMORP_H_HAVE_EVENTFD 1 |
332 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
364 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
333 | # include <stdint.h> |
365 | # include <stdint.h> |
334 | # ifdef __cplusplus |
366 | # ifdef __cplusplus |
335 | extern "C" { |
367 | extern "C" { |
336 | # endif |
368 | # endif |
… | |
… | |
404 | * incompetent windows programmers - is this redundant? |
436 | * incompetent windows programmers - is this redundant? |
405 | */ |
437 | */ |
406 | DWORD dummy; |
438 | DWORD dummy; |
407 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
439 | WriteFile (S_TO_HANDLE (epp->fd [1]), (LPCVOID)&dummy, 1, &dummy, 0); |
408 | #else |
440 | #else |
|
|
441 | # if SCHMORP_H_HAVE_EVENTFD |
409 | static uint64_t counter = 1; |
442 | static uint64_t counter = 1; |
|
|
443 | # else |
|
|
444 | static char counter [8]; |
|
|
445 | # endif |
410 | /* some modules accept fd's from outside, support eventfd here */ |
446 | /* some modules accept fd's from outside, support eventfd here */ |
411 | if (write (epp->fd [1], &counter, epp->len) < 0 |
447 | if (write (epp->fd [1], &counter, epp->len) < 0 |
412 | && errno == EINVAL |
448 | && errno == EINVAL |
413 | && epp->len != 8) |
449 | && epp->len != 8) |
414 | write (epp->fd [1], &counter, (epp->len = 8)); |
450 | write (epp->fd [1], &counter, (epp->len = 8)); |
… | |
… | |
444 | if (epp->len) |
480 | if (epp->len) |
445 | { |
481 | { |
446 | if (dup2 (epn.fd [0], epp->fd [0]) < 0) |
482 | if (dup2 (epn.fd [0], epp->fd [0]) < 0) |
447 | croak ("unable to dup over old event pipe"); /* should not croak */ |
483 | croak ("unable to dup over old event pipe"); /* should not croak */ |
448 | |
484 | |
449 | if (epp->fd [1] != epp->fd [0]) |
|
|
450 | close (epn.fd [0]); |
485 | close (epn.fd [0]); |
|
|
486 | |
|
|
487 | if (epn.fd [0] == epn.fd [1]) |
|
|
488 | epn.fd [1] = epp->fd [0]; |
451 | |
489 | |
452 | epn.fd [0] = epp->fd [0]; |
490 | epn.fd [0] = epp->fd [0]; |
453 | } |
491 | } |
454 | |
492 | |
455 | *epp = epn; |
493 | *epp = epn; |
… | |
… | |
461 | |
499 | |
462 | static int |
500 | static int |
463 | s_epipe_wait (s_epipe *epp) |
501 | s_epipe_wait (s_epipe *epp) |
464 | { |
502 | { |
465 | dTHX; |
503 | dTHX; |
466 | #ifdef _WIN32 |
504 | #if SCHMORP_H_PREFER_SELECT |
467 | fd_set rfd; |
505 | fd_set rfd; |
468 | int fd = s_epipe_fd (epp); |
506 | int fd = s_epipe_fd (epp); |
469 | |
507 | |
470 | FD_ZERO (&rfd); |
508 | FD_ZERO (&rfd); |
471 | FD_SET (fd, &rfd); |
509 | FD_SET (fd, &rfd); |