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
gh-92869: ctypes: Add c_time_t #92870
base: main
Are you sure you want to change the base?
Conversation
9d077ff
to
f8a8dd3
Compare
Bump after 24 days of no activity. Any takers for reviewing this PR? |
@thp |
c_time_t = c_int64 | ||
elif SIZEOF_TIME_T == 4: | ||
c_time_t = c_int32 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thp
Is it ok not to define else case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If time_t
is not 32-bit or 64-bit, ctypes.c_time_t
will not be defined. I haven't seen a system where it's not 32-bit or 64-bit, but if we encounter such a system, the right type mapping can be added then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thp
I think you should add to raise an exception on else case to make sure.
It may not happen, but it is a good practice to consider such exceptional case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR updated, now raises an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems I had approved this PR yesterday before the PR was updated,
But it was a mistake. I made it on a smart phone.
It seem I can't dismiss the approval for this repository.
Is there a way to manually re-trigger it? I don't seem to have permissions. I can of course amend the commits and force-push to indirectly re-trigger a build? |
You can close and reopen the PR. |
There is another way to re-trigger. You can comment |
Misc/NEWS.d/next/Library/2022-05-17-06-27-39.gh-issue-92869.t8oBkw.rst
Outdated
Show resolved
Hide resolved
Pinging listed names from the experts index for review. A |
…oBkw.rst Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@@ -28,6 +28,9 @@ def test_size_t(self): | |||
def test_ssize_t(self): | |||
self.assertEqual(sizeof(c_void_p), sizeof(c_ssize_t)) | |||
|
|||
def test_time_t(self): | |||
self.assertIn(sizeof(c_time_t), (4, 8)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple test case added.
As the reason for c_time_t
is mostly to get the size of the object out of it, test_sizes.py
is probably the best place to test for this. This test is mostly about checking for the existence of the field, and that it's 4 or 8. If/when platforms are found that have a differently-sized c_time_t
, this test can be updated.
In the future, if we find a platform where c_time_t
is of a different type (different size or even non-integer type), some other tests could be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you compare sizeof(c_time_t)
with SIZEOF_TIME_T
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you should be able to use an independent version from _testcapi
.
A
Found that the ctypes documentation's "Calling functions" documentation does this (without setting
This uses the default return type of
Updated the documentation accordingly with setting The |
I think this is a better approach. (Thanks for noticing!) A |
This implements a simple way of using
ctypes.c_time_t
for 32-bit and 64-bittime_t
sizes. See #92869 for a discussion on why this is useful and considerations for different platforms. This doesn't take into account platforms wheretime_t
is defined asdouble
or anything else that's not a signed integer.