mirror of
https://github.com/Z3Prover/z3
synced 2025-04-07 09:55:19 +00:00
Fix memory and concurrency issues in OCaml API (#6992)
* Fix memory and concurrency issues in OCaml API * Undo locking changes
This commit is contained in:
parent
5b9fdcf462
commit
36382ccb57
|
@ -241,6 +241,20 @@ extern "C" {
|
||||||
Z3_CATCH_RETURN(nullptr);
|
Z3_CATCH_RETURN(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned Z3_API Z3_constructor_num_fields(Z3_context c, Z3_constructor constr) {
|
||||||
|
Z3_TRY;
|
||||||
|
LOG_Z3_constructor_num_fields(c, constr);
|
||||||
|
RESET_ERROR_CODE();
|
||||||
|
mk_c(c)->reset_last_result();
|
||||||
|
if (!constr) {
|
||||||
|
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
constructor* c = reinterpret_cast<constructor*>(constr);
|
||||||
|
return c->m_field_names.size();
|
||||||
|
Z3_CATCH_RETURN(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Z3_API Z3_query_constructor(Z3_context c,
|
void Z3_API Z3_query_constructor(Z3_context c,
|
||||||
Z3_constructor constr,
|
Z3_constructor constr,
|
||||||
|
|
|
@ -858,15 +858,6 @@ struct
|
||||||
module Constructor =
|
module Constructor =
|
||||||
struct
|
struct
|
||||||
type constructor = Z3native.constructor
|
type constructor = Z3native.constructor
|
||||||
|
|
||||||
module FieldNumTable = Hashtbl.Make(struct
|
|
||||||
type t = AST.ast
|
|
||||||
let equal x y = AST.compare x y = 0
|
|
||||||
let hash = AST.hash
|
|
||||||
end)
|
|
||||||
|
|
||||||
let _field_nums = FieldNumTable.create 0
|
|
||||||
|
|
||||||
let create (ctx:context) (name:Symbol.symbol) (recognizer:Symbol.symbol) (field_names:Symbol.symbol list) (sorts:Sort.sort option list) (sort_refs:int list) =
|
let create (ctx:context) (name:Symbol.symbol) (recognizer:Symbol.symbol) (field_names:Symbol.symbol list) (sorts:Sort.sort option list) (sort_refs:int list) =
|
||||||
let n = List.length field_names in
|
let n = List.length field_names in
|
||||||
if n <> List.length sorts then
|
if n <> List.length sorts then
|
||||||
|
@ -882,10 +873,9 @@ struct
|
||||||
(let f x = match x with None -> Z3native.mk_null_ast ctx | Some s -> s in
|
(let f x = match x with None -> Z3native.mk_null_ast ctx | Some s -> s in
|
||||||
List.map f sorts)
|
List.map f sorts)
|
||||||
sort_refs in
|
sort_refs in
|
||||||
FieldNumTable.add _field_nums no n;
|
|
||||||
no
|
no
|
||||||
|
|
||||||
let get_num_fields (x:constructor) = FieldNumTable.find _field_nums x
|
let get_num_fields (x:constructor) = Z3native.constructor_num_fields (gc x) x
|
||||||
|
|
||||||
let get_constructor_decl (x:constructor) =
|
let get_constructor_decl (x:constructor) =
|
||||||
let (a, _, _) = (Z3native.query_constructor (gc x) x (get_num_fields x)) in
|
let (a, _, _) = (Z3native.query_constructor (gc x) x (get_num_fields x)) in
|
||||||
|
@ -1512,13 +1502,15 @@ struct
|
||||||
in
|
in
|
||||||
Z3native.apply_result_inc_ref (gc x) arn;
|
Z3native.apply_result_inc_ref (gc x) arn;
|
||||||
let sg = Z3native.apply_result_get_num_subgoals (gc x) arn in
|
let sg = Z3native.apply_result_get_num_subgoals (gc x) arn in
|
||||||
let res = if sg = 0 then
|
if sg = 0 then (
|
||||||
raise (Error "No subgoals")
|
Z3native.apply_result_dec_ref (gc x) arn;
|
||||||
else
|
Z3native.tactic_dec_ref (gc x) tn;
|
||||||
Z3native.apply_result_get_subgoal (gc x) arn 0 in
|
raise (Error "No subgoals"))
|
||||||
Z3native.apply_result_dec_ref (gc x) arn;
|
else
|
||||||
Z3native.tactic_dec_ref (gc x) tn;
|
let res:goal = Z3native.apply_result_get_subgoal (gc x) arn 0 in
|
||||||
res
|
Z3native.apply_result_dec_ref (gc x) arn;
|
||||||
|
Z3native.tactic_dec_ref (gc x) tn;
|
||||||
|
res
|
||||||
|
|
||||||
let mk_goal = Z3native.mk_goal
|
let mk_goal = Z3native.mk_goal
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#ifndef __STDC_NO_ATOMICS__
|
||||||
|
#include <stdatomic.h>
|
||||||
|
#else
|
||||||
|
#define _Atomic(T) T
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -118,7 +124,7 @@ int compare_pointers(void* pt1, void* pt2) {
|
||||||
blocks that get copied. */
|
blocks that get copied. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Z3_context ctx;
|
Z3_context ctx;
|
||||||
unsigned long obj_count;
|
_Atomic(unsigned long) obj_count;
|
||||||
} Z3_context_plus_data;
|
} Z3_context_plus_data;
|
||||||
|
|
||||||
/* A context is wrapped to an OCaml value by storing a pointer
|
/* A context is wrapped to an OCaml value by storing a pointer
|
||||||
|
|
|
@ -2082,6 +2082,16 @@ extern "C" {
|
||||||
unsigned sort_refs[]
|
unsigned sort_refs[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Retrieve the number of fields of a constructor
|
||||||
|
|
||||||
|
\param c logical context.
|
||||||
|
\param constr constructor.
|
||||||
|
|
||||||
|
def_API('Z3_constructor_num_fields', UINT, (_in(CONTEXT), _in(CONSTRUCTOR)))
|
||||||
|
*/
|
||||||
|
unsigned Z3_API Z3_constructor_num_fields(Z3_context c, Z3_constructor constr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Reclaim memory allocated to constructor.
|
\brief Reclaim memory allocated to constructor.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue