Skip to content

Commit 27a58f1

Browse files
committed
Wrap/redefine static inline functions with '_' appended to their names
1 parent c560991 commit 27a58f1

File tree

5 files changed

+888
-5
lines changed

5 files changed

+888
-5
lines changed

suitesparse_graphblas/create_headers.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,14 +682,20 @@ def handle_static_inline(node):
682682
decl = node.decl
683683
if decl.name in DEPRECATED:
684684
return
685+
# Append "_" to the name that we expose to Python
686+
decl.type.type.declname += "_"
687+
decl.storage = ["extern"]
688+
decl.funcspec = []
685689
text = generator.visit(node).strip()
690+
decl_text = generator.visit(decl).strip()
686691
if skip_complex and has_complex(text):
687692
return
688693
return {
689694
"name": decl.name,
690695
"group": "static inline",
691696
"node": node,
692697
"text": text + "\n",
698+
"decl_text": decl_text + ";",
693699
}
694700

695701
grb_funcs = (handle_function_node(node) for node in grb_nodes)
@@ -791,9 +797,12 @@ def handle_funcs(group):
791797
text.append("****************/")
792798
text.extend(handle_funcs(groups["GxB methods"]))
793799

794-
# CFFI doesn't like compiling this
795-
# text.append("")
796-
# text.extend(handle_funcs(groups["static inline"]))
800+
# Declare wrapper functions with '_' appended to the name
801+
text.append("")
802+
text.append("/**************************")
803+
text.append("* static inline functions *")
804+
text.append("**************************/")
805+
text.extend(sorted((info["decl_text"] for info in groups["static inline"]), key=sort_key))
797806

798807
text.append("")
799808
text.append("/* int DEFINES */")
@@ -816,6 +825,9 @@ def create_source_text(groups, *, char_defines=None):
816825
]
817826
for item in sorted(char_defines, key=sort_key):
818827
text.append(f"char *{item}_STR = {item};")
828+
text.append("")
829+
for node in groups["static inline"]:
830+
text.append(node["text"])
819831
return text
820832

821833

@@ -843,6 +855,7 @@ def main():
843855
final_h = os.path.join(thisdir, "suitesparse_graphblas.h")
844856
final_no_complex_h = os.path.join(thisdir, "suitesparse_graphblas_no_complex.h")
845857
source_c = os.path.join(thisdir, "source.c")
858+
source_no_complex_c = os.path.join(thisdir, "source_no_complex.c")
846859

847860
# Copy original file
848861
print(f"Step 1: copy {args.graphblas} to {graphblas_h}")
@@ -881,8 +894,14 @@ def main():
881894
with open(source_c, "w") as f:
882895
f.write("\n".join(text))
883896

897+
# Create source (no complex)
898+
print(f"Step 6: create {source_no_complex_c}")
899+
text = create_source_text(groups_no_complex)
900+
with open(source_no_complex_c, "w") as f:
901+
f.write("\n".join(text))
902+
884903
# Check defines
885-
print("Step 6: check #define definitions")
904+
print("Step 7: check #define definitions")
886905
with open(graphblas_h) as f:
887906
text = f.read()
888907
define_lines = re.compile(r".*?#define\s+\w+\s+")

0 commit comments

Comments
 (0)