Skip to content

Commit

Permalink
Add remaining PyTuple API.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher committed Jul 9, 2019
1 parent 304a3b8 commit 1050131
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
9 changes: 7 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import typing


ARGS = 8


API: typing.Tuple[
typing.Union[typing.Tuple[str, str, str], typing.Tuple[str, str, str, str, str]],
...,
Expand Down Expand Up @@ -735,6 +738,7 @@
("PyTuple_GetItem", "On", "N"),
("PyTuple_GetSlice", "Onn", "N"),
("PyTuple_New", "n", "N"),
("PyTuple_Pack", "n" + "|" + "O" * ARGS, "N"),
("PyTuple_SET_ITEM", "OnO", ""),
("PyTuple_SetItem", "OnO", "i"),
("PyTuple_Size", "O", "n"),
Expand Down Expand Up @@ -978,6 +982,7 @@
}

EXTRAS = {"*"}
SKIP = {"|"}

FUNCTIONDEF = """\
static PyObject* capi_{}(PyObject* Py_UNUSED(self), PyObject* {}) {{
Expand Down Expand Up @@ -1170,7 +1175,7 @@ def build_stub(api: str, arg_types: str, return_type: str) -> str:
for index, code in enumerate(arg_types):
if code in EXTRAS:
preprocessed_args[-1] = arg_types[index - 1] + code
else:
elif code not in SKIP:
preprocessed_args.append(code)

args_str = ", ".join(
Expand All @@ -1195,7 +1200,7 @@ def build_definition(api: str, arg_types: str, return_type: str) -> str:
for index, code in enumerate(arg_types):
if code in EXTRAS:
preprocessed_args[-1] = arg_types[index - 1] + code
else:
elif code not in SKIP:
preprocessed_args.append(code)

if arg_types and arg_types != "O":
Expand Down
33 changes: 33 additions & 0 deletions pycapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -9573,6 +9573,38 @@ static PyObject* capi_PyTuple_New(PyObject* Py_UNUSED(self), PyObject* args) {
return result;
}

static PyObject* capi_PyTuple_Pack(PyObject* Py_UNUSED(self), PyObject* args) {

Py_ssize_t arg0;
PyObject* arg1;
PyObject* arg2;
PyObject* arg3;
PyObject* arg4;
PyObject* arg5;
PyObject* arg6;
PyObject* arg7;
PyObject* arg8;

PyObject* result;

if (!PyArg_ParseTuple(args, "n|OOOOOOOO:PyTuple_Pack", &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8)) {
return NULL;
}

result = PyTuple_Pack(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);

if (!result) {

if (PyErr_Occurred()) {
return NULL;
}

Py_RETURN_NONE;
}

return result;
}

static PyObject* capi_PyTuple_SET_ITEM(PyObject* Py_UNUSED(self), PyObject* args) {

PyObject* arg0;
Expand Down Expand Up @@ -12684,6 +12716,7 @@ static PyMethodDef CAPIMethods[] = {
{"PyTuple_GetItem", capi_PyTuple_GetItem, METH_VARARGS, NULL},
{"PyTuple_GetSlice", capi_PyTuple_GetSlice, METH_VARARGS, NULL},
{"PyTuple_New", capi_PyTuple_New, METH_VARARGS, NULL},
{"PyTuple_Pack", capi_PyTuple_Pack, METH_VARARGS, NULL},
{"PyTuple_SET_ITEM", capi_PyTuple_SET_ITEM, METH_VARARGS, NULL},
{"PyTuple_SetItem", capi_PyTuple_SetItem, METH_VARARGS, NULL},
{"PyTuple_Size", capi_PyTuple_Size, METH_O, NULL},
Expand Down
11 changes: 11 additions & 0 deletions pycapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,17 @@ def PyTuple_GET_SIZE(__0: object) -> int: ...
def PyTuple_GetItem(__0: object, __1: int) -> typing.Any: ...
def PyTuple_GetSlice(__0: object, __1: int, __2: int) -> typing.Any: ...
def PyTuple_New(__0: int) -> typing.Any: ...
def PyTuple_Pack(
__0: int,
__1: object,
__2: object,
__3: object,
__4: object,
__5: object,
__6: object,
__7: object,
__8: object,
) -> typing.Any: ...
def PyTuple_SET_ITEM(__0: object, __1: int, __2: object) -> None: ...
def PyTuple_SetItem(__0: object, __1: int, __2: object) -> int: ...
def PyTuple_Size(__0: object) -> int: ...
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
long_description_content_type="text/markdown",
name="pycapi",
url="https://github.com/brandtbucher/pycapi",
version="0.80.0",
version="0.81.0",
)

0 comments on commit 1050131

Please sign in to comment.