Skip to content

Commit 1f1f9dc

Browse files
committed
add intial Python module structure
1 parent 702b815 commit 1f1f9dc

File tree

7 files changed

+103
-21
lines changed

7 files changed

+103
-21
lines changed
File renamed without changes.

client/lib/meson.build

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
client_inc = include_directories('.', '../../include')
2+
3+
libhopper = static_library(
4+
'hopper',
5+
'lib.c',
6+
include_directories: client_inc,
7+
pic: true,
8+
install: true,
9+
)
10+
11+
pkg = import('pkgconfig')
12+
13+
pkg.generate(
14+
libhopper,
15+
name: 'hopper',
16+
description: 'Hopper client library',
17+
version: meson.project_version(),
18+
subdirs: 'hopper',
19+
)
20+

client/meson.build

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,2 @@
1-
client_inc = include_directories('.', '../include')
2-
3-
libhopper = static_library(
4-
'hopper',
5-
'lib.c',
6-
include_directories: client_inc,
7-
pic: true,
8-
install: true,
9-
)
10-
11-
pkg = import('pkgconfig')
12-
13-
pkg.generate(
14-
libhopper,
15-
name: 'hopper',
16-
description: 'Hopper client library',
17-
version: meson.project_version(),
18-
subdirs: 'hopper',
19-
)
20-
1+
subdir('lib')
2+
subdir('py')

client/py/hoppermodule.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#define PY_SSIZE_T_CLEAN
2+
#include <Python.h>
3+
4+
#include "hopper/hopper.h"
5+
6+
// clang-format off
7+
struct _hopper_pipe {
8+
PyObject_HEAD
9+
PyObject *name;
10+
PyObject *endpoint;
11+
PyObject *hopper;
12+
int fd;
13+
int flags;
14+
};
15+
16+
static PyTypeObject _py_hopper_pipe = {
17+
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
18+
.tp_name = "hopper.HopperPipe",
19+
.tp_doc = PyDoc_STR("A object representing a Hopper pipe"),
20+
.tp_basicsize = sizeof(struct _hopper_pipe),
21+
.tp_itemsize = 0,
22+
.tp_flags = Py_TPFLAGS_DEFAULT,
23+
.tp_new = PyType_GenericNew,
24+
};
25+
// clang-format on
26+
27+
static PyObject *hopper_open_pipe(PyObject *self, PyObject *args) {}
28+
static PyObject *hopper_close_pipe(PyObject *self, PyObject *args) {}
29+
static PyObject *hopper_read_pipe(PyObject *self, PyObject *args) {}
30+
static PyObject *hopper_write_pipe(PyObject *self, PyObject *args) {}
31+
32+
static int hopper_module_exec(PyObject *m) {
33+
if (PyType_Ready(&_py_hopper_pipe) < 0)
34+
return -1;
35+
36+
if (PyModule_AddObjectRef(m, "HopperPipe", (PyObject *)&_py_hopper_pipe) <
37+
0)
38+
return -1;
39+
40+
return 0;
41+
}
42+
43+
static PyMethodDef hopper_methods[] = {
44+
{"open", hopper_open_pipe, METH_VARARGS, ""},
45+
{"close", hopper_close_pipe, METH_VARARGS, ""},
46+
{"read", hopper_read_pipe, METH_VARARGS, ""},
47+
{"write", hopper_write_pipe, METH_VARARGS, ""},
48+
{NULL, NULL, 0, NULL},
49+
};
50+
51+
static PyModuleDef_Slot hopper_slots[] = {
52+
{Py_mod_exec, (void *)hopper_module_exec},
53+
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
54+
{0, NULL},
55+
};
56+
57+
static struct PyModuleDef hoppermodule = {
58+
.m_base = PyModuleDef_HEAD_INIT,
59+
.m_name = "hopper",
60+
.m_doc = NULL,
61+
.m_methods = hopper_methods,
62+
.m_slots = hopper_slots,
63+
};
64+
65+
PyMODINIT_FUNC PyInit_hopper(void) { return PyModuleDef_Init(&hoppermodule); }
66+

client/py/meson.build

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
client_inc = include_directories('.', '../../include')
2+
3+
py = import('python').find_installation('python3')
4+
5+
py.extension_module(
6+
'hopper',
7+
'hoppermodule.c',
8+
include_directories: client_inc,
9+
install: true,
10+
)
11+

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
ninja
4545
pkg-config
4646

47+
python313
48+
4749
# one probably wants these too
4850
gdb
4951
valgrind

nix/package.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ stdenv, meson, ninja, pkg-config }:
1+
{ stdenv, meson, ninja, pkg-config, python313 }:
22

33
stdenv.mkDerivation {
44
name = "hopper";
@@ -9,5 +9,6 @@ stdenv.mkDerivation {
99
meson
1010
ninja
1111
pkg-config
12+
python313
1213
];
1314
}

0 commit comments

Comments
 (0)