Skip to content

Commit a195b8b

Browse files
committed
Sync mypy and bump version to 0.6.0
This breaks the ABI (a new function is added to the capsule). The new function enables making backward-compatible changes to the `librt.internal` capsule safely.
1 parent c447dbe commit a195b8b

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

lib-rt/librt_internal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,11 @@ NativeInternal_ABI_Version(void) {
962962
return LIBRT_INTERNAL_ABI_VERSION;
963963
}
964964

965+
static int
966+
NativeInternal_API_Version(void) {
967+
return LIBRT_INTERNAL_API_VERSION;
968+
}
969+
965970
static int
966971
librt_internal_module_exec(PyObject *m)
967972
{
@@ -999,6 +1004,7 @@ librt_internal_module_exec(PyObject *m)
9991004
(void *)cache_version_internal,
10001005
(void *)ReadBuffer_type_internal,
10011006
(void *)WriteBuffer_type_internal,
1007+
(void *)NativeInternal_API_Version,
10021008
};
10031009
PyObject *c_api_object = PyCapsule_New((void *)NativeInternal_API, "librt.internal._C_API", NULL);
10041010
if (PyModule_Add(m, "_C_API", c_api_object) < 0) {

lib-rt/librt_internal.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
#ifndef LIBRT_INTERNAL_H
22
#define LIBRT_INTERNAL_H
33

4-
#define LIBRT_INTERNAL_ABI_VERSION 1
5-
#define LIBRT_INTERNAL_API_LEN 19
4+
// ABI version -- only an exact match is compatible. This will only be changed in
5+
// very exceptional cases (likely never) due to strict backward compatibility
6+
// requirements.
7+
#define LIBRT_INTERNAL_ABI_VERSION 2
8+
9+
// API version -- more recent versions must maintain backward compatibility, i.e.
10+
// we can add new features but not remove or change existing features (unless
11+
// ABI version is changed, but see the comment above).
12+
#define LIBRT_INTERNAL_API_VERSION 0
13+
14+
// Number of functions in the capsule API. If you add a new function, also increase
15+
// LIBRT_INTERNAL_API_VERSION.
16+
#define LIBRT_INTERNAL_API_LEN 20
617

718
#ifdef LIBRT_INTERNAL_MODULE
819

@@ -27,6 +38,7 @@ static PyObject *read_bytes_internal(PyObject *data);
2738
static uint8_t cache_version_internal(void);
2839
static PyTypeObject *ReadBuffer_type_internal(void);
2940
static PyTypeObject *WriteBuffer_type_internal(void);
41+
static int NativeInternal_API_Version(void);
3042

3143
#else
3244

@@ -51,6 +63,7 @@ static void *NativeInternal_API[LIBRT_INTERNAL_API_LEN];
5163
#define cache_version_internal (*(uint8_t (*)(void)) NativeInternal_API[16])
5264
#define ReadBuffer_type_internal (*(PyTypeObject* (*)(void)) NativeInternal_API[17])
5365
#define WriteBuffer_type_internal (*(PyTypeObject* (*)(void)) NativeInternal_API[18])
66+
#define NativeInternal_API_Version (*(int (*)(void)) NativeInternal_API[19])
5467

5568
static int
5669
import_librt_internal(void)
@@ -64,7 +77,22 @@ import_librt_internal(void)
6477
return -1;
6578
memcpy(NativeInternal_API, capsule, sizeof(NativeInternal_API));
6679
if (NativeInternal_ABI_Version() != LIBRT_INTERNAL_ABI_VERSION) {
67-
PyErr_SetString(PyExc_ValueError, "ABI version conflict for librt.internal");
80+
char err[128];
81+
snprintf(err, sizeof(err), "ABI version conflict for librt.internal, expected %d, found %d",
82+
LIBRT_INTERNAL_ABI_VERSION,
83+
NativeInternal_ABI_Version()
84+
);
85+
PyErr_SetString(PyExc_ValueError, err);
86+
return -1;
87+
}
88+
if (NativeInternal_API_Version() < LIBRT_INTERNAL_API_VERSION) {
89+
char err[128];
90+
snprintf(err, sizeof(err),
91+
"API version conflict for librt.internal, expected %d or newer, found %d (hint: upgrade librt)",
92+
LIBRT_INTERNAL_API_VERSION,
93+
NativeInternal_API_Version()
94+
);
95+
PyErr_SetString(PyExc_ValueError, err);
6896
return -1;
6997
}
7098
return 0;

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ authors = [
1919
{name = "Jukka Lehtosalo", email = "[email protected]"},
2020
{name = "Ivan Levkivskyi", email = "[email protected]"},
2121
]
22-
version = "0.5.0"
22+
version = "0.6.0"
2323
license = {text = "MIT"}
2424
classifiers = [
2525
"Development Status :: 3 - Alpha",

0 commit comments

Comments
 (0)