Skip to content

Commit ea4356d

Browse files
committed
add comments, remove some APIs, add _PyDict_InsertSplitValue
1 parent 54607ee commit ea4356d

File tree

11 files changed

+63
-34
lines changed

11 files changed

+63
-34
lines changed

Include/internal/pycore_abstract.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ _PyIndex_Check(PyObject *obj)
1616
return (tp_as_number != NULL && tp_as_number->nb_index != NULL);
1717
}
1818

19-
PyObject *_PyNumber_PowerNoMod(PyObject *lhs, PyObject *rhs);
20-
PyObject *_PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs);
19+
// Exported for external JIT support
20+
PyAPI_FUNC(PyObject *) _PyNumber_PowerNoMod(PyObject *lhs, PyObject *rhs);
21+
PyAPI_FUNC(PyObject *) _PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs);
2122

22-
extern int _PyObject_HasLen(PyObject *o);
23+
PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o);
2324

2425
/* === Sequence protocol ================================================ */
2526

Include/internal/pycore_call.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ _PyStack_UnpackDict(PyThreadState *tstate,
166166
PyObject *const *args, Py_ssize_t nargs,
167167
PyObject *kwargs, PyObject **p_kwnames);
168168

169-
extern void _PyStack_UnpackDict_Free(
169+
// Exported for external JIT support
170+
PyAPI_FUNC(void) _PyStack_UnpackDict_Free(
170171
PyObject *const *stack,
171172
Py_ssize_t nargs,
172173
PyObject *kwnames);

Include/internal/pycore_dict.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key,
3131
PyAPI_FUNC(int) _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key,
3232
Py_hash_t hash);
3333

34-
extern int _PyDict_DelItem_KnownHash_LockHeld(PyObject *mp, PyObject *key,
34+
// Exported for external JIT support
35+
PyAPI_FUNC(int) _PyDict_DelItem_KnownHash_LockHeld(PyObject *mp, PyObject *key,
3536
Py_hash_t hash);
3637

3738
extern int _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
@@ -88,8 +89,9 @@ extern PyDictKeysObject *_PyDict_NewKeysForClass(PyHeapTypeObject *);
8889
extern PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
8990

9091
/* Gets a version number unique to the current state of the keys of dict, if possible.
91-
* Returns the version number, or zero if it was not possible to get a version number. */
92-
extern uint32_t _PyDictKeys_GetVersionForCurrentState(
92+
* Returns the version number, or zero if it was not possible to get a version number.
93+
* Exported for external JIT support */
94+
PyAPI_FUNC(uint32_t) _PyDictKeys_GetVersionForCurrentState(
9395
PyInterpreterState *interp, PyDictKeysObject *dictkeys);
9496

9597
/* Gets a version number unique to the current state of the keys of dict, if possible.
@@ -99,8 +101,9 @@ extern uint32_t _PyDictKeys_GetVersionForCurrentState(
99101
*
100102
* The caller must hold the per-object lock on dict.
101103
*
102-
* Returns the version number, or zero if it was not possible to get a version number. */
103-
extern uint32_t _PyDict_GetKeysVersionForCurrentState(
104+
* Returns the version number, or zero if it was not possible to get a version number.
105+
* Exported for external JIT support */
106+
PyAPI_FUNC(uint32_t) _PyDict_GetKeysVersionForCurrentState(
104107
PyInterpreterState *interp, PyDictObject *dict);
105108

106109
extern size_t _PyDict_KeysSize(PyDictKeysObject *keys);
@@ -109,16 +112,18 @@ extern void _PyDictKeys_DecRef(PyDictKeysObject *keys);
109112

110113
/* _Py_dict_lookup() returns index of entry which can be used like DK_ENTRIES(dk)[index].
111114
* -1 when no entry found, -3 when compare raises error.
115+
* Exported for external JIT support
112116
*/
113-
extern Py_ssize_t _Py_dict_lookup(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr);
117+
PyAPI_FUNC(Py_ssize_t) _Py_dict_lookup(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr);
114118
extern Py_ssize_t _Py_dict_lookup_threadsafe(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr);
115119
extern Py_ssize_t _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t hash, _PyStackRef *value_addr);
116120

117121
extern int _PyDict_GetMethodStackRef(PyDictObject *dict, PyObject *name, _PyStackRef *method);
118122

119-
extern Py_ssize_t _PyDict_LookupIndexAndValue(PyDictObject *, PyObject *, PyObject **);
120-
extern Py_ssize_t _PyDict_LookupIndex(PyDictObject *, PyObject *);
121-
extern Py_ssize_t _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyObject *key);
123+
// Exported for external JIT support
124+
PyAPI_FUNC(Py_ssize_t) _PyDict_LookupIndexAndValue(PyDictObject *, PyObject *, PyObject **);
125+
PyAPI_FUNC(Py_ssize_t) _PyDict_LookupIndex(PyDictObject *, PyObject *);
126+
PyAPI_FUNC(Py_ssize_t) _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyObject *key);
122127

123128
/* Look up a string key in an all unicode dict keys, assign the keys object a version, and
124129
* store it in version.
@@ -127,9 +132,11 @@ extern Py_ssize_t _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyObject
127132
* strings.
128133
*
129134
* Returns DKIX_EMPTY if the key is not present.
135+
*
136+
* Exported for external JIT support
130137
*/
131-
extern Py_ssize_t _PyDictKeys_StringLookupAndVersion(PyDictKeysObject* dictkeys, PyObject *key, uint32_t *version);
132-
extern Py_ssize_t _PyDictKeys_StringLookupSplit(PyDictKeysObject* dictkeys, PyObject *key);
138+
PyAPI_FUNC(Py_ssize_t) _PyDictKeys_StringLookupAndVersion(PyDictKeysObject* dictkeys, PyObject *key, uint32_t *version);
139+
PyAPI_FUNC(Py_ssize_t) _PyDictKeys_StringLookupSplit(PyDictKeysObject* dictkeys, PyObject *key);
133140
PyAPI_FUNC(PyObject *)_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
134141
PyAPI_FUNC(void) _PyDict_LoadGlobalStackRef(PyDictObject *, PyDictObject *, PyObject *, _PyStackRef *);
135142

@@ -139,7 +146,8 @@ extern PyObject *_PyDict_LoadBuiltinsFromGlobals(PyObject *globals);
139146
/* Consumes references to key and value */
140147
PyAPI_FUNC(int) _PyDict_SetItem_Take2(PyDictObject *op, PyObject *key, PyObject *value);
141148
PyAPI_FUNC(int) _PyDict_SetItem_Take2_KnownHash(PyDictObject *op, PyObject *key, PyObject *value, Py_hash_t hash);
142-
extern int _PyDict_SetItem_LockHeld(PyDictObject *dict, PyObject *name, PyObject *value);
149+
// Exported for external JIT support
150+
PyAPI_FUNC(int) _PyDict_SetItem_LockHeld(PyDictObject *dict, PyObject *name, PyObject *value);
143151
// Export for '_asyncio' shared extension
144152
PyAPI_FUNC(int) _PyDict_SetItem_KnownHash_LockHeld(PyDictObject *mp, PyObject *key,
145153
PyObject *value, Py_hash_t hash);
@@ -324,6 +332,10 @@ _PyDictValues_AddToInsertionOrder(PyDictValues *values, Py_ssize_t ix)
324332
values->size = size+1;
325333
}
326334

335+
// Exported for external JIT support
336+
PyAPI_FUNC(void)
337+
_PyDict_InsertSplitValue(PyDictObject *mp, PyObject *key, PyObject *value, Py_ssize_t ix);
338+
327339
static inline size_t
328340
shared_keys_usable_size(PyDictKeysObject *keys)
329341
{

Include/internal/pycore_frame.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ struct _frame {
3838
PyObject *_f_frame_data[1];
3939
};
4040

41-
extern PyFrameObject* _PyFrame_New_NoTrack(PyCodeObject *code);
41+
// Exported for external JIT support
42+
PyAPI_FUNC(PyFrameObject *) _PyFrame_New_NoTrack(PyCodeObject *code);
4243

4344

4445
/* other API */

Include/internal/pycore_function.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ _PyFunction_IsVersionValid(uint32_t version)
2727
return version >= FUNC_VERSION_FIRST_VALID;
2828
}
2929

30-
extern uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func);
30+
// Exported for external JIT support
31+
PyAPI_FUNC(uint32_t) _PyFunction_GetVersionForCurrentState(PyFunctionObject *func);
3132
PyAPI_FUNC(void) _PyFunction_SetVersion(PyFunctionObject *func, uint32_t version);
3233
void _PyFunction_ClearCodeByVersion(uint32_t version);
3334

Include/internal/pycore_interpframe.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ _PyFrame_GetFrameObject(_PyInterpreterFrame *frame)
302302
return _PyFrame_MakeAndSetFrameObject(frame);
303303
}
304304

305-
void
305+
// Exported for external JIT support
306+
PyAPI_FUNC(void)
306307
_PyFrame_ClearLocals(_PyInterpreterFrame *frame);
307308

308309
/* Clears all references in the frame.
@@ -313,8 +314,10 @@ _PyFrame_ClearLocals(_PyInterpreterFrame *frame);
313314
* in the frame.
314315
* take should be set to 1 for heap allocated
315316
* frames like the ones in generators and coroutines.
317+
*
318+
* Exported for external JIT support
316319
*/
317-
void
320+
PyAPI_FUNC(void)
318321
_PyFrame_ClearExceptCode(_PyInterpreterFrame * frame);
319322

320323
int
@@ -338,7 +341,8 @@ _PyThreadState_HasStackSpace(PyThreadState *tstate, int size)
338341
size < tstate->datastack_limit - tstate->datastack_top;
339342
}
340343

341-
extern _PyInterpreterFrame *
344+
// Exported for external JIT support
345+
PyAPI_FUNC(_PyInterpreterFrame *)
342346
_PyThreadState_PushFrame(PyThreadState *tstate, size_t size);
343347

344348
PyAPI_FUNC(void) _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame *frame);

