Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewContext should use tiledb_ctx_alloc_with_error #223

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package tiledb
#cgo LDFLAGS: -ltiledb
#cgo linux LDFLAGS: -ldl
#include <tiledb/tiledb.h>
#include <tiledb/tiledb_experimental.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is experimental, do we need to have a separate "experimental" vs. "non-experimental" file for this, with a flag like this:

//go:build experimental

(and a corresponding "not experimental" file)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this API is experimental mostly because we don't know why allocs fail. Once we collect some of the errors that will inform us about the reasons and lead to possible API changes in which we might want to remove or change this with_error API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about separating things which use "experimental" TileDB APIs versus the stable ones, and the assumption that I assume we make that only stable APIs should be included when building without -tags=experimental. I have an example of what I mean by this here: 53e5e08

#include <stdlib.h>
*/
import "C"
Expand All @@ -28,13 +29,25 @@ type Context struct {
func NewContext(config *Config) (*Context, error) {
var context Context
var ret C.int32_t
var tdbErr *C.tiledb_error_t
if config != nil {
ret = C.tiledb_ctx_alloc(config.tiledbConfig, &context.tiledbContext)
ret = C.tiledb_ctx_alloc_with_error(config.tiledbConfig, &context.tiledbContext, &tdbErr)
} else {
ret = C.tiledb_ctx_alloc(nil, &context.tiledbContext)
ret = C.tiledb_ctx_alloc_with_error(nil, &context.tiledbContext, &tdbErr)
}
if ret != C.TILEDB_OK {
return nil, fmt.Errorf("error creating tiledb context: %w", context.LastError())
// If the error isn't null report this
if tdbErr != nil {
var msg *C.char
C.tiledb_error_message(tdbErr, &msg)
defer C.tiledb_error_free(&tdbErr)
return nil, fmt.Errorf("error creating tiledb context: %s", C.GoString(msg))
}
// If the context is not null see if the error exists there
if context.tiledbContext != nil {
return nil, fmt.Errorf("error creating tiledb context: %w", context.LastError())
}
return nil, fmt.Errorf("error creating tiledb context: unknown error")
}

// Set finalizer for free C pointer on gc
Expand Down