Skip to content

Commit

Permalink
Merge pull request #86 from thierry-martinez/fix.85.forget_pyobjects_…
Browse files Browse the repository at this point in the history
…on_finalize

Fix #85: segmentation fault by forgetting objects on library unloading
  • Loading branch information
thierry-martinez authored Oct 24, 2022
2 parents 60ef460 + a0bc5ac commit e33f4c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[*] marks changes that break compatibility with previous versions.

# Development version

- Fix segmentation fault by forgetting objects on library unloading
(observed on Fedora Rawhide with address randomization)
(reported by Jerry James,
https://github.com/thierry-martinez/pyml/issues/85)

# 2022-09-05

- Support for OCaml 5.0
Expand Down
11 changes: 8 additions & 3 deletions py.ml
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,16 @@ let is_none v =

exception E of pyobject * pyobject

let fetched_exception = ref None
let create_ref_to_python_object () =
let result = ref None in
on_finalize (fun () -> result := None);
result

let fetched_exception = create_ref_to_python_object ()

let ocaml_exception_class = ref None
let ocaml_exception_class = create_ref_to_python_object ()

let ocaml_exception_capsule = ref None
let ocaml_exception_capsule = create_ref_to_python_object ()

let python_exception () =
let ptype, pvalue, ptraceback = pyerr_fetch_internal () in
Expand Down

0 comments on commit e33f4c4

Please sign in to comment.