Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
99061d1d
Commit
99061d1d
authored
Jul 31, 2016
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/modbtree: Switch to accepting stream object instead of filename.
Requires "embedded" BerkeleyDB BTree implementation.
parent
0dfe8494
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
extmod/modbtree.c
extmod/modbtree.c
+11
-5
No files found.
extmod/modbtree.c
View file @
99061d1d
...
...
@@ -31,6 +31,7 @@
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/stream.h"
#if MICROPY_PY_BTREE
...
...
@@ -314,15 +315,20 @@ STATIC const mp_obj_type_t btree_type = {
.
locals_dict
=
(
void
*
)
&
btree_locals_dict
,
};
STATIC
FILEVTABLE
btree_stream_fvtable
=
{
mp_stream_posix_read
,
mp_stream_posix_write
,
mp_stream_posix_lseek
,
mp_stream_posix_fsync
};
STATIC
mp_obj_t
mod_btree_open
(
size_t
n_args
,
const
mp_obj_t
*
pos_args
,
mp_map_t
*
kw_args
)
{
static
const
mp_arg_t
allowed_args
[]
=
{
{
MP_QSTR_server_side
,
MP_ARG_KW_ONLY
|
MP_ARG_BOOL
,
{.
u_bool
=
false
}
},
};
const
char
*
fname
=
NULL
;
if
(
pos_args
[
0
]
!=
mp_const_none
)
{
fname
=
mp_obj_str_get_str
(
pos_args
[
0
]);
}
// Make sure we got a stream object
mp_get_stream_raise
(
pos_args
[
0
],
MP_STREAM_OP_READ
|
MP_STREAM_OP_WRITE
|
MP_STREAM_OP_IOCTL
);
struct
{
mp_arg_val_t
server_side
;
...
...
@@ -330,7 +336,7 @@ STATIC mp_obj_t mod_btree_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t
mp_arg_parse_all
(
n_args
-
1
,
pos_args
+
1
,
kw_args
,
MP_ARRAY_SIZE
(
allowed_args
),
allowed_args
,
(
mp_arg_val_t
*
)
&
args
);
DB
*
db
=
__bt_open
(
fname
,
/*flags*/
O_CREAT
|
O_RDWR
,
/*mode*/
0770
,
/*openinfo*/
NULL
,
/*dflags*/
0
);
DB
*
db
=
__bt_open
(
pos_args
[
0
],
&
btree_stream_fvtable
,
/*openinfo*/
NULL
,
/*dflags*/
0
);
if
(
db
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
errno
)));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment