diff --git a/lib-rt/CPy.h b/lib-rt/CPy.h index b9cecb9..e9dfd8d 100644 --- a/lib-rt/CPy.h +++ b/lib-rt/CPy.h @@ -952,6 +952,9 @@ void CPyTrace_LogEvent(const char *location, const char *line, const char *op, c static inline PyObject *CPyObject_GenericGetAttr(PyObject *self, PyObject *name) { return _PyObject_GenericGetAttrWithDict(self, name, NULL, 1); } +static inline int CPyObject_GenericSetAttr(PyObject *self, PyObject *name, PyObject *value) { + return _PyObject_GenericSetAttrWithDict(self, name, value, NULL); +} #if CPY_3_11_FEATURES PyObject *CPy_GetName(PyObject *obj); diff --git a/lib-rt/native_internal.c b/lib-rt/librt_internal.c similarity index 96% rename from lib-rt/native_internal.c rename to lib-rt/librt_internal.c index a6511a1..cb9aa10 100644 --- a/lib-rt/native_internal.c +++ b/lib-rt/librt_internal.c @@ -2,8 +2,8 @@ #include #include #include "CPy.h" -#define NATIVE_INTERNAL_MODULE -#include "native_internal.h" +#define LIBRT_INTERNAL_MODULE +#include "librt_internal.h" #define START_SIZE 512 #define MAX_SHORT_INT_TAGGED (255 << 1) @@ -558,7 +558,7 @@ write_tag(PyObject *self, PyObject *const *args, size_t nargs, PyObject *kwnames return Py_None; } -static PyMethodDef native_internal_module_methods[] = { +static PyMethodDef librt_internal_module_methods[] = { {"write_bool", (PyCFunction)write_bool, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("write a bool")}, {"read_bool", (PyCFunction)read_bool, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("read a bool")}, {"write_str", (PyCFunction)write_str, METH_FASTCALL | METH_KEYWORDS, PyDoc_STR("write a string")}, @@ -574,11 +574,11 @@ static PyMethodDef native_internal_module_methods[] = { static int NativeInternal_ABI_Version(void) { - return NATIVE_INTERNAL_ABI_VERSION; + return LIBRT_INTERNAL_ABI_VERSION; } static int -native_internal_module_exec(PyObject *m) +librt_internal_module_exec(PyObject *m) { if (PyType_Ready(&BufferType) < 0) { return -1; @@ -604,32 +604,32 @@ native_internal_module_exec(PyObject *m) (void *)read_tag_internal, (void *)NativeInternal_ABI_Version, }; - PyObject *c_api_object = PyCapsule_New((void *)NativeInternal_API, "native_internal._C_API", NULL); + PyObject *c_api_object = PyCapsule_New((void *)NativeInternal_API, "librt.internal._C_API", NULL); if (PyModule_Add(m, "_C_API", c_api_object) < 0) { return -1; } return 0; } -static PyModuleDef_Slot native_internal_module_slots[] = { - {Py_mod_exec, native_internal_module_exec}, +static PyModuleDef_Slot librt_internal_module_slots[] = { + {Py_mod_exec, librt_internal_module_exec}, #ifdef Py_MOD_GIL_NOT_USED {Py_mod_gil, Py_MOD_GIL_NOT_USED}, #endif {0, NULL} }; -static PyModuleDef native_internal_module = { +static PyModuleDef librt_internal_module = { .m_base = PyModuleDef_HEAD_INIT, - .m_name = "native_internal", + .m_name = "internal", .m_doc = "Mypy cache serialization utils", .m_size = 0, - .m_methods = native_internal_module_methods, - .m_slots = native_internal_module_slots, + .m_methods = librt_internal_module_methods, + .m_slots = librt_internal_module_slots, }; PyMODINIT_FUNC -PyInit_native_internal(void) +PyInit_internal(void) { - return PyModuleDef_Init(&native_internal_module); + return PyModuleDef_Init(&librt_internal_module); } diff --git a/lib-rt/native_internal.h b/lib-rt/librt_internal.h similarity index 86% rename from lib-rt/native_internal.h rename to lib-rt/librt_internal.h index 63e902a..32fb129 100644 --- a/lib-rt/native_internal.h +++ b/lib-rt/librt_internal.h @@ -1,9 +1,9 @@ -#ifndef NATIVE_INTERNAL_H -#define NATIVE_INTERNAL_H +#ifndef LIBRT_INTERNAL_H +#define LIBRT_INTERNAL_H -#define NATIVE_INTERNAL_ABI_VERSION 0 +#define LIBRT_INTERNAL_ABI_VERSION 0 -#ifdef NATIVE_INTERNAL_MODULE +#ifdef LIBRT_INTERNAL_MODULE static PyObject *Buffer_internal(PyObject *source); static PyObject *Buffer_internal_empty(void); @@ -40,17 +40,17 @@ static void **NativeInternal_API; #define NativeInternal_ABI_Version (*(int (*)(void)) NativeInternal_API[13]) static int -import_native_internal(void) +import_librt_internal(void) { - NativeInternal_API = (void **)PyCapsule_Import("native_internal._C_API", 0); + NativeInternal_API = (void **)PyCapsule_Import("librt.internal._C_API", 0); if (NativeInternal_API == NULL) return -1; - if (NativeInternal_ABI_Version() != NATIVE_INTERNAL_ABI_VERSION) { - PyErr_SetString(PyExc_ValueError, "ABI version conflict for native_internal"); + if (NativeInternal_ABI_Version() != LIBRT_INTERNAL_ABI_VERSION) { + PyErr_SetString(PyExc_ValueError, "ABI version conflict for librt.internal"); return -1; } return 0; } #endif -#endif // NATIVE_INTERNAL_H +#endif // LIBRT_INTERNAL_H diff --git a/lib-rt/setup.py b/lib-rt/setup.py index 27ced3b..b78ad0d 100644 --- a/lib-rt/setup.py +++ b/lib-rt/setup.py @@ -75,9 +75,9 @@ def run(self) -> None: setup( ext_modules=[ Extension( - "native_internal", + "librt.internal", [ - "native_internal.c", + "librt_internal.c", "init.c", "int_ops.c", "exc_ops.c", @@ -86,5 +86,5 @@ def run(self) -> None: ], include_dirs=["."], ) - ], + ] ) diff --git a/pyproject.toml b/pyproject.toml index 993cdf4..e818377 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ authors = [ {name = "Jukka Lehtosalo", email = "jukka.lehtosalo@iki.fi"}, {name = "Ivan Levkivskyi", email = "levkivskyi@gmail.com"}, ] -version = "0.1.1" +version = "0.2.0" license = {text = "MIT"} classifiers = [ "Development Status :: 3 - Alpha", diff --git a/sync-mypy.py b/sync-mypy.py index b4cf9a7..0778f5d 100644 --- a/sync-mypy.py +++ b/sync-mypy.py @@ -7,8 +7,9 @@ def main() -> None: with tempfile.TemporaryDirectory() as tmp_dir: - mypy_dir = os.path.join(tmp_dir, "mypy") + mypy_dir = os.path.join(tmp_dir, "mypy") subprocess.run(["git", "clone", REPO, mypy_dir, "--depth=1"], check=True) + shutil.rmtree("lib-rt") shutil.copytree(os.path.join(mypy_dir, "mypyc", "lib-rt"), "lib-rt", dirs_exist_ok=True)