Include/internal/pycore_object.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,14 +879,16 @@ PyAPI_FUNC(PyObject *) _PyType_NewManagedObject(PyTypeObject *type);
879879
extern PyTypeObject* _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
880880
extern PyObject* _PyType_GetDocFromInternalDoc(const char *, const char *);
881881
extern PyObject* _PyType_GetTextSignatureFromInternalDoc(const char *, const char *, int);
882-
extern int _PyObject_SetAttributeErrorContext(PyObject *v, PyObject* name);
882+
// Exported for external JIT support
883+
PyAPI_FUNC(int) _PyObject_SetAttributeErrorContext(PyObject *v, PyObject* name);
883884

884885
void _PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp);
885886
extern int _PyObject_StoreInstanceAttribute(PyObject *obj,
886887
PyObject *name, PyObject *value);
887888
extern bool _PyObject_TryGetInstanceAttribute(PyObject *obj, PyObject *name,
888889
PyObject **attr);
889-
extern PyObject *_PyType_LookupRefAndVersion(PyTypeObject *, PyObject *,
890+
// Exported for external JIT support
891+
PyAPI_FUNC(PyObject *) _PyType_LookupRefAndVersion(PyTypeObject *, PyObject *,
890892
unsigned int *);
891893

892894
// Internal API to look for a name through the MRO.
@@ -910,7 +912,9 @@ PyAPI_FUNC(_PyStackRef) _PyObject_GetAttrStackRef(PyObject *obj, PyObject *name)
910912
// deferred reference counting.
911913
//
912914
// Returns 1 if the value was cached or 0 otherwise.
913-
extern int _PyType_CacheInitForSpecialization(PyHeapTypeObject *type,
915+
//
916+
// Exported for external JIT support
917+
PyAPI_FUNC(int) _PyType_CacheInitForSpecialization(PyHeapTypeObject *type,
914918
PyObject *init,
915919
unsigned int tp_version);
916920

Include/internal/pycore_pyerrors.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ extern PyObject* _PyErr_FormatFromCauseTstate(
170170
const char *format,
171171
...);
172172

173-
extern PyObject* _PyExc_CreateExceptionGroup(
173+
// Exported for external JIT support
174+
PyAPI_FUNC(PyObject *) _PyExc_CreateExceptionGroup(
174175
const char *msg,
175176
PyObject *excs);
176177

@@ -181,7 +182,8 @@ extern PyObject* _PyExc_PrepReraiseStar(
181182
extern int _PyErr_CheckSignalsTstate(PyThreadState *tstate);
182183

183184
extern void _Py_DumpExtensionModules(int fd, PyInterpreterState *interp);
184-
extern PyObject* _Py_CalculateSuggestions(PyObject *dir, PyObject *name);
185+
// Exported for external JIT support
186+
PyAPI_FUNC(PyObject *) _Py_CalculateSuggestions(PyObject *dir, PyObject *name);
185187
extern PyObject* _Py_Offer_Suggestions(PyObject* exception);
186188

187189
// Export for '_testinternalcapi' shared extension

Include/internal/pycore_traceback.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ extern void _Py_DumpHexadecimal(
8585
uintptr_t value,
8686
Py_ssize_t width);
8787

88-
extern PyObject* _PyTraceBack_FromFrame(
88+
// Exported for external JIT support
89+
PyAPI_FUNC(PyObject *) _PyTraceBack_FromFrame(
8990
PyObject *tb_next,
9091
PyFrameObject *frame);
9192

Include/internal/pycore_typeobject.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ extern void _PyStaticType_FiniBuiltin(
6060
extern void _PyStaticType_ClearWeakRefs(
6161
PyInterpreterState *interp,
6262
PyTypeObject *type);
63-
extern managed_static_type_state * _PyStaticType_GetState(
63+
// Exported for external JIT support
64+
PyAPI_FUNC(managed_static_type_state *) _PyStaticType_GetState(
6465
PyInterpreterState *interp,
6566
PyTypeObject *type);
6667

@@ -156,8 +157,9 @@ typedef int (*_py_validate_type)(PyTypeObject *);
156157
// It will verify the ``ty`` through user-defined validation function ``validate``,
157158
// and if the validation is passed, it will set the ``tp_version`` as valid
158159
// tp_version_tag from the ``ty``.
159-
extern int _PyType_Validate(PyTypeObject *ty, _py_validate_type validate, unsigned int *tp_version);
160-
extern int _PyType_CacheGetItemForSpecialization(PyHeapTypeObject *ht, PyObject *descriptor, uint32_t tp_version);
160+
// Exported for external JIT support
161+
int _PyType_Validate(PyTypeObject *ty, _py_validate_type validate, unsigned int *tp_version);
162+
int _PyType_CacheGetItemForSpecialization(PyHeapTypeObject *ht, PyObject *descriptor, uint32_t tp_version);
161163

162164
// Precalculates count of non-unique slots and fills wrapperbase.name_count.
163165
extern int _PyType_InitSlotDefs(PyInterpreterState *interp);

0 commit comments

Comments
 (0)