@@ -148,15 +148,14 @@ Calling functions
148
148
^^^^^^^^^^^^^^^^^
149
149
150
150
You can call these functions like any other Python callable. This example uses
151
- the ``time() `` function, which returns system time in seconds since the Unix
152
- epoch, and the ``GetModuleHandleA() `` function, which returns a win32 module
153
- handle.
151
+ the ``rand() `` function, which takes no arguments and returns a pseudo-random integer::
154
152
155
- This example calls both functions with a ``NULL `` pointer (``None `` should be used
156
- as the ``NULL `` pointer)::
153
+ >>> print(libc.rand()) # doctest: +SKIP
154
+ 1804289383
155
+
156
+ On Windows, you can call the ``GetModuleHandleA() `` function, which returns a win32 module
157
+ handle (passing ``None `` as single argument to call it with a ``NULL `` pointer)::
157
158
158
- >>> print(libc.time(None)) # doctest: +SKIP
159
- 1150640792
160
159
>>> print(hex(windll.kernel32.GetModuleHandleA(None))) # doctest: +WINDOWS
161
160
0x1d000000
162
161
>>>
@@ -247,6 +246,8 @@ Fundamental data types
247
246
| :class: `c_ssize_t ` | :c:type: `ssize_t ` or | int |
248
247
| | :c:type: `Py_ssize_t ` | |
249
248
+----------------------+------------------------------------------+----------------------------+
249
+ | :class: `c_time_t ` | :c:type: `time_t ` | int |
250
+ +----------------------+------------------------------------------+----------------------------+
250
251
| :class: `c_float ` | :c:type: `float ` | float |
251
252
+----------------------+------------------------------------------+----------------------------+
252
253
| :class: `c_double ` | :c:type: `double ` | float |
@@ -447,6 +448,21 @@ By default functions are assumed to return the C :c:type:`int` type. Other
447
448
return types can be specified by setting the :attr: `restype ` attribute of the
448
449
function object.
449
450
451
+ The C prototype of ``time() `` is ``time_t time(time_t *) ``. Because ``time_t ``
452
+ might be of a different type than the default return type ``int ``, you should
453
+ specify the ``restype ``::
454
+
455
+ >>> libc.time.restype = c_time_t
456
+
457
+ The argument types can be specified using ``argtypes ``::
458
+
459
+ >>> libc.time.argtypes = (POINTER(c_time_t),)
460
+
461
+ To call the function with a ``NULL `` pointer as first argument, use ``None ``::
462
+
463
+ >>> print(libc.time(None)) # doctest: +SKIP
464
+ 1150640792
465
+
450
466
Here is a more advanced example, it uses the ``strchr `` function, which expects
451
467
a string pointer and a char, and returns a pointer to a string::
452
468
@@ -2275,6 +2291,13 @@ These are the fundamental ctypes data types:
2275
2291
.. versionadded :: 3.2
2276
2292
2277
2293
2294
+ .. class :: c_time_t
2295
+
2296
+ Represents the C :c:type: `time_t ` datatype.
2297
+
2298
+ .. versionadded :: 3.12
2299
+
2300
+
2278
2301
.. class :: c_ubyte
2279
2302
2280
2303
Represents the C :c:type: `unsigned char ` datatype, it interprets the value as
0 commit comments