mirror of
https://github.com/Z3Prover/z3
synced 2026-04-30 07:43:38 +00:00
git bindings v1.0
This commit is contained in:
parent
e2486eff77
commit
66d0fb5477
33 changed files with 5289 additions and 7 deletions
67
src/api/go/log.go
Normal file
67
src/api/go/log.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// 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 result != 0 {
|
||||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue