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
a2bfcbe0
Commit
a2bfcbe0
authored
Oct 07, 2016
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stmhal: Use mp_raise_OSError helper function.
parent
e3d29996
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
25 deletions
+26
-25
stmhal/moduos.c
stmhal/moduos.c
+4
-4
stmhal/moduselect.c
stmhal/moduselect.c
+3
-3
stmhal/modusocket.c
stmhal/modusocket.c
+17
-17
stmhal/mphalport.c
stmhal/mphalport.c
+2
-1
No files found.
stmhal/moduos.c
View file @
a2bfcbe0
...
...
@@ -28,6 +28,7 @@
#include <string.h>
#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/objtuple.h"
#include "py/objstr.h"
#include "genhdr/mpversion.h"
...
...
@@ -107,7 +108,7 @@ STATIC mp_obj_t os_getcwd(void) {
FRESULT
res
=
f_getcwd
(
buf
,
sizeof
buf
);
if
(
res
!=
FR_OK
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
fresult_to_errno_table
[
res
]))
);
mp_raise_OSError
(
fresult_to_errno_table
[
res
]
);
}
return
mp_obj_new_str
(
buf
,
strlen
(
buf
),
false
);
...
...
@@ -258,8 +259,7 @@ STATIC mp_obj_t os_stat(mp_obj_t path_in) {
res
=
f_stat
(
path
,
&
fno
);
}
if
(
res
!=
FR_OK
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
fresult_to_errno_table
[
res
])));
mp_raise_OSError
(
fresult_to_errno_table
[
res
]);
}
}
...
...
@@ -319,7 +319,7 @@ STATIC mp_obj_t os_statvfs(mp_obj_t path_in) {
return
t
;
error:
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
fresult_to_errno_table
[
res
]))
);
mp_raise_OSError
(
fresult_to_errno_table
[
res
]
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
os_statvfs_obj
,
os_statvfs
);
...
...
stmhal/moduselect.c
View file @
a2bfcbe0
...
...
@@ -26,7 +26,7 @@
#include <stdio.h>
#include "py/
nlr
.h"
#include "py/
runtime
.h"
#include "py/obj.h"
#include "py/objlist.h"
#include "py/mperrno.h"
...
...
@@ -89,7 +89,7 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, mp_uint_t *rwx_num) {
if
(
ret
==
-
1
)
{
// error doing ioctl
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
errcode
))
);
mp_raise_OSError
(
errcode
);
}
if
(
ret
!=
0
)
{
...
...
@@ -213,7 +213,7 @@ STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmas
mp_obj_poll_t
*
self
=
self_in
;
mp_map_elem_t
*
elem
=
mp_map_lookup
(
&
self
->
poll_map
,
mp_obj_id
(
obj_in
),
MP_MAP_LOOKUP
);
if
(
elem
==
NULL
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_ENOENT
))
);
mp_raise_OSError
(
MP_ENOENT
);
}
((
poll_obj_t
*
)
elem
->
value
)
->
flags
=
mp_obj_get_int
(
eventmask_in
);
return
mp_const_none
;
...
...
stmhal/modusocket.c
View file @
a2bfcbe0
...
...
@@ -76,7 +76,7 @@ STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) {
// call the NIC to open the socket
int
_errno
;
if
(
self
->
nic_type
->
socket
(
self
,
&
_errno
)
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
}
}
...
...
@@ -105,7 +105,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
// call the NIC to bind the socket
int
_errno
;
if
(
self
->
nic_type
->
bind
(
self
,
ip
,
port
,
&
_errno
)
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
return
mp_const_none
;
...
...
@@ -119,12 +119,12 @@ STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
if
(
self
->
nic
==
MP_OBJ_NULL
)
{
// not connected
// TODO I think we can listen even if not bound...
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_ENOTCONN
))
);
mp_raise_OSError
(
MP_ENOTCONN
);
}
int
_errno
;
if
(
self
->
nic_type
->
listen
(
self
,
mp_obj_get_int
(
backlog
),
&
_errno
)
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
return
mp_const_none
;
...
...
@@ -147,7 +147,7 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
mp_uint_t
port
;
int
_errno
;
if
(
self
->
nic_type
->
accept
(
self
,
socket2
,
ip
,
&
port
,
&
_errno
)
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
// new socket has valid state, so set the NIC to the same as parent
...
...
@@ -177,7 +177,7 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
// call the NIC to connect the socket
int
_errno
;
if
(
self
->
nic_type
->
connect
(
self
,
ip
,
port
,
&
_errno
)
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
return
mp_const_none
;
...
...
@@ -189,14 +189,14 @@ STATIC mp_obj_t socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
mod_network_socket_obj_t
*
self
=
self_in
;
if
(
self
->
nic
==
MP_OBJ_NULL
)
{
// not connected
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_EPIPE
))
);
mp_raise_OSError
(
MP_EPIPE
);
}
mp_buffer_info_t
bufinfo
;
mp_get_buffer_raise
(
buf_in
,
&
bufinfo
,
MP_BUFFER_READ
);
int
_errno
;
mp_uint_t
ret
=
self
->
nic_type
->
send
(
self
,
bufinfo
.
buf
,
bufinfo
.
len
,
&
_errno
);
if
(
ret
==
-
1
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
return
mp_obj_new_int_from_uint
(
ret
);
}
...
...
@@ -207,7 +207,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
mod_network_socket_obj_t
*
self
=
self_in
;
if
(
self
->
nic
==
MP_OBJ_NULL
)
{
// not connected
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_ENOTCONN
))
);
mp_raise_OSError
(
MP_ENOTCONN
);
}
mp_int_t
len
=
mp_obj_get_int
(
len_in
);
vstr_t
vstr
;
...
...
@@ -215,7 +215,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
int
_errno
;
mp_uint_t
ret
=
self
->
nic_type
->
recv
(
self
,
(
byte
*
)
vstr
.
buf
,
len
,
&
_errno
);
if
(
ret
==
-
1
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
if
(
ret
==
0
)
{
return
mp_const_empty_bytes
;
...
...
@@ -244,7 +244,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
int
_errno
;
mp_int_t
ret
=
self
->
nic_type
->
sendto
(
self
,
bufinfo
.
buf
,
bufinfo
.
len
,
ip
,
port
,
&
_errno
);
if
(
ret
==
-
1
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
return
mp_obj_new_int
(
ret
);
...
...
@@ -256,7 +256,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
mod_network_socket_obj_t
*
self
=
self_in
;
if
(
self
->
nic
==
MP_OBJ_NULL
)
{
// not connected
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_ENOTCONN
))
);
mp_raise_OSError
(
MP_ENOTCONN
);
}
vstr_t
vstr
;
vstr_init_len
(
&
vstr
,
mp_obj_get_int
(
len_in
));
...
...
@@ -265,7 +265,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
int
_errno
;
mp_int_t
ret
=
self
->
nic_type
->
recvfrom
(
self
,
(
byte
*
)
vstr
.
buf
,
vstr
.
len
,
ip
,
&
port
,
&
_errno
);
if
(
ret
==
-
1
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
mp_obj_t
tuple
[
2
];
if
(
ret
==
0
)
{
...
...
@@ -302,7 +302,7 @@ STATIC mp_obj_t socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
int
_errno
;
if
(
self
->
nic_type
->
setsockopt
(
self
,
level
,
opt
,
optval
,
optlen
,
&
_errno
)
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
return
mp_const_none
;
...
...
@@ -317,7 +317,7 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
mod_network_socket_obj_t
*
self
=
self_in
;
if
(
self
->
nic
==
MP_OBJ_NULL
)
{
// not connected
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
MP_ENOTCONN
))
);
mp_raise_OSError
(
MP_ENOTCONN
);
}
mp_uint_t
timeout
;
if
(
timeout_in
==
mp_const_none
)
{
...
...
@@ -331,7 +331,7 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
}
int
_errno
;
if
(
self
->
nic_type
->
settimeout
(
self
,
timeout
,
&
_errno
)
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
_errno
))
);
mp_raise_OSError
(
_errno
);
}
return
mp_const_none
;
}
...
...
@@ -401,7 +401,7 @@ STATIC mp_obj_t mod_usocket_getaddrinfo(mp_obj_t host_in, mp_obj_t port_in) {
int
ret
=
nic_type
->
gethostbyname
(
nic
,
host
,
hlen
,
out_ip
);
if
(
ret
!=
0
)
{
// TODO CPython raises: socket.gaierror: [Errno -2] Name or service not known
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
ret
))
);
mp_raise_OSError
(
ret
);
}
mp_obj_tuple_t
*
tuple
=
mp_obj_new_tuple
(
5
,
NULL
);
tuple
->
items
[
0
]
=
MP_OBJ_NEW_SMALL_INT
(
MOD_NETWORK_AF_INET
);
...
...
stmhal/mphalport.c
View file @
a2bfcbe0
#include <string.h>
#include "py/mpstate.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "py/mphal.h"
#include "usb.h"
...
...
@@ -15,7 +16,7 @@ const byte mp_hal_status_to_errno_table[4] = {
};
NORETURN
void
mp_hal_raise
(
HAL_StatusTypeDef
status
)
{
nlr_raise
(
mp_obj_new_exception_arg1
(
&
mp_type_OSError
,
MP_OBJ_NEW_SMALL_INT
(
mp_hal_status_to_errno_table
[
status
]))
);
mp_raise_OSError
(
mp_hal_status_to_errno_table
[
status
]
);
}
void
mp_hal_set_interrupt_char
(
int
c
)
{
...
...
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