py/stream: Adjust mp_stream_posix_XXX to take void*, not mp_obj_t.
These POSIX wrappers are assumed to be passed a concrete stream object so it is more efficient (eg on nan-boxing builds) to pass in the pointer rather than mp_obj_t, because then the users of these functions only need to store a void* (and mp_obj_t may be wider than a pointer). And things would be further improved if the stream protocol functions eventually took a pointer as their first argument (instead of an mp_obj_t). This patch is a step to getting ussl/axtls compiling on nan-boxing builds. See issue #3085.
This commit is contained in:
parent
ab78fe0eb9
commit
9ab816d676
24
py/stream.c
24
py/stream.c
|
@ -507,10 +507,10 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_ioctl_obj, 2, 3, stream_ioctl);
|
|||
// status, this variable will contain error no.
|
||||
int mp_stream_errno;
|
||||
|
||||
ssize_t mp_stream_posix_write(mp_obj_t stream, const void *buf, size_t len) {
|
||||
mp_obj_base_t* o = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream);
|
||||
ssize_t mp_stream_posix_write(void *stream, const void *buf, size_t len) {
|
||||
mp_obj_base_t* o = stream;
|
||||
const mp_stream_p_t *stream_p = o->type->protocol;
|
||||
mp_uint_t out_sz = stream_p->write(stream, buf, len, &mp_stream_errno);
|
||||
mp_uint_t out_sz = stream_p->write(MP_OBJ_FROM_PTR(stream), buf, len, &mp_stream_errno);
|
||||
if (out_sz == MP_STREAM_ERROR) {
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -518,10 +518,10 @@ ssize_t mp_stream_posix_write(mp_obj_t stream, const void *buf, size_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
ssize_t mp_stream_posix_read(mp_obj_t stream, void *buf, size_t len) {
|
||||
mp_obj_base_t* o = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream);
|
||||
ssize_t mp_stream_posix_read(void *stream, void *buf, size_t len) {
|
||||
mp_obj_base_t* o = stream;
|
||||
const mp_stream_p_t *stream_p = o->type->protocol;
|
||||
mp_uint_t out_sz = stream_p->read(stream, buf, len, &mp_stream_errno);
|
||||
mp_uint_t out_sz = stream_p->read(MP_OBJ_FROM_PTR(stream), buf, len, &mp_stream_errno);
|
||||
if (out_sz == MP_STREAM_ERROR) {
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -529,23 +529,23 @@ ssize_t mp_stream_posix_read(mp_obj_t stream, void *buf, size_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
off_t mp_stream_posix_lseek(mp_obj_t stream, off_t offset, int whence) {
|
||||
const mp_obj_base_t* o = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream);
|
||||
off_t mp_stream_posix_lseek(void *stream, off_t offset, int whence) {
|
||||
const mp_obj_base_t* o = stream;
|
||||
const mp_stream_p_t *stream_p = o->type->protocol;
|
||||
struct mp_stream_seek_t seek_s;
|
||||
seek_s.offset = offset;
|
||||
seek_s.whence = whence;
|
||||
mp_uint_t res = stream_p->ioctl(stream, MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &mp_stream_errno);
|
||||
mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &mp_stream_errno);
|
||||
if (res == MP_STREAM_ERROR) {
|
||||
return -1;
|
||||
}
|
||||
return seek_s.offset;
|
||||
}
|
||||
|
||||
int mp_stream_posix_fsync(mp_obj_t stream) {
|
||||
mp_obj_base_t* o = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream);
|
||||
int mp_stream_posix_fsync(void *stream) {
|
||||
mp_obj_base_t* o = stream;
|
||||
const mp_stream_p_t *stream_p = o->type->protocol;
|
||||
mp_uint_t res = stream_p->ioctl(stream, MP_STREAM_FLUSH, 0, &mp_stream_errno);
|
||||
mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_FLUSH, 0, &mp_stream_errno);
|
||||
if (res == MP_STREAM_ERROR) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -116,10 +116,11 @@ void mp_stream_write_adaptor(void *self, const char *buf, size_t len);
|
|||
|
||||
#if MICROPY_STREAMS_POSIX_API
|
||||
// Functions with POSIX-compatible signatures
|
||||
ssize_t mp_stream_posix_write(mp_obj_t stream, const void *buf, size_t len);
|
||||
ssize_t mp_stream_posix_read(mp_obj_t stream, void *buf, size_t len);
|
||||
off_t mp_stream_posix_lseek(mp_obj_t stream, off_t offset, int whence);
|
||||
int mp_stream_posix_fsync(mp_obj_t stream);
|
||||
// "stream" is assumed to be a pointer to a concrete object with the stream protocol
|
||||
ssize_t mp_stream_posix_write(void *stream, const void *buf, size_t len);
|
||||
ssize_t mp_stream_posix_read(void *stream, void *buf, size_t len);
|
||||
off_t mp_stream_posix_lseek(void *stream, off_t offset, int whence);
|
||||
int mp_stream_posix_fsync(void *stream);
|
||||
#endif
|
||||
|
||||
#if MICROPY_STREAMS_NON_BLOCK
|
||||
|
|
Loading…
Reference in New Issue