Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib-rt/CPy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions lib-rt/native_internal.c → lib-rt/librt_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <Python.h>
#include <stdint.h>
#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)
Expand Down Expand Up @@ -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")},
Expand All @@ -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;
Expand All @@ -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);
}
18 changes: 9 additions & 9 deletions lib-rt/native_internal.h → lib-rt/librt_internal.h
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions lib-rt/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -86,5 +86,5 @@ def run(self) -> None:
],
include_dirs=["."],
)
],
]
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion sync-mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down