kopia lustrzana https://github.com/micropython/micropython
py/dynruntime: Add mp_binary_get_size/get_val_array/set_val_array.
These are needed to read/write array.array objects, which is useful in native code to provide fast extensions that work with big arrays of data. Signed-off-by: Damien George <damien@micropython.org>pull/14177/head
rodzic
4662a71f44
commit
d2276f0d41
|
@ -29,6 +29,7 @@
|
||||||
// This header file contains definitions to dynamically implement the static
|
// This header file contains definitions to dynamically implement the static
|
||||||
// MicroPython runtime API defined in py/obj.h and py/runtime.h.
|
// MicroPython runtime API defined in py/obj.h and py/runtime.h.
|
||||||
|
|
||||||
|
#include "py/binary.h"
|
||||||
#include "py/nativeglue.h"
|
#include "py/nativeglue.h"
|
||||||
#include "py/objfun.h"
|
#include "py/objfun.h"
|
||||||
#include "py/objstr.h"
|
#include "py/objstr.h"
|
||||||
|
@ -184,6 +185,10 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
// General runtime functions
|
// General runtime functions
|
||||||
|
|
||||||
|
#define mp_binary_get_size(struct_type, val_type, palign) (mp_fun_table.binary_get_size((struct_type), (val_type), (palign)))
|
||||||
|
#define mp_binary_get_val_array(typecode, p, index) (mp_fun_table.binary_get_val_array((typecode), (p), (index)))
|
||||||
|
#define mp_binary_set_val_array(typecode, p, index, val_in) (mp_fun_table.binary_set_val_array((typecode), (p), (index), (val_in)))
|
||||||
|
|
||||||
#define mp_load_name(qst) (mp_fun_table.load_name((qst)))
|
#define mp_load_name(qst) (mp_fun_table.load_name((qst)))
|
||||||
#define mp_load_global(qst) (mp_fun_table.load_global((qst)))
|
#define mp_load_global(qst) (mp_fun_table.load_global((qst)))
|
||||||
#define mp_load_attr(base, attr) (mp_fun_table.load_attr((base), (attr)))
|
#define mp_load_attr(base, attr) (mp_fun_table.load_attr((base), (attr)))
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "py/binary.h"
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "py/smallint.h"
|
#include "py/smallint.h"
|
||||||
#include "py/nativeglue.h"
|
#include "py/nativeglue.h"
|
||||||
|
@ -330,6 +331,9 @@ const mp_fun_table_t mp_fun_table = {
|
||||||
mp_obj_get_float_to_d,
|
mp_obj_get_float_to_d,
|
||||||
mp_get_buffer,
|
mp_get_buffer,
|
||||||
mp_get_stream_raise,
|
mp_get_stream_raise,
|
||||||
|
mp_binary_get_size,
|
||||||
|
mp_binary_get_val_array,
|
||||||
|
mp_binary_set_val_array,
|
||||||
&mp_plat_print,
|
&mp_plat_print,
|
||||||
&mp_type_type,
|
&mp_type_type,
|
||||||
&mp_type_str,
|
&mp_type_str,
|
||||||
|
|
|
@ -156,7 +156,12 @@ typedef struct _mp_fun_table_t {
|
||||||
double (*obj_get_float_to_d)(mp_obj_t o);
|
double (*obj_get_float_to_d)(mp_obj_t o);
|
||||||
bool (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
|
bool (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
|
||||||
const mp_stream_p_t *(*get_stream_raise)(mp_obj_t self_in, int flags);
|
const mp_stream_p_t *(*get_stream_raise)(mp_obj_t self_in, int flags);
|
||||||
|
size_t (*binary_get_size)(char struct_type, char val_type, size_t *palign);
|
||||||
|
mp_obj_t (*binary_get_val_array)(char typecode, void *p, size_t index);
|
||||||
|
void (*binary_set_val_array)(char typecode, void *p, size_t index, mp_obj_t val_in);
|
||||||
const mp_print_t *plat_print;
|
const mp_print_t *plat_print;
|
||||||
|
// The following entries start at index 70 and are referenced by tools-mpy_ld.py,
|
||||||
|
// see constant MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET.
|
||||||
const mp_obj_type_t *type_type;
|
const mp_obj_type_t *type_type;
|
||||||
const mp_obj_type_t *type_str;
|
const mp_obj_type_t *type_str;
|
||||||
const mp_obj_type_t *type_list;
|
const mp_obj_type_t *type_list;
|
||||||
|
|
|
@ -52,6 +52,7 @@ MP_SCOPE_FLAG_VIPERRELOC = 0x10
|
||||||
MP_SCOPE_FLAG_VIPERRODATA = 0x20
|
MP_SCOPE_FLAG_VIPERRODATA = 0x20
|
||||||
MP_SCOPE_FLAG_VIPERBSS = 0x40
|
MP_SCOPE_FLAG_VIPERBSS = 0x40
|
||||||
MP_SMALL_INT_BITS = 31
|
MP_SMALL_INT_BITS = 31
|
||||||
|
MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET = 70
|
||||||
|
|
||||||
# ELF constants
|
# ELF constants
|
||||||
R_386_32 = 1
|
R_386_32 = 1
|
||||||
|
@ -754,7 +755,7 @@ def link_objects(env, native_qstr_vals_len):
|
||||||
# Resolve unknown symbols
|
# Resolve unknown symbols
|
||||||
mp_fun_table_sec = Section(".external.mp_fun_table", b"", 0)
|
mp_fun_table_sec = Section(".external.mp_fun_table", b"", 0)
|
||||||
fun_table = {
|
fun_table = {
|
||||||
key: 67 + idx
|
key: MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET + idx
|
||||||
for idx, key in enumerate(
|
for idx, key in enumerate(
|
||||||
[
|
[
|
||||||
"mp_type_type",
|
"mp_type_type",
|
||||||
|
|
Ładowanie…
Reference in New Issue