]> Repositorios git - scryer-prolog.git/commitdiff
use setup_call_cleanup/3 for with_locals
authorSkgland <[email protected]>
Sat, 9 Aug 2025 23:57:28 +0000 (01:57 +0200)
committerBennet Bleßmann <[email protected]>
Sun, 24 Aug 2025 17:56:25 +0000 (19:56 +0200)
as suggested by triska

src/lib/ffi.pl

index ab981e82928121d4cc9257177b0534da9bf76454..86c7bdc97c6897f191d4faf71096587203a8f23e 100644 (file)
@@ -54,6 +54,7 @@ And a new window should pop up!
 :- use_module(library(error)).
 :- use_module(library(format)).
 :- use_module(library(dcgs)).
+:- use_module(library(iso_ext)).
 
 %% foreign_struct(+Name, +Elements).
 %
@@ -144,9 +145,10 @@ array_type(ElemType, Len, ArrayType) :-
 
 with_locals(Locals, Goal) :-
     verify_locals(Locals),
-    allocate_locals(Locals),
-    ( catch(Goal, E, (deallocate_locals(Locals), throw(E))) -> deallocate_locals(Locals)
-    ; deallocate_locals(Locals), false
+    setup_call_cleanup(
+        allocate_locals(Locals),
+        Goal,
+        deallocate_locals(Locals)
     ).
 
 verify_locals(Locals) :-