cgo: change interface to not return already-collected error interfaces
This commit is contained in:
parent
a94a330345
commit
e8030a9579
38
main.go
38
main.go
@ -34,24 +34,24 @@ func Recall(f func(a int64) int64) int64 {
|
||||
}
|
||||
|
||||
//export Bolt_Open
|
||||
func Bolt_Open(path string, mode uint32, opts ObjectReference) (ObjectReference, error) {
|
||||
func Bolt_Open(path string, mode uint32, opts ObjectReference) (ObjectReference, string) {
|
||||
optsIFC, ok := gms.Get(opts)
|
||||
if !ok {
|
||||
return 0, NullObjectReference
|
||||
return 0, ""
|
||||
}
|
||||
|
||||
ptrBoltOps, ok := optsIFC.(*bolt.Options)
|
||||
if !ok {
|
||||
return 0, NullObjectReference
|
||||
return 0, ""
|
||||
}
|
||||
|
||||
ptrDB, err := bolt.Open(path, os.FileMode(mode), ptrBoltOps)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, err.Error()
|
||||
}
|
||||
|
||||
dbRef := gms.Put(ptrDB)
|
||||
return dbRef, nil
|
||||
return dbRef, ""
|
||||
}
|
||||
|
||||
func withBoltDBReference(b ObjectReference, fn func(db *bolt.DB) error) error {
|
||||
@ -68,13 +68,8 @@ func withBoltDBReference(b ObjectReference, fn func(db *bolt.DB) error) error {
|
||||
return fn(ptrDB)
|
||||
}
|
||||
|
||||
//export Error_Error
|
||||
func Error_Error(e error) string {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
//export Bolt_ListBuckets
|
||||
func Bolt_ListBuckets(b ObjectReference, browse []string, withEach func(string)) error {
|
||||
func Bolt_ListBuckets(b ObjectReference, browse []string, withEach func(string)) string {
|
||||
if len(browse) == 0 {
|
||||
return Bolt_ListBucketsAtRoot(b, withEach)
|
||||
}
|
||||
@ -102,11 +97,16 @@ func Bolt_ListBuckets(b ObjectReference, browse []string, withEach func(string))
|
||||
|
||||
})
|
||||
})
|
||||
return err
|
||||
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
//export Bolt_ListBucketsAtRoot
|
||||
func Bolt_ListBucketsAtRoot(b ObjectReference, withEach func(string)) error {
|
||||
func Bolt_ListBucketsAtRoot(b ObjectReference, withEach func(string)) string {
|
||||
err := withBoltDBReference(b, func(db *bolt.DB) error {
|
||||
return db.View(func(tx *bolt.Tx) error {
|
||||
|
||||
@ -118,21 +118,25 @@ func Bolt_ListBucketsAtRoot(b ObjectReference, withEach func(string)) error {
|
||||
|
||||
})
|
||||
})
|
||||
return err
|
||||
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
//export Bolt_Close
|
||||
func Bolt_Close(b ObjectReference) error {
|
||||
func Bolt_Close(b ObjectReference) string {
|
||||
err := withBoltDBReference(b, func(db *bolt.DB) error {
|
||||
return db.Close()
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
gms.Delete(b)
|
||||
return nil
|
||||
return ""
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
10
qbolt.h
10
qbolt.h
@ -63,18 +63,16 @@ extern GoInt64 Recall(void* p0);
|
||||
/* Return type for Bolt_Open */
|
||||
struct Bolt_Open_return {
|
||||
GoInt64 r0;
|
||||
GoInterface r1;
|
||||
GoString r1;
|
||||
};
|
||||
|
||||
extern struct Bolt_Open_return Bolt_Open(GoString p0, GoUint32 p1, GoInt64 p2);
|
||||
|
||||
extern GoString Error_Error(GoInterface p0);
|
||||
extern GoString Bolt_ListBuckets(GoInt64 p0, GoSlice p1, void* p2);
|
||||
|
||||
extern GoInterface Bolt_ListBuckets(GoInt64 p0, GoSlice p1, void* p2);
|
||||
extern GoString Bolt_ListBucketsAtRoot(GoInt64 p0, void* p1);
|
||||
|
||||
extern GoInterface Bolt_ListBucketsAtRoot(GoInt64 p0, void* p1);
|
||||
|
||||
extern GoInterface Bolt_Close(GoInt64 p0);
|
||||
extern GoString Bolt_Close(GoInt64 p0);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ BoltDB* BoltDB::createFrom(QString filePath, QString &errorOut)
|
||||
GoString filePathGS = Interop::toGoString_WeakRef(&filePathBytes);
|
||||
|
||||
auto open_ret = Bolt_Open(filePathGS, 0444, opts);
|
||||
if (open_ret.r1.v != nullptr) {
|
||||
errorOut = Interop::GetError(open_ret.r1);
|
||||
if (open_ret.r1.n != 0) {
|
||||
errorOut = QString(open_ret.r1.p);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -25,9 +25,9 @@ BoltDB* BoltDB::createFrom(QString filePath, QString &errorOut)
|
||||
|
||||
BoltDB::~BoltDB()
|
||||
{
|
||||
auto err = Bolt_Close(this->gmsDbRef);
|
||||
if (err.v != nullptr) {
|
||||
// Error closing database:
|
||||
// errorOut = Interop::GetError(err);
|
||||
GoString err = Bolt_Close(this->gmsDbRef);
|
||||
if (err.n != 0) {
|
||||
// Error closing database!
|
||||
// Need to display an alert... somewhere
|
||||
}
|
||||
}
|
||||
|
@ -5,15 +5,6 @@ Interop::Interop()
|
||||
|
||||
}
|
||||
|
||||
QString Interop::GetError(GoInterface err) {
|
||||
if (err.v == nullptr) {
|
||||
return ""; // no error
|
||||
}
|
||||
|
||||
GoString gs = Error_Error(err);
|
||||
return QString::fromUtf8(gs.p, gs.n);
|
||||
}
|
||||
|
||||
GoString Interop::toGoString_WeakRef(QByteArray *qba) {
|
||||
return GoString{qba->data(), qba->length()};
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ class Interop
|
||||
public:
|
||||
Interop();
|
||||
|
||||
static QString GetError(GoInterface err);
|
||||
|
||||
static GoString toGoString_WeakRef(QByteArray *qba);
|
||||
|
||||
static int64_t GetMagic();
|
||||
|
Loading…
Reference in New Issue
Block a user