@@ -46,24 +46,25 @@ void init_vfs(py::module &m) {
46
46
47
47
class FileHandle {
48
48
private:
49
- tiledb_ctx_t * _ctx;
49
+ Context _ctx;
50
50
tiledb_vfs_fh_t *_fh;
51
51
52
52
public:
53
- // TODO ERROR CHECKING
54
-
55
53
FileHandle (const Context &ctx, const VFS &vfs, std::string uri,
56
54
tiledb_vfs_mode_t mode)
57
- : _ctx(ctx.ptr().get()) {
58
- tiledb_vfs_open (this ->_ctx , vfs.ptr ().get (), uri.c_str (), mode, &this ->_fh );
55
+ : _ctx(ctx) {
56
+ _ctx.handle_error (tiledb_vfs_open (_ctx.ptr ().get (), vfs.ptr ().get (),
57
+ uri.c_str (), mode, &this ->_fh ));
59
58
}
60
59
61
- void close () { tiledb_vfs_close (this -> _ctx , this ->_fh ); }
60
+ void close () { tiledb_vfs_close (_ctx. ptr (). get () , this ->_fh ); }
62
61
63
62
py::bytes read (uint64_t offset, uint64_t nbytes) {
64
63
py::array data = py::array (py::dtype::of<std::byte>(), nbytes);
65
64
py::buffer_info buffer = data.request ();
66
- tiledb_vfs_read (this ->_ctx , this ->_fh , offset, buffer.ptr , nbytes);
65
+
66
+ _ctx.handle_error (tiledb_vfs_read (_ctx.ptr ().get (), this ->_fh , offset,
67
+ buffer.ptr , nbytes));
67
68
68
69
auto np = py::module::import (" numpy" );
69
70
auto to_bytes = np.attr (" ndarray" ).attr (" tobytes" );
@@ -73,14 +74,18 @@ class FileHandle {
73
74
74
75
void write (py::buffer data) {
75
76
py::buffer_info buffer = data.request ();
76
- tiledb_vfs_write (this ->_ctx , this ->_fh , buffer.ptr , buffer.shape [0 ]);
77
+ _ctx.handle_error (tiledb_vfs_write (_ctx.ptr ().get (), this ->_fh , buffer.ptr ,
78
+ buffer.shape [0 ]));
77
79
}
78
80
79
- void flush () { tiledb_vfs_sync (this ->_ctx , this ->_fh ); }
81
+ void flush () {
82
+ _ctx.handle_error (tiledb_vfs_sync (_ctx.ptr ().get (), this ->_fh ));
83
+ }
80
84
81
85
bool closed () {
82
86
int32_t is_closed;
83
- tiledb_vfs_fh_is_closed (this ->_ctx , this ->_fh , &is_closed);
87
+ _ctx.handle_error (
88
+ tiledb_vfs_fh_is_closed (_ctx.ptr ().get (), this ->_fh , &is_closed));
84
89
return is_closed;
85
90
}
86
91
};
0 commit comments