Skip to content

Commit a6ab71c

Browse files
authored
Rename native_internal to librt.internal (#8)
Also sync lib-rt from mypy.
1 parent ccf082a commit a6ab71c

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

lib-rt/CPy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,9 @@ void CPyTrace_LogEvent(const char *location, const char *line, const char *op, c
952952
static inline PyObject *CPyObject_GenericGetAttr(PyObject *self, PyObject *name) {
953953
return _PyObject_GenericGetAttrWithDict(self, name, NULL, 1);
954954
}
955+
static inline int CPyObject_GenericSetAttr(PyObject *self, PyObject *name, PyObject *value) {
956+
return _PyObject_GenericSetAttrWithDict(self, name, value, NULL);
957+
}
955958

956959
#if CPY_3_11_FEATURES
957960
PyObject *CPy_GetName(PyObject *obj);

lib-rt/native_internal.c renamed to lib-rt/librt_internal.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include <Python.h>
33
#include <stdint.h>
44
#include "CPy.h"
5-
#define NATIVE_INTERNAL_MODULE
6-
#include "native_internal.h"
5+
#define LIBRT_INTERNAL_MODULE
6+
#include "librt_internal.h"
77

88
#define START_SIZE 512
99
#define MAX_SHORT_INT_TAGGED (255 << 1)
@@ -558,7 +558,7 @@ write_tag(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames
558558
return Py_None;
559559
}
560560

561-
static PyMethodDef native_internal_module_methods[] = {
561+
static PyMethodDef librt_internal_module_methods[] = {
562562
{"write_bool", (PyCFunction)write_bool, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("write a bool")},
563563
{"read_bool", (PyCFunction)read_bool, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("read a bool")},
564564
{"write_str", (PyCFunction)write_str, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("write a string")},
@@ -574,11 +574,11 @@ static PyMethodDef native_internal_module_methods[] = {
574574

575575
static int
576576
NativeInternal_ABI_Version(void) {
577-
return NATIVE_INTERNAL_ABI_VERSION;
577+
return LIBRT_INTERNAL_ABI_VERSION;
578578
}
579579

580580
static int
581-
native_internal_module_exec(PyObject *m)
581+
librt_internal_module_exec(PyObject *m)
582582
{
583583
if (PyType_Ready(&BufferType) < 0) {
584584
return -1;
@@ -604,32 +604,32 @@ native_internal_module_exec(PyObject *m)
604604
(void *)read_tag_internal,
605605
(void *)NativeInternal_ABI_Version,
606606
};
607-
PyObject *c_api_object = PyCapsule_New((void *)NativeInternal_API, "native_internal._C_API", NULL);
607+
PyObject *c_api_object = PyCapsule_New((void *)NativeInternal_API, "librt.internal._C_API", NULL);
608608
if (PyModule_Add(m, "_C_API", c_api_object) < 0) {
609609
return -1;
610610
}
611611
return 0;
612612
}
613613

614-
static PyModuleDef_Slot native_internal_module_slots[] = {
615-
{Py_mod_exec, native_internal_module_exec},
614+
static PyModuleDef_Slot librt_internal_module_slots[] = {
615+
{Py_mod_exec, librt_internal_module_exec},
616616
#ifdef Py_MOD_GIL_NOT_USED
617617
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
618618
#endif
619619
{0, NULL}
620620
};
621621

622-
static PyModuleDef native_internal_module = {
622+
static PyModuleDef librt_internal_module = {
623623
.m_base = PyModuleDef_HEAD_INIT,
624-
.m_name = "native_internal",
624+
.m_name = "internal",
625625
.m_doc = "Mypy cache serialization utils",
626626
.m_size = 0,
627-
.m_methods = native_internal_module_methods,
628-
.m_slots = native_internal_module_slots,
627+
.m_methods = librt_internal_module_methods,
628+
.m_slots = librt_internal_module_slots,
629629
};
630630

631631
PyMODINIT_FUNC
632-
PyInit_native_internal(void)
632+
PyInit_internal(void)
633633
{
634-
return PyModuleDef_Init(&native_internal_module);
634+
return PyModuleDef_Init(&librt_internal_module);
635635
}

lib-rt/native_internal.h renamed to lib-rt/librt_internal.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#ifndef NATIVE_INTERNAL_H
2-
#define NATIVE_INTERNAL_H
1+
#ifndef LIBRT_INTERNAL_H
2+
#define LIBRT_INTERNAL_H
33

4-
#define NATIVE_INTERNAL_ABI_VERSION 0
4+
#define LIBRT_INTERNAL_ABI_VERSION 0
55

6-
#ifdef NATIVE_INTERNAL_MODULE
6+
#ifdef LIBRT_INTERNAL_MODULE
77

88
static PyObject *Buffer_internal(PyObject *source);
99
static PyObject *Buffer_internal_empty(void);
@@ -40,17 +40,17 @@ static void **NativeInternal_API;
4040
#define NativeInternal_ABI_Version (*(int (*)(void)) NativeInternal_API[13])
4141

4242
static int
43-
import_native_internal(void)
43+
import_librt_internal(void)
4444
{
45-
NativeInternal_API = (void **)PyCapsule_Import("native_internal._C_API", 0);
45+
NativeInternal_API = (void **)PyCapsule_Import("librt.internal._C_API", 0);
4646
if (NativeInternal_API == NULL)
4747
return -1;
48-
if (NativeInternal_ABI_Version() != NATIVE_INTERNAL_ABI_VERSION) {
49-
PyErr_SetString(PyExc_ValueError, "ABI version conflict for native_internal");
48+
if (NativeInternal_ABI_Version() != LIBRT_INTERNAL_ABI_VERSION) {
49+
PyErr_SetString(PyExc_ValueError, "ABI version conflict for librt.internal");
5050
return -1;
5151
}
5252
return 0;
5353
}
5454

5555
#endif
56-
#endif // NATIVE_INTERNAL_H
56+
#endif // LIBRT_INTERNAL_H

lib-rt/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def run(self) -> None:
7575
setup(
7676
ext_modules=[
7777
Extension(
78-
"native_internal",
78+
"librt.internal",
7979
[
80-
"native_internal.c",
80+
"librt_internal.c",
8181
"init.c",
8282
"int_ops.c",
8383
"exc_ops.c",
@@ -86,5 +86,5 @@ def run(self) -> None:
8686
],
8787
include_dirs=["."],
8888
)
89-
],
89+
]
9090
)

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.1.1"
22+
version = "0.2.0"
2323
license = {text = "MIT"}
2424
classifiers = [
2525
"Development Status :: 3 - Alpha",

sync-mypy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
def main() -> None:
99
with tempfile.TemporaryDirectory() as tmp_dir:
10-
mypy_dir = os.path.join(tmp_dir, "mypy")
10+
mypy_dir = os.path.join(tmp_dir, "mypy")
1111
subprocess.run(["git", "clone", REPO, mypy_dir, "--depth=1"], check=True)
12+
shutil.rmtree("lib-rt")
1213
shutil.copytree(os.path.join(mypy_dir, "mypyc", "lib-rt"), "lib-rt", dirs_exist_ok=True)
1314

1415

0 commit comments

Comments
 (0)