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
12 changes: 5 additions & 7 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ permissions:
jobs:
build:

runs-on: fedora-latest
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.13
uses: actions/setup-python@v3
with:
python-version: "3.13"
- name: Install dependencies
run: |
sudo dnf install -y python3-clang
python -m pip install --upgrade pip
sudo apt install -y python3-pip python3-clang-20
# python -m pip install --upgrade pip
# pip install clang==19.1.7
- name: Install package
run: |
pip install .
pip uninstall -y clang
- name: Run Tests
run: |
python test/run_tests.py
Expand Down
36 changes: 15 additions & 21 deletions cl_bindgen/processfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io
import itertools
import typing
import re
from enum import Enum
from dataclasses import dataclass, field
from collections import namedtuple
Expand All @@ -14,36 +15,29 @@
import clang.cindex as clang
from clang.cindex import TypeKind, CursorKind

# the pip version of clang doesn't have the comment functions,
# so define _output_comment accordingly
if hasattr(clang.Cursor, 'raw_comment'):
import re
def _lispify_comment(comment):
comment = comment.replace('"', '\\"')
return re.sub(_lispify_comment.doc_decorator_re, '', comment).strip()
_lispify_comment.doc_decorator_re = re.compile("^\s*[*/]* ?",flags=re.MULTILINE)

doc_decorator_re = re.compile("^\s*[*/]* ?",flags=re.MULTILINE)

def _lispify_comment(comment):
comment = comment.replace('"', '\\"')
return re.sub(doc_decorator_re, '', comment).strip()

def _output_comment(cursor, output, before='', after=''):
comment = cursor.raw_comment
if comment:
comment = _lispify_comment(comment)
output.write(before)
output.write(f' "{comment}"')
output.write(after)
else:
def _output_comment(cursor, output, before='', after=''):
pass
def _output_comment(cursor, output, before='', after=''):
comment = cursor.raw_comment
if comment:
comment = _lispify_comment(comment)
output.write(before)
output.write(f' "{comment}"')
output.write(after)

if hasattr(clang.Cursor, 'is_anonymous_record_decl'):
# This function was added in the llvm-project commit fbcf3cb7fe95d9d420b643ce379f7ee2106a6efc
# Which will be released in version 20? It's a simple definition though,
# so you can copy it into your cindex.py file and it should work.
print("Has anon record decl", file=sys.stderr)
def _is_anonymous_record_decl(cursor):
return cursor.is_anonymous_record_decl()
else:
print("WARNING: the version of libclang being used doesn't",
"provide a way to detect anonymous records.",
sep='\n ')
def _is_anonymous_record_decl(cursor):
# This won't work on some versions of libclang (particularlly libclang 17),
# as this spelling isn't empty, and is instead something like "(anonymous at ...)"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup

requirements = [
'clang',
'clang>=19.1.0',
'PyYAML'
]

Expand Down
3 changes: 3 additions & 0 deletions test/inputs/simple_struct.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* A very simple struct
*/
struct a {
int a;
int b;
Expand Down
3 changes: 3 additions & 0 deletions test/inputs/standard_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include <stddef.h>
#include <sys/types.h>

/**
* A function with a bunch of standard types
**/
int8_t std_int_fn(int16_t foo, int32_t bar, int64_t baz);

uint8_t uint_fn(uint16_t foo, uint32_t bar, uint64_t baz);
Expand Down
1 change: 1 addition & 0 deletions test/outputs/simple-struct.lisp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
;; next section imported from file inputs/simple_struct.h

(cffi:defcstruct a
"A very simple struct"
(a :int)
(b :int))
1 change: 1 addition & 0 deletions test/outputs/standard_types.lisp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;; next section imported from file inputs/standard_types.h

(cffi:defcfun ("std_int_fn" std-int-fn) :int8
"A function with a bunch of standard types"
(foo :int16)
(bar :int32)
(baz :int64))
Expand Down