-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,70 @@ | ||
#include <pybind11/pybind11.h> | ||
#include <iostream> | ||
|
||
#include "tiledb/tiledb" | ||
#include "tiledb/tiledb_experimental" | ||
#include <pybind11/pybind11.h> | ||
|
||
using namespace tiledb; | ||
namespace py = pybind11; | ||
|
||
void init_enums(py::module& m) { | ||
py::enum_<tiledb_query_type_t>(m, "QueryType") | ||
.value("READ", TILEDB_READ) | ||
.value("WRITE", TILEDB_WRITE) | ||
.value("DELETE", TILEDB_DELETE) | ||
.value("MODIFY_EXCLUSIVE", TILEDB_MODIFY_EXCLUSIVE); | ||
} | ||
class MyContext { | ||
public: | ||
MyContext() : msg_("Can I be a mongoose dog?") { | ||
std::cerr << "Context Constructor: " << (void*) this << std::endl; | ||
} | ||
|
||
~MyContext() { | ||
std::cerr << "Context Destructor: " << (void*) this << std::endl; | ||
} | ||
|
||
std::string get() const { | ||
return msg_; | ||
} | ||
|
||
private: | ||
std::string msg_; | ||
}; | ||
|
||
class MyGroup { | ||
public: | ||
MyGroup(const MyContext& ctx, const std::string& uri) : ctx_(ctx), uri_(uri) { | ||
std::cerr << "Group Constructor: " << (void*) this << std::endl; | ||
std::cerr << "Group Context: " << (void*) &ctx_ << std::endl; | ||
throw std::runtime_error("Look! A squirrel!"); | ||
} | ||
|
||
~MyGroup() { | ||
std::cerr << "Group Destructor: " << (void*) this << std::endl; | ||
} | ||
|
||
std::string dump(bool) { | ||
return ctx_.get(); | ||
} | ||
|
||
private: | ||
const MyContext& ctx_; | ||
std::string uri_; | ||
}; | ||
|
||
void init_context(py::module &m) { | ||
py::class_<Context>(m, "Context") | ||
py::class_<MyContext>(m, "Context") | ||
.def(py::init()); | ||
} | ||
|
||
std::string do_dump(Group& group, bool recursive) { | ||
std::string do_dump(MyGroup& group, bool recursive) { | ||
std::cerr << "DUMPING GROUP: " << (void*) &group << std::endl; | ||
auto ret = group.dump(recursive); | ||
std::cerr << "FINISHED DUMPING GROUP: " << (void*) &group << std::endl; | ||
return ret; | ||
} | ||
|
||
void init_group(py::module &m) { | ||
py::class_<Group>(m, "Group") | ||
py::class_<MyGroup>(m, "Group") | ||
.def( | ||
py::init<const Context &, const std::string &, tiledb_query_type_t>(), | ||
py::init<const MyContext &, const std::string &>(), | ||
py::keep_alive<1, 2>()) | ||
.def(py::init<const Context &, const std::string &, tiledb_query_type_t, | ||
const Config &>(), | ||
py::keep_alive<1, 2>()) | ||
.def("_dump", do_dump); | ||
|
||
} | ||
|
||
PYBIND11_MODULE(errortest, m) { | ||
m.doc() = "Test exceptions from contructors"; | ||
init_enums(m); | ||
init_context(m); | ||
init_group(m); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,11 @@ | ||
from pybind11.setup_helpers import Pybind11Extension, build_ext | ||
from setuptools import setup | ||
|
||
INC_DIRS = [ | ||
'/opt/tiledb/include', | ||
'/Users/davisp/github/tiledb/py-tiledb/venv/lib/python3.11/site-packages/pybind11/include' | ||
] | ||
DEF_MACROS = [] | ||
LIB_DIRS = ['/opt/tiledb/lib'] | ||
LIBS = ['tiledb'] | ||
LFLAGS = ['-stdlib=libc++', '-Wl,-rpath,/opt/tiledb/lib'] | ||
CXXFLAGS = ['-std=c++17', '-Wno-deprecated-declarations'] | ||
|
||
ext_modules = [ | ||
Pybind11Extension( | ||
"errortest", | ||
["main.cc"], | ||
include_dirs=INC_DIRS, | ||
define_macros=DEF_MACROS, | ||
library_dirs=LIB_DIRS, | ||
libraries=LIBS, | ||
extra_link_args=LFLAGS, | ||
extra_compile_args=CXXFLAGS + ["-fvisibility=hidden"], | ||
language="c++", | ||
), | ||
["main.cc"] | ||
) | ||
] | ||
|
||
setup(ext_modules=ext_modules, cmdclass={"build_ext": build_ext}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters