77
77
int PyApi_Tuple_FromArray (uintptr_t len, PyRef * array, PyRef * result);
78
78
```
79
79
80
- ## Use standard C99 types, not custom ones.
80
+ ## Use C99 <stdint.h> types
81
+
82
+ ### Use C99 integers types, not custom ones
81
83
82
84
In other words, use `intptr_t` not `Py_ssize_t`.
83
85
This helps portability, and wrapping for other languages.
84
86
87
+ ### Use C99 integers types, not legacy ones
88
+
89
+ Use `int32_t` or `intptr_t` not `int` or `long`.
90
+ `long` should never be used, as it differs in size even on the same hardware.
91
+ `int` is acceptable only as a return `kind`.
92
+ If the return value can represent a value, then a `<stdint.h>` type should be used.
93
+
94
+ E.g.
95
+ * `int PyApi_Tuple_FromArray(uintptr_t len, PyRef *array, PyRef *result)` is OK.
96
+ * But, `int PyApi_Tuple_GetSize(PyTupleRef *ref)` is not OK as it returns a value, not just a `kind`.
97
+ * It should be `uintptr_t PyApi_Tuple_GetSize(PyTupleRef *ref)`
98
+
85
99
## No variable length argument lists.
86
100
87
101
In other words no `...` at the end of the parameters.
@@ -158,9 +172,6 @@ we should specify it as
158
172
PyCodeRef PyApi_Function_GetCode(PyFunctionRef f);
159
173
```
160
174
161
- This may force us to add some extra casts to support the ` M ` form,
162
- but should keep code cleaner overall.
163
-
164
175
## Provide a safe and easy to use set of casts
165
176
166
177
If we want to use specific types, we need casts.
@@ -180,6 +191,9 @@ Downcasts are tricky, because we can't return a more type specific ``PyRef`` typ
180
191
Either the ``PyRef`` is unsafe, due to potential errors, or it is useless as
181
192
the result of the cast, being as general as its input.
182
193
194
+ * `PyListRef PyApi_List_DownCast(PyRef obj)`: unsafe
195
+ * `PyRef PyApi_List_DownCast(PyRef obj)`: useless
196
+
183
197
Consequently the API contains macros to wrap the test then unsafe cast idiom.
184
198
185
199
For example support we want to treat an reference as a reference to a `list`.
0 commit comments