Merge pull request #15844 from s-hadinger/berry_bytes_ismapped

Berry bytes.ismapped()
This commit is contained in:
s-hadinger 2022-06-22 19:26:35 +02:00 committed by GitHub
commit 9ae09b347b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1107 additions and 1087 deletions

View File

@ -519,6 +519,7 @@ extern const bcstring be_const_str_is_ota;
extern const bcstring be_const_str_is_running;
extern const bcstring be_const_str_is_spiffs;
extern const bcstring be_const_str_isinstance;
extern const bcstring be_const_str_ismapped;
extern const bcstring be_const_str_ismethod;
extern const bcstring be_const_str_isnan;
extern const bcstring be_const_str_issubclass;

File diff suppressed because it is too large Load Diff

View File

@ -1,44 +1,45 @@
#include "be_constobj.h"
static be_define_const_map_slots(be_class_bytes_map) {
{ be_const_key(set, -1), be_const_func(m_set) },
{ be_const_key(_X2Elen, 0), be_const_var(0) },
{ be_const_key(tob64, 4), be_const_func(m_tob64) },
{ be_const_key(_X2E_X2E, -1), be_const_func(m_connect) },
{ be_const_key(copy, 8), be_const_func(m_copy) },
{ be_const_key(setbits, -1), be_const_closure(setbits_closure) },
{ be_const_key(deinit, 18), be_const_func(m_deinit) },
{ be_const_key(setfloat, -1), be_const_func(m_setfloat) },
{ be_const_key(get, 2), be_const_func(m_getu) },
{ be_const_key(asstring, -1), be_const_func(m_asstring) },
{ be_const_key(getfloat, 24), be_const_func(m_getfloat) },
{ be_const_key(_buffer, -1), be_const_func(m_buffer) },
{ be_const_key(init, -1), be_const_func(m_init) },
{ be_const_key(_X2Esize, 23), be_const_var(1) },
{ be_const_key(tohex, 16), be_const_func(m_tohex) },
{ be_const_key(fromhex, -1), be_const_func(m_fromhex) },
{ be_const_key(setbits, 7), be_const_closure(setbits_closure) },
{ be_const_key(copy, 31), be_const_func(m_copy) },
{ be_const_key(size, 17), be_const_func(m_size) },
{ be_const_key(getbits, -1), be_const_closure(getbits_closure) },
{ be_const_key(fromb64, -1), be_const_func(m_fromb64) },
{ be_const_key(ismapped, -1), be_const_func(m_is_mapped) },
{ be_const_key(getbits, 30), be_const_closure(getbits_closure) },
{ be_const_key(getfloat, 17), be_const_func(m_getfloat) },
{ be_const_key(_change_buffer, -1), be_const_func(m_change_buffer) },
{ be_const_key(_X21_X3D, 30), be_const_func(m_nequal) },
{ be_const_key(clear, -1), be_const_func(m_clear) },
{ be_const_key(seti, 18), be_const_func(m_set) },
{ be_const_key(_X2B, -1), be_const_func(m_merge) },
{ be_const_key(add, 26), be_const_func(m_add) },
{ be_const_key(deinit, -1), be_const_func(m_deinit) },
{ be_const_key(tob64, -1), be_const_func(m_tob64) },
{ be_const_key(set, -1), be_const_func(m_set) },
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
{ be_const_key(_X2E_X2E, 6), be_const_func(m_connect) },
{ be_const_key(add, -1), be_const_func(m_add) },
{ be_const_key(_X2Ep, -1), be_const_var(0) },
{ be_const_key(_buffer, -1), be_const_func(m_buffer) },
{ be_const_key(_X21_X3D, 21), be_const_func(m_nequal) },
{ be_const_key(seti, 23), be_const_func(m_set) },
{ be_const_key(fromb64, -1), be_const_func(m_fromb64) },
{ be_const_key(asstring, 25), be_const_func(m_asstring) },
{ be_const_key(tostring, -1), be_const_func(m_tostring) },
{ be_const_key(item, -1), be_const_func(m_item) },
{ be_const_key(geti, -1), be_const_func(m_geti) },
{ be_const_key(init, -1), be_const_func(m_init) },
{ be_const_key(_X2Esize, 31), be_const_var(1) },
{ be_const_key(clear, -1), be_const_func(m_clear) },
{ be_const_key(_X2Elen, -1), be_const_var(2) },
{ be_const_key(_X2B, -1), be_const_func(m_merge) },
{ be_const_key(fromhex, -1), be_const_func(m_fromhex) },
{ be_const_key(get, -1), be_const_func(m_getu) },
{ be_const_key(size, 2), be_const_func(m_size) },
{ be_const_key(tohex, -1), be_const_func(m_tohex) },
{ be_const_key(resize, -1), be_const_func(m_resize) },
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
{ be_const_key(_X2Ep, -1), be_const_var(2) },
{ be_const_key(geti, -1), be_const_func(m_geti) },
{ be_const_key(fromstring, -1), be_const_func(m_fromstring) },
{ be_const_key(_X3D_X3D, -1), be_const_func(m_equal) },
{ be_const_key(_X3D_X3D, 5), be_const_func(m_equal) },
};
static be_define_const_map(
be_class_bytes_map,
33
34
);
BE_EXPORT_VARIABLE be_define_const_class(

View File

@ -1262,6 +1262,20 @@ static int m_buffer(bvm *vm)
be_return(vm);
}
/*
* Returns `btrue` if the buffer is mapped to memory
* or `bfalse` if memory was allocated by us.
*
* `ismapped() -> bool`
*/
static int m_is_mapped(bvm *vm)
{
buf_impl attr = m_read_attributes(vm, 1);
bbool mapped = (attr.mapped || (attr.bufptr == NULL));
be_pushbool(vm, mapped);
be_return(vm);
}
/*
* Change the pointer to a mapped buffer.
*
@ -1547,6 +1561,7 @@ void be_load_byteslib(bvm *vm)
{ ".len", NULL },
{ "_buffer", m_buffer },
{ "_change_buffer", m_change_buffer },
{ "ismapped", m_is_mapped },
{ "init", m_init },
{ "deinit", m_deinit },
{ "tostring", m_tostring },
@ -1590,6 +1605,7 @@ class be_class_bytes (scope: global, name: bytes) {
.len, var
_buffer, func(m_buffer)
_change_buffer, func(m_change_buffer)
ismapped, func(m_is_mapped)
init, func(m_init)
deinit, func(m_deinit)
tostring, func(m_tostring)