Skip to content

Commit

Permalink
declare glibc function signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
P403n1x87 committed Oct 14, 2022
1 parent 094f09f commit bd1fd68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,10 @@ jobs:
valgrind \
gdb
# See (https://github.com/actions/setup-python/issues/442#issuecomment-1167837162)
- name: Temprorary setup-python workaround
run: |
curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi7_3.3-4_amd64.deb
sudo dpkg -i libffi6_3.2.1-8_amd64.deb
sudo ln -sf libffi.so.6.0.4 /usr/lib/x86_64-linux-gnu/libffi.so
sudo dpkg -i libffi7_3.3-4_amd64.deb
sudo ln -sf libffi.so.7.1.0 /lib/x86_64-linux-gnu/libffi.so.7
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python-version }}-dev

- name: Install Python 3.10
uses: actions/setup-python@v4
Expand Down
8 changes: 7 additions & 1 deletion test/cunit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ctypes
import re
from ctypes import CDLL, POINTER, Structure, c_char_p, cast
from ctypes import CDLL, POINTER, Structure, c_char_p, c_void_p, cast
from pathlib import Path
from subprocess import PIPE, STDOUT, run
from types import ModuleType
Expand Down Expand Up @@ -88,6 +88,10 @@ def compile(

C = CDLL("libc.so.6")

# https://github.com/actions/setup-python/issues/442#issuecomment-1193140956
C.malloc.restype = ctypes.c_void_p
C.free.argtypes = [ctypes.c_void_p]


class CFunctionDef:
def __init__(self, name: str, args: list[str], rtype: Any) -> None:
Expand Down Expand Up @@ -231,6 +235,8 @@ def visit_Decl(self, node: c_ast.Node) -> None:
if isinstance(ret_type, c_ast.PtrDecl):
if "".join(ret_type.type.type.names) == "char":
rtype = c_char_p
else:
rtype = c_void_p
args = (
[_.name if hasattr(_, "name") else None for _ in node.type.args.params]
if node.type.args is not None
Expand Down

0 comments on commit bd1fd68

Please sign in to comment.