3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-28 11:25:51 +00:00

Java bindings with no finalizers

Replacing finalizers with PhantomReferences, required quite a lot of
changes to the codebase.
This commit is contained in:
George Karpenkov 2016-06-12 14:18:13 +02:00
parent dfc80d3b69
commit 495ef0f055
48 changed files with 368 additions and 939 deletions

View file

@ -20,8 +20,14 @@ package com.microsoft.z3;
/**
* Constructors are used for datatype sorts.
**/
public class Constructor extends Z3Object
{
public class Constructor extends Z3Object {
private final int n;
Constructor(Context ctx, int n, long nativeObj) {
super(ctx, nativeObj);
this.n = n;
}
/**
* The number of fields of the constructor.
* @throws Z3Exception
@ -78,29 +84,16 @@ public class Constructor extends Z3Object
return t;
}
/**
* Destructor.
* @throws Throwable
* @throws Z3Exception on error
**/
protected void finalize() throws Throwable
{
try {
Native.delConstructor(getContext().nCtx(), getNativeObject());
} finally {
super.finalize();
}
@Override
void incRef(long o) {
// Datatype constructors are not reference counted.
getContext().getConstructorDRQ().storeReference(getContext(), this);
}
private int n = 0;
Constructor(Context ctx, Symbol name, Symbol recognizer,
Symbol[] fieldNames, Sort[] sorts, int[] sortRefs)
{
super(ctx);
n = AST.arrayLength(fieldNames);
static Constructor of(Context ctx, Symbol name, Symbol recognizer,
Symbol[] fieldNames, Sort[] sorts, int[] sortRefs) {
int n = AST.arrayLength(fieldNames);
if (n != AST.arrayLength(sorts))
throw new Z3Exception(
@ -112,9 +105,10 @@ public class Constructor extends Z3Object
if (sortRefs == null)
sortRefs = new int[n];
setNativeObject(Native.mkConstructor(ctx.nCtx(), name.getNativeObject(),
long nativeObj = Native.mkConstructor(ctx.nCtx(), name.getNativeObject(),
recognizer.getNativeObject(), n, Symbol.arrayToNative(fieldNames),
Sort.arrayToNative(sorts), sortRefs));
Sort.arrayToNative(sorts), sortRefs);
return new Constructor(ctx, n, nativeObj);
}
}