Skip to content

Fix segmentation fault by adding ctypes function signatures#60

Open
Odinroast wants to merge 1 commit intopimoroni:masterfrom
Odinroast:fix-segfault-ctypes-declarations
Open

Fix segmentation fault by adding ctypes function signatures#60
Odinroast wants to merge 1 commit intopimoroni:masterfrom
Odinroast:fix-segfault-ctypes-declarations

Conversation

@Odinroast
Copy link

The library was crashing with 'Segmentation fault (core dumped)' when calling start_ranging() and other methods on Python 3.7+ and 64-bit systems.

Root cause: ctypes was treating the pointer returned by initialise() as a 32-bit int instead of a 64-bit pointer, causing pointer truncation on 64-bit architectures.

Solution: Added explicit argtypes and restype declarations for all C function calls to preserve full pointer addresses.

Fixes segmentation faults reported in multiple issues on:

  • Python 3.7+
  • Raspberry Pi 4B, 5
  • Jetson Nano, Orin
  • Ubuntu 64-bit systems

Tested on: Jetson Orin with Python 3.10

The library was crashing with 'Segmentation fault (core dumped)' when calling
start_ranging() and other methods on Python 3.7+ and 64-bit systems.

Root cause: ctypes was treating the pointer returned by initialise() as a
32-bit int instead of a 64-bit pointer, causing pointer truncation on 64-bit
architectures.

Solution: Added explicit argtypes and restype declarations for all C function
calls to preserve full pointer addresses.

Fixes segmentation faults reported in multiple issues on:
- Python 3.7+
- Raspberry Pi 4B, 5
- Jetson Nano, Orin
- Ubuntu 64-bit systems

Tested on: Jetson Orin with Python 3.10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant