Skip to content

Commit

Permalink
Revert last commits
Browse files Browse the repository at this point in the history
  • Loading branch information
Diviloper committed Mar 28, 2024
1 parent 675e07c commit 42013b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
20 changes: 3 additions & 17 deletions pymeos_cffi/pymeos_cffi/builder/build_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
def get_defined_functions(library_path):
result = subprocess.check_output(["nm", "-g", library_path])
output = result.decode("utf-8")
print(output)
lines = output.splitlines()
defined = {line.split(" ")[-1] for line in lines if " T " in line}
return defined
Expand All @@ -21,7 +22,7 @@ def remove_undefined_functions(content, so_path):
def remove_if_not_defined(m):
function = m.group(0).split("(")[0].strip().split(" ")[-1].strip("*")
if function in defined or (
sys.platform == "darwin" and ("_" + function) in defined
sys.platform == "darwin" and ("_" + function) in defined
):
for t in undefined_types:
if t in m.group(0):
Expand All @@ -39,7 +40,7 @@ def remove_if_not_defined(m):


def remove_repeated_functions(
content: str, seen_functions: set
content: str, seen_functions: set
) -> Tuple[str, Set[str]]:
def remove_if_repeated(m):
function = m.group(0).replace("\n", "").strip()
Expand All @@ -56,17 +57,6 @@ def remove_if_repeated(m):
return content, seen_functions


def add_underscore_prefix(content: str) -> str:
def add_underscore(m):
function = m.group(0).split("(")[0].strip().split(" ")[-1].strip("*")
return m.group(0).replace(function, "_" + function)

content = re.sub(
r"extern .*?;", add_underscore, content, flags=re.RegexFlag.MULTILINE
)
return content


def main(include_dir, so_path=None, destination_path="pymeos_cffi/builder/meos.h"):
files = ["meos.h", "meos_catalog.h", "meos_internal.h"]
global_content = ""
Expand Down Expand Up @@ -101,10 +91,6 @@ def main(include_dir, so_path=None, destination_path="pymeos_cffi/builder/meos.h

content, functions = remove_repeated_functions(content, functions)

if sys.platform == "darwin":
# In macOS, functions are prefixed with an underscore
content = add_underscore_prefix(content)

global_content += f"//-------------------- {file_name} --------------------\n"
global_content += content

Expand Down
13 changes: 2 additions & 11 deletions pymeos_cffi/pymeos_cffi/builder/build_pymeos_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ def main(header_path="pymeos_cffi/builder/meos.h"):
for match in matches:
named = match.groupdict()
function = named["function"]
if sys.platform == "darwin":
# In macOS, functions are prefixed with an underscore
function = function.lstrip("_")
inner_return_type = named["returnType"]
if function in skipped_functions:
continue
Expand Down Expand Up @@ -527,16 +524,10 @@ def build_function_string(
)
# If the function didn't return anything, just add the function call to the base
if return_type.return_type == "None":
function_string = (
f"{base}"
f" _lib.{'_' if sys.platform == 'darwin' else ''}{function_name}({inner_params})"
)
function_string = f"{base}" f" _lib.{function_name}({inner_params})"
# Otherwise, store the result in a variable
else:
function_string = (
f"{base}"
f" result = _lib.{'_' if sys.platform == 'darwin' else ''}{function_name}({inner_params})"
)
function_string = f"{base}" f" result = _lib.{function_name}({inner_params})"

# Add error handling
function_string += f"\n _check_error()"
Expand Down

0 comments on commit 42013b7

Please sign in to comment.