Skip to content

Fix compile error on older systems without clock_get* - #8256

Merged
nobu merged 1 commit into
ruby:masterfrom
Bo98:old-clock-fix
Aug 24, 2023
Merged

Fix compile error on older systems without clock_get*#8256
nobu merged 1 commit into
ruby:masterfrom
Bo98:old-clock-fix

Conversation

@Bo98

@Bo98 Bo98 commented Aug 21, 2023

Copy link
Copy Markdown
Contributor

clock_get* calls are already gated in ifdef conditionals here:

ruby/process.c

Lines 8377 to 8381 in 3c53d31

#if defined(HAVE_CLOCK_GETTIME)
struct timespec ts;
c = NUM2CLOCKID(clk_id);
gettime:
ret = clock_gettime(c, &ts);

and here:

ruby/process.c

Lines 8556 to 8560 in 3c53d31

#if defined(HAVE_CLOCK_GETRES)
struct timespec ts;
c = NUM2CLOCKID(clk_id);
getres:
ret = clock_getres(c, &ts);

as are all other assignments of the variable c.

However declaration clockid_t c; was not wrapped in an ifdef. Besides being an unused variable, systems that are without clock_get* are unlikely to have clockid_t, resulting in a compile error. This pull request fixes that.

This regressed in Ruby 3.2.

@nobu

nobu commented Aug 22, 2023

Copy link
Copy Markdown
Member

What is your platform?
I'm curious where CLOCK_REALTIME etc are defined while clock_gettime is unavailable.

@Bo98

Bo98 commented Aug 22, 2023

Copy link
Copy Markdown
Contributor Author

Sorry, I wrote this patch months ago and it appears I've misread it. I've corrected the description - the issue is solely the clockid_t usage. I've also simplified the patch to reflect this. I've tested it again and the patch fixes the issue described.

I've found a bug report for it: https://bugs.ruby-lang.org/issues/19478. I happen to be using the same system (for old hardware), but it may affect other systems not updated for POSIX 2008 compliance.

@nobu nobu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation.
Makes sense.

@nobu
nobu merged commit 84a12d6 into ruby:master Aug 24, 2023
@Bo98
Bo98 deleted the old-clock-fix branch November 20, 2023 04:00
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

Successfully merging this pull request may close these issues.

2 participants