Skip to content

Commit

Permalink
c type-alias getter thing
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Aug 17, 2024
1 parent e7761a1 commit 1a80c4d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import annotations

from setuptools import Extension, setup

setup(
ext_modules=[
Extension(
name="basedtyping.type_alias_value_getter", sources=["c/type_alias_value_getter.c"]
)
]
)
45 changes: 45 additions & 0 deletions c/type_alias_value_getter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

typedef struct {
PyObject_HEAD
PyObject *name;
PyObject *type_params;
PyObject *compute_value;
PyObject *value;
PyObject *module;
} typealiasobject;

static PyObject *
foo_test(PyObject *self, PyObject *args)
{
PyObject *alias;
if (!PyArg_ParseTuple(args, "O", &alias))
return NULL;
typealiasobject *ta = (typealiasobject *)alias;
return Py_NewRef(ta->compute_value);
}

static PyMethodDef foo_methods[] = {
/* The cast of the function is necessary since PyCFunction values
* only take two PyObject* parameters, and keywdarg_parrot() takes
* three.
*/
{"test", (PyCFunction)(void(*)(void))foo_test, METH_VARARGS,
"debug alias."},
{NULL, NULL, 0, NULL} /* sentinel */
};

static struct PyModuleDef foo = {
PyModuleDef_HEAD_INIT,
"foo",
NULL,
-1,
foo_methods
};

PyMODINIT_FUNC
PyInit_foo(void)
{
PyModule_Create(&foo);
};
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = [
description = "Utilities for basedmypy"
name = "basedtyping"
version = "0.1.4"
build = "build.py"

[tool.poetry.dependencies]
python = "^3.8"
Expand Down

0 comments on commit 1a80c4d

Please sign in to comment.