File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -338,7 +338,6 @@ module Stub = struct
338
338
type connection
339
339
type result
340
340
341
- external conn_isnull : connection -> bool = "PQconn_isnull" [@@ noalloc]
342
341
external connect : string -> bool -> connection = "PQconnectdb_stub"
343
342
external finish : connection -> unit = "PQfinish_stub"
344
343
external reset : connection -> unit = "PQreset_stub"
@@ -968,8 +967,9 @@ module Connection (Mutex : Mutex) = struct
968
967
in
969
968
let conn_mtx = Mutex. create () in
970
969
let cancel_mtx = Mutex. create () in
970
+ let finished = ref false in (* bool becomes true after deallocation *)
971
971
let check_null () =
972
- if Stub. conn_isnull my_conn then
972
+ if ! finished then
973
973
failwith " Postgresql.check_null: connection already finished"
974
974
in
975
975
let wrap_conn f =
@@ -990,6 +990,18 @@ module Connection (Mutex : Mutex) = struct
990
990
f my_conn)
991
991
~finally: (fun _ -> Mutex. unlock cancel_mtx)
992
992
in
993
+ let wrap_both f =
994
+ protectx
995
+ ~f: (fun _ ->
996
+ Mutex. lock conn_mtx;
997
+ Mutex. lock cancel_mtx;
998
+ check_null () ;
999
+ (* Check again in case the world has changed *)
1000
+ f my_conn)
1001
+ ~finally: (fun _ ->
1002
+ Mutex. unlock cancel_mtx;
1003
+ Mutex. unlock conn_mtx)
1004
+ in
993
1005
let signal_error conn =
994
1006
raise (Error (Connection_failure (Stub. error_message conn)))
995
1007
in
@@ -1019,7 +1031,7 @@ module Connection (Mutex : Mutex) = struct
1019
1031
in
1020
1032
1021
1033
object (self (* Main routines *) )
1022
- method finish = wrap_conn (fun c -> Stub. finish c)
1034
+ method finish = wrap_both (fun c -> Stub. finish c; finished := true )
1023
1035
1024
1036
method try_reset =
1025
1037
wrap_conn (fun conn ->
Original file line number Diff line number Diff line change @@ -494,10 +494,6 @@ static inline void free_result(value v_res) {
494
494
}
495
495
}
496
496
497
- CAMLprim value PQres_isnull (value v_res ) {
498
- return Val_bool (get_res (v_res ) ? 0 : 1 );
499
- }
500
-
501
497
static struct custom_operations result_ops = {
502
498
"pg_ocaml_result" , free_result ,
503
499
custom_compare_default , custom_hash_default ,
You can’t perform that action at this time.
0 commit comments