summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/modstruct.c2
-rw-r--r--py/obj.c8
-rw-r--r--py/obj.h4
-rw-r--r--py/objfun.c2
-rw-r--r--py/objint.c2
-rw-r--r--unix/modsocket.c6
6 files changed, 12 insertions, 12 deletions
diff --git a/py/modstruct.c b/py/modstruct.c
index 945f4fe461..cd2516b240 100644
--- a/py/modstruct.c
+++ b/py/modstruct.c
@@ -56,7 +56,7 @@ STATIC mp_obj_t struct_unpack(mp_obj_t fmt_in, mp_obj_t data_in) {
uint size = calcsize_items(fmt);
mp_obj_tuple_t *res = mp_obj_new_tuple(size, NULL);
mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(data_in, &bufinfo);
+ mp_get_buffer_raise(data_in, &bufinfo, MP_BUFFER_READ);
byte *p = bufinfo.buf;
for (uint i = 0; i < size; i++) {
diff --git a/py/obj.c b/py/obj.c
index e0a712cb01..4b72514476 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -357,20 +357,20 @@ mp_obj_t mp_identity(mp_obj_t self) {
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_identity_obj, mp_identity);
-bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo) {
+bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags) {
mp_obj_type_t *type = mp_obj_get_type(obj);
if (type->buffer_p.get_buffer == NULL) {
return false;
}
- int ret = type->buffer_p.get_buffer(obj, bufinfo, MP_BUFFER_READ);
+ int ret = type->buffer_p.get_buffer(obj, bufinfo, flags);
if (ret != 0 || bufinfo->buf == NULL) {
return false;
}
return true;
}
-void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo) {
- if (!mp_get_buffer(obj, bufinfo)) {
+void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags) {
+ if (!mp_get_buffer(obj, bufinfo, flags)) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "object with buffer protocol required"));
}
}
diff --git a/py/obj.h b/py/obj.h
index 969f2fcb29..dd25ec4f22 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -209,8 +209,8 @@ typedef struct _mp_buffer_info_t {
typedef struct _mp_buffer_p_t {
machine_int_t (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags);
} mp_buffer_p_t;
-bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo);
-void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo);
+bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags);
+void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, int flags);
// Stream protocol
typedef struct _mp_stream_p_t {
diff --git a/py/objfun.c b/py/objfun.c
index 633f5d0cae..ab6326057f 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -427,7 +427,7 @@ STATIC machine_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
return (machine_uint_t)items;
} else {
mp_buffer_info_t bufinfo;
- if (mp_get_buffer(obj, &bufinfo)) {
+ if (mp_get_buffer(obj, &bufinfo, MP_BUFFER_WRITE)) {
// supports the buffer protocol, return a pointer to the data
return (machine_uint_t)bufinfo.buf;
} else {
diff --git a/py/objint.c b/py/objint.c
index 8bec4a3e3f..110876e003 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -273,7 +273,7 @@ STATIC mp_obj_t int_from_bytes(uint n_args, const mp_obj_t *args) {
// get the buffer info
mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(args[1], &bufinfo);
+ mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
// convert the bytes to an integer
machine_uint_t value = 0;
diff --git a/unix/modsocket.c b/unix/modsocket.c
index 44ad698e4a..bfa5849c86 100644
--- a/unix/modsocket.c
+++ b/unix/modsocket.c
@@ -81,7 +81,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno);
STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
mp_obj_socket_t *self = self_in;
mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(addr_in, &bufinfo);
+ mp_get_buffer_raise(addr_in, &bufinfo, MP_BUFFER_READ);
int r = connect(self->fd, (const struct sockaddr *)bufinfo.buf, bufinfo.len);
RAISE_ERRNO(r, errno);
return mp_const_none;
@@ -91,7 +91,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
mp_obj_socket_t *self = self_in;
mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(addr_in, &bufinfo);
+ mp_get_buffer_raise(addr_in, &bufinfo, MP_BUFFER_READ);
int r = bind(self->fd, (const struct sockaddr *)bufinfo.buf, bufinfo.len);
RAISE_ERRNO(r, errno);
return mp_const_none;
@@ -169,7 +169,7 @@ STATIC mp_obj_t socket_setsockopt(uint n_args, const mp_obj_t *args) {
optlen = sizeof(val);
} else {
mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(args[3], &bufinfo);
+ mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
optval = bufinfo.buf;
optlen = bufinfo.len;
}