3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-17 06:11:44 +00:00
z3/src/api/go/log.go
copilot-swe-agent[bot] 3f4bd11f00 Fix Go bindings and enable in CI
- Fix all compilation errors in Go bindings
- Add missing type definitions (Pattern, ASTVector, ParamDescrs)
- Fix boolean comparisons to use bool() casts
- Fix Z3_app type casts using unsafe.Pointer
- Fix null symbol handling to use nil
- Fix unused variable in basic_example.go
- Fix CMake test target to run from examples/go directory
- Restore CI steps to build and test Go bindings

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
2026-02-16 06:05:58 +00:00

67 lines
1.1 KiB
Go

// Copyright (c) Microsoft Corporation 2025
// Z3 Go API: Logging functionality
package z3
/*
#include "z3.h"
#include <stdlib.h>
*/
import "C"
import (
"sync"
"unsafe"
)
var (
logMutex sync.Mutex
isLogOpen bool
)
// OpenLog opens an interaction log file
// Returns true if successful, false otherwise
func OpenLog(filename string) bool {
logMutex.Lock()
defer logMutex.Unlock()
cFilename := C.CString(filename)
defer C.free(unsafe.Pointer(cFilename))
result := C.Z3_open_log(cFilename)
if bool(result) {
isLogOpen = true
return true
}
return false
}
// CloseLog closes the interaction log
func CloseLog() {
logMutex.Lock()
defer logMutex.Unlock()
C.Z3_close_log()
isLogOpen = false
}
// AppendLog appends a user-provided string to the interaction log
// Panics if the log is not open
func AppendLog(s string) {
logMutex.Lock()
defer logMutex.Unlock()
if !isLogOpen {
panic("Log is not open")
}
cStr := C.CString(s)
defer C.free(unsafe.Pointer(cStr))
C.Z3_append_log(cStr)
}
// IsLogOpen returns true if the interaction log is open
func IsLogOpen() bool {
logMutex.Lock()
defer logMutex.Unlock()
return isLogOpen
}