diff options
Diffstat (limited to 'test/data')
| -rw-r--r-- | test/data/emacs-module/mod-test.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/test/data/emacs-module/mod-test.c b/test/data/emacs-module/mod-test.c index 61733f1ef49..5e3112f4471 100644 --- a/test/data/emacs-module/mod-test.c +++ b/test/data/emacs-module/mod-test.c | |||
| @@ -30,8 +30,18 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 30 | #include <string.h> | 30 | #include <string.h> |
| 31 | #include <time.h> | 31 | #include <time.h> |
| 32 | 32 | ||
| 33 | #include <pthread.h> | 33 | #ifdef WINDOWSNT |
| 34 | #include <unistd.h> | 34 | /* Cannot include <process.h> because of the local header by the same |
| 35 | name, sigh. */ | ||
| 36 | uintptr_t _beginthread (void (__cdecl *)(void *), unsigned, void *); | ||
| 37 | # if !defined __x86_64__ | ||
| 38 | # define ALIGN_STACK __attribute__((force_align_arg_pointer)) | ||
| 39 | # endif | ||
| 40 | # include <windows.h> /* for Sleep */ | ||
| 41 | #else /* !WINDOWSNT */ | ||
| 42 | # include <pthread.h> | ||
| 43 | # include <unistd.h> | ||
| 44 | #endif | ||
| 35 | 45 | ||
| 36 | #ifdef HAVE_GMP | 46 | #ifdef HAVE_GMP |
| 37 | #include <gmp.h> | 47 | #include <gmp.h> |
| @@ -302,7 +312,7 @@ Fmod_test_invalid_load (emacs_env *env, ptrdiff_t nargs, emacs_value *args, | |||
| 302 | } | 312 | } |
| 303 | 313 | ||
| 304 | /* An invalid finalizer: Finalizers are run during garbage collection, | 314 | /* An invalid finalizer: Finalizers are run during garbage collection, |
| 305 | where Lisp code can’t be executed. -module-assertions tests for | 315 | where Lisp code can't be executed. -module-assertions tests for |
| 306 | this case. */ | 316 | this case. */ |
| 307 | 317 | ||
| 308 | static emacs_env *current_env; | 318 | static emacs_env *current_env; |
| @@ -542,20 +552,39 @@ Fmod_test_function_finalizer_calls (emacs_env *env, ptrdiff_t nargs, | |||
| 542 | return env->funcall (env, Flist, 2, list_args); | 552 | return env->funcall (env, Flist, 2, list_args); |
| 543 | } | 553 | } |
| 544 | 554 | ||
| 555 | static void | ||
| 556 | sleep_for_half_second (void) | ||
| 557 | { | ||
| 558 | /* mingw.org's MinGW has nanosleep, but MinGW64 doesn't. */ | ||
| 559 | #ifdef WINDOWSNT | ||
| 560 | Sleep (500); | ||
| 561 | #else | ||
| 562 | const struct timespec sleep = {0, 500000000}; | ||
| 563 | if (nanosleep (&sleep, NULL) != 0) | ||
| 564 | perror ("nanosleep"); | ||
| 565 | #endif | ||
| 566 | } | ||
| 567 | |||
| 568 | #ifdef WINDOWSNT | ||
| 569 | static void ALIGN_STACK | ||
| 570 | #else | ||
| 545 | static void * | 571 | static void * |
| 572 | #endif | ||
| 546 | write_to_pipe (void *arg) | 573 | write_to_pipe (void *arg) |
| 547 | { | 574 | { |
| 548 | /* We sleep a bit to test that writing to a pipe is indeed possible | 575 | /* We sleep a bit to test that writing to a pipe is indeed possible |
| 549 | if no environment is active. */ | 576 | if no environment is active. */ |
| 550 | const struct timespec sleep = {0, 500000000}; | 577 | sleep_for_half_second (); |
| 551 | if (nanosleep (&sleep, NULL) != 0) | ||
| 552 | perror ("nanosleep"); | ||
| 553 | FILE *stream = arg; | 578 | FILE *stream = arg; |
| 579 | /* The string below should be identical to the one we compare with | ||
| 580 | in emacs-module-tests.el:module/async-pipe. */ | ||
| 554 | if (fputs ("data from thread", stream) < 0) | 581 | if (fputs ("data from thread", stream) < 0) |
| 555 | perror ("fputs"); | 582 | perror ("fputs"); |
| 556 | if (fclose (stream) != 0) | 583 | if (fclose (stream) != 0) |
| 557 | perror ("close"); | 584 | perror ("close"); |
| 585 | #ifndef WINDOWSNT | ||
| 558 | return NULL; | 586 | return NULL; |
| 587 | #endif | ||
| 559 | } | 588 | } |
| 560 | 589 | ||
| 561 | static emacs_value | 590 | static emacs_value |
| @@ -572,12 +601,17 @@ Fmod_test_async_pipe (emacs_env *env, ptrdiff_t nargs, emacs_value *args, | |||
| 572 | signal_errno (env, "fdopen"); | 601 | signal_errno (env, "fdopen"); |
| 573 | return NULL; | 602 | return NULL; |
| 574 | } | 603 | } |
| 604 | #ifdef WINDOWSNT | ||
| 605 | uintptr_t thd = _beginthread (write_to_pipe, 0, stream); | ||
| 606 | int error = (thd == (uintptr_t)-1L) ? errno : 0; | ||
| 607 | #else /* !WINDOWSNT */ | ||
| 575 | pthread_t thread; | 608 | pthread_t thread; |
| 576 | int error | 609 | int error |
| 577 | = pthread_create (&thread, NULL, write_to_pipe, stream); | 610 | = pthread_create (&thread, NULL, write_to_pipe, stream); |
| 611 | #endif | ||
| 578 | if (error != 0) | 612 | if (error != 0) |
| 579 | { | 613 | { |
| 580 | signal_system_error (env, error, "pthread_create"); | 614 | signal_system_error (env, error, "thread create"); |
| 581 | if (fclose (stream) != 0) | 615 | if (fclose (stream) != 0) |
| 582 | perror ("fclose"); | 616 | perror ("fclose"); |
| 583 | return NULL; | 617 | return NULL; |