Skip to content

Commit 9ab93b6

Browse files
authored
Fix Faulthandler import error for RobotFramework (RF). (#129)
- run: ruff format Signed-off-by: Guiliano99 <[email protected]>
1 parent f70842e commit 9ab93b6

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

.github/workflows/python_detailed.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env:
1616
LD_LIBRARY_PATH: /usr/local/lib
1717
WIN_LIBOQS_INSTALL_PATH: C:\liboqs
1818
VERSION: 0.14.0
19+
PYOQS_ENABLE_FAULTHANDLER: "1"
1920

2021
concurrency:
2122
group: test-python-detailed-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}

.github/workflows/python_simplified.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ concurrency:
1515
group: test-python-simplified-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
1616
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
1717

18+
env:
19+
PYOQS_ENABLE_FAULTHANDLER: "1"
1820

1921
jobs:
2022
build:

oqs/oqs.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
import subprocess
1818
import tempfile # to install liboqs on demand
1919
import time
20-
import faulthandler
21-
22-
faulthandler.enable()
20+
import os
2321

2422
try:
2523
import tomllib # Python 3.11+
@@ -52,6 +50,18 @@
5250
logger.setLevel(logging.INFO)
5351
logger.addHandler(logging.StreamHandler(stdout))
5452

53+
# To identify issues in native code, we enable faulthandler.
54+
# As an example, this will print a stack trace if a segfault occurs,
55+
# if the STFL key generation flag was not set when building liboqs.
56+
if os.environ.get("PYOQS_ENABLE_FAULTHANDLER", "0") == "1":
57+
import faulthandler
58+
59+
faulthandler.enable()
60+
logger.info("liboqs-python faulthandler is enabled")
61+
else:
62+
logger.info("liboqs-python faulthandler is disabled")
63+
64+
5565
# Expected return value from native OQS functions
5666
OQS_SUCCESS: Final[int] = 0
5767
OQS_ERROR: Final[int] = -1
@@ -111,9 +121,7 @@ def _load_shared_obj(
111121
elif platform.system() == "Windows":
112122
# Try both oqs.dll and liboqs.dll in the install path
113123
for dll_name in (name, f"lib{name}"):
114-
paths.append(
115-
path.absolute() / Path(dll_name).with_suffix(".dll")
116-
)
124+
paths.append(path.absolute() / Path(dll_name).with_suffix(".dll"))
117125
else: # Linux/FreeBSD/UNIX
118126
paths.append(path.absolute() / Path(f"lib{name}").with_suffix(".so"))
119127
# https://stackoverflow.com/questions/856116/changing-ld-library-path-at-runtime-for-ctypes

oqs/serialize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def deserialize_stateful_signature_key(
9292
public_key_bytes = one_asym_key["publicKey"].asOctets()
9393
return private_key_bytes, public_key_bytes
9494

95+
9596
def _may_generate_stfl_key(
9697
key_name: str, dir_name: str
9798
) -> tuple[Optional[bytes], Optional[bytes]]:

0 commit comments

Comments
 (0)