Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] win32: sleep() warns and it doesn't really sleep forever #16631

Closed
p5pRT opened this issue Jul 15, 2018 · 8 comments
Closed

[PATCH] win32: sleep() warns and it doesn't really sleep forever #16631

p5pRT opened this issue Jul 15, 2018 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 15, 2018

Migrated from rt.perl.org#133376 (status was 'resolved')

Searchable as RT133376$

@p5pRT
Copy link
Author

p5pRT commented Jul 15, 2018

From @xenu

Under windows, sleep() called with no arguments triggers the following
warning​:

perl -Mwarnings -E "sleep"
sleep(2147450879) too large at -e line 1.

Additionally, it sleeps for just 4262198 seconds (~50 days) instead of
forever.

I have implemented win32_pause() which will fix the above problems, the
patch will follow.

@p5pRT
Copy link
Author

p5pRT commented Jul 15, 2018

From @xenu

On Sat, 14 Jul 2018 17​:51​:02 -0700
"Tomasz Konojacki \(via RT\)" <perlbug-followup@​perl.org> wrote​:

# New Ticket Created by Tomasz Konojacki
# Please include the string​: [perl #133376]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=133376 >

Under windows, sleep() called with no arguments triggers the following
warning​:

perl -Mwarnings -E "sleep"
sleep(2147450879) too large at -e line 1.

Additionally, it sleeps for just 4262198 seconds (~50 days) instead of
forever.

I have implemented win32_pause() which will fix the above problems, the
patch will follow.

The patch is attached.

@p5pRT
Copy link
Author

p5pRT commented Jul 15, 2018

From @xenu

0001-win32-fix-argumentless-sleep.patch
From 6196cf8728a5c10a6d9322b9e71cc7d67d96f4c6 Mon Sep 17 00:00:00 2001
From: Tomasz Konojacki <me@xenu.pl>
Date: Sun, 15 Jul 2018 02:33:16 +0200
Subject: [PATCH 1/1] win32: fix argumentless sleep()

Before this commit, pause() was implemented as a macro calling
win32_sleep((32767L << 16) + 32767), which was causing the following
problems with argumentless sleep():

- it was sleeping for 4262198 seconds (~50 days) instead of forever
- it was triggering "sleep(2147450879) too large" warning

This commit implements pause() as a proper function which calls
win32_msgwait() with an INFINITE timeout.

[perl #133376]
---
 makedef.pl       | 1 +
 win32/perlhost.h | 2 +-
 win32/win32.c    | 8 ++++++++
 win32/win32iop.h | 3 ++-
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/makedef.pl b/makedef.pl
index 661b71de7e..6b97ad0033 100644
--- a/makedef.pl
+++ b/makedef.pl
@@ -898,6 +898,7 @@ if ($ARGS{PLATFORM} =~ /^win(?:32|ce)$/) {
 			    win32_realloc
 			    win32_free
 			    win32_sleep
+			    win32_pause
 			    win32_times
 			    win32_access
 			    win32_alarm
diff --git a/win32/perlhost.h b/win32/perlhost.h
index 3260f62a02..6dd269efa7 100644
--- a/win32/perlhost.h
+++ b/win32/perlhost.h
@@ -1605,7 +1605,7 @@ PerlProcKillpg(struct IPerlProc* piPerl, int pid, int sig)
 int
 PerlProcPauseProc(struct IPerlProc* piPerl)
 {
-    return win32_sleep((32767L << 16) + 32767);
+    return win32_pause();
 }
 
 PerlIO*
diff --git a/win32/win32.c b/win32/win32.c
index c7656c631b..769a0e11b3 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2455,6 +2455,14 @@ win32_sleep(unsigned int t)
     return win32_msgwait(aTHX_ 0, NULL, t * 1000, NULL) / 1000;
 }
 
+DllExport int
+win32_pause(void)
+{
+    dTHX;
+    win32_msgwait(aTHX_ 0, NULL, INFINITE, NULL);
+    return -1;
+}
+
 DllExport unsigned int
 win32_alarm(unsigned int sec)
 {
diff --git a/win32/win32iop.h b/win32/win32iop.h
index 842bc073be..a9235d3595 100644
--- a/win32/win32iop.h
+++ b/win32/win32iop.h
@@ -128,6 +128,7 @@ DllExport  char*	win32_getenv(const char *name);
 DllExport  int		win32_putenv(const char *name);
 
 DllExport  unsigned 	win32_sleep(unsigned int);
+DllExport  int		win32_pause(void);
 DllExport  int		win32_times(struct tms *timebuf);
 DllExport  unsigned 	win32_alarm(unsigned int sec);
 DllExport  char*	win32_longpath(char *path);
@@ -429,7 +430,7 @@ END_EXTERN_C
  */
 
 #define pipe(fd)		win32_pipe((fd), 512, O_BINARY)
-#define pause()			win32_sleep((32767L << 16) + 32767)
+#define pause			win32_pause
 #define sleep			win32_sleep
 #define times			win32_times
 #define ioctl			win32_ioctl
-- 
2.17.0.windows.1

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2018

From @tonycoz

On Sat, 14 Jul 2018 17​:58​:58 -0700, me@​xenu.pl wrote​:

On Sat, 14 Jul 2018 17​:51​:02 -0700
"Tomasz Konojacki \(via RT\)" <perlbug-followup@​perl.org> wrote​:

# New Ticket Created by Tomasz Konojacki
# Please include the string​: [perl #133376]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=133376 >

Under windows, sleep() called with no arguments triggers the following
warning​:

perl -Mwarnings -E "sleep"
sleep(2147450879) too large at -e line 1.

Additionally, it sleeps for just 4262198 seconds (~50 days) instead of
forever.

I have implemented win32_pause() which will fix the above problems, the
patch will follow.

The patch is attached.

Thanks, applied as bbc9927.

Tony

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2018

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 1, 2018

@tonycoz - Status changed from 'open' to 'pending release'

@p5pRT
Copy link
Author

p5pRT commented May 22, 2019

From @khwilliamson

Thank you for filing this report. You have helped make Perl better.

With the release today of Perl 5.30.0, this and 160 other issues have been
resolved.

Perl 5.30.0 may be downloaded via​:
https://metacpan.org/release/XSAWYERX/perl-5.30.0

If you find that the problem persists, feel free to reopen this ticket.

@p5pRT
Copy link
Author

p5pRT commented May 22, 2019

@khwilliamson - Status changed from 'pending release' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant