Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
cd31d826
Commit
cd31d826
authored
11 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
unix: Use STATIC modifier to enable code size analysis via map file.
parent
6582a417
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
unix/file.c
+12
-12
12 additions, 12 deletions
unix/file.c
unix/main.c
+14
-14
14 additions, 14 deletions
unix/main.c
unix/socket.c
+36
-36
36 additions, 36 deletions
unix/socket.c
unix/time.c
+6
-6
6 additions, 6 deletions
unix/time.c
with
68 additions
and
68 deletions
unix/file.c
+
12
−
12
View file @
cd31d826
...
@@ -17,14 +17,14 @@ typedef struct _mp_obj_fdfile_t {
...
@@ -17,14 +17,14 @@ typedef struct _mp_obj_fdfile_t {
int
fd
;
int
fd
;
}
mp_obj_fdfile_t
;
}
mp_obj_fdfile_t
;
static
const
mp_obj_type_t
rawfile_type
;
STATIC
const
mp_obj_type_t
rawfile_type
;
static
void
fdfile_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
STATIC
void
fdfile_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
mp_obj_fdfile_t
*
self
=
self_in
;
mp_obj_fdfile_t
*
self
=
self_in
;
print
(
env
,
"<io.FileIO %d>"
,
self
->
fd
);
print
(
env
,
"<io.FileIO %d>"
,
self
->
fd
);
}
}
static
machine_int_t
fdfile_read
(
mp_obj_t
o_in
,
void
*
buf
,
machine_uint_t
size
,
int
*
errcode
)
{
STATIC
machine_int_t
fdfile_read
(
mp_obj_t
o_in
,
void
*
buf
,
machine_uint_t
size
,
int
*
errcode
)
{
mp_obj_fdfile_t
*
o
=
o_in
;
mp_obj_fdfile_t
*
o
=
o_in
;
machine_int_t
r
=
read
(
o
->
fd
,
buf
,
size
);
machine_int_t
r
=
read
(
o
->
fd
,
buf
,
size
);
if
(
r
==
-
1
)
{
if
(
r
==
-
1
)
{
...
@@ -33,7 +33,7 @@ static machine_int_t fdfile_read(mp_obj_t o_in, void *buf, machine_uint_t size,
...
@@ -33,7 +33,7 @@ static machine_int_t fdfile_read(mp_obj_t o_in, void *buf, machine_uint_t size,
return
r
;
return
r
;
}
}
static
machine_int_t
fdfile_write
(
mp_obj_t
o_in
,
const
void
*
buf
,
machine_uint_t
size
,
int
*
errcode
)
{
STATIC
machine_int_t
fdfile_write
(
mp_obj_t
o_in
,
const
void
*
buf
,
machine_uint_t
size
,
int
*
errcode
)
{
mp_obj_fdfile_t
*
o
=
o_in
;
mp_obj_fdfile_t
*
o
=
o_in
;
machine_int_t
r
=
write
(
o
->
fd
,
buf
,
size
);
machine_int_t
r
=
write
(
o
->
fd
,
buf
,
size
);
if
(
r
==
-
1
)
{
if
(
r
==
-
1
)
{
...
@@ -42,32 +42,32 @@ static machine_int_t fdfile_write(mp_obj_t o_in, const void *buf, machine_uint_t
...
@@ -42,32 +42,32 @@ static machine_int_t fdfile_write(mp_obj_t o_in, const void *buf, machine_uint_t
return
r
;
return
r
;
}
}
static
mp_obj_t
fdfile_close
(
mp_obj_t
self_in
)
{
STATIC
mp_obj_t
fdfile_close
(
mp_obj_t
self_in
)
{
mp_obj_fdfile_t
*
self
=
self_in
;
mp_obj_fdfile_t
*
self
=
self_in
;
close
(
self
->
fd
);
close
(
self
->
fd
);
return
mp_const_none
;
return
mp_const_none
;
}
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
fdfile_close_obj
,
fdfile_close
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
fdfile_close_obj
,
fdfile_close
);
mp_obj_t
fdfile___exit__
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_t
fdfile___exit__
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
return
fdfile_close
(
args
[
0
]);
return
fdfile_close
(
args
[
0
]);
}
}
static
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
fdfile___exit___obj
,
4
,
4
,
fdfile___exit__
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
fdfile___exit___obj
,
4
,
4
,
fdfile___exit__
);
static
mp_obj_t
fdfile_fileno
(
mp_obj_t
self_in
)
{
STATIC
mp_obj_t
fdfile_fileno
(
mp_obj_t
self_in
)
{
mp_obj_fdfile_t
*
self
=
self_in
;
mp_obj_fdfile_t
*
self
=
self_in
;
return
MP_OBJ_NEW_SMALL_INT
((
machine_int_t
)
self
->
fd
);
return
MP_OBJ_NEW_SMALL_INT
((
machine_int_t
)
self
->
fd
);
}
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
fdfile_fileno_obj
,
fdfile_fileno
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
fdfile_fileno_obj
,
fdfile_fileno
);
static
mp_obj_fdfile_t
*
fdfile_new
(
int
fd
)
{
STATIC
mp_obj_fdfile_t
*
fdfile_new
(
int
fd
)
{
mp_obj_fdfile_t
*
o
=
m_new_obj
(
mp_obj_fdfile_t
);
mp_obj_fdfile_t
*
o
=
m_new_obj
(
mp_obj_fdfile_t
);
o
->
base
.
type
=
&
rawfile_type
;
o
->
base
.
type
=
&
rawfile_type
;
o
->
fd
=
fd
;
o
->
fd
=
fd
;
return
o
;
return
o
;
}
}
static
mp_obj_t
fdfile_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
STATIC
mp_obj_t
fdfile_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
mp_obj_fdfile_t
*
o
=
m_new_obj
(
mp_obj_fdfile_t
);
mp_obj_fdfile_t
*
o
=
m_new_obj
(
mp_obj_fdfile_t
);
o
->
base
.
type
=
type_in
;
o
->
base
.
type
=
type_in
;
...
@@ -123,7 +123,7 @@ STATIC const mp_map_elem_t rawfile_locals_dict_table[] = {
...
@@ -123,7 +123,7 @@ STATIC const mp_map_elem_t rawfile_locals_dict_table[] = {
STATIC
MP_DEFINE_CONST_DICT
(
rawfile_locals_dict
,
rawfile_locals_dict_table
);
STATIC
MP_DEFINE_CONST_DICT
(
rawfile_locals_dict
,
rawfile_locals_dict_table
);
static
const
mp_obj_type_t
rawfile_type
=
{
STATIC
const
mp_obj_type_t
rawfile_type
=
{
{
&
mp_type_type
},
{
&
mp_type_type
},
.
name
=
MP_QSTR_io_dot_FileIO
,
.
name
=
MP_QSTR_io_dot_FileIO
,
.
print
=
fdfile_print
,
.
print
=
fdfile_print
,
...
...
This diff is collapsed.
Click to expand it.
unix/main.c
+
14
−
14
View file @
cd31d826
...
@@ -42,7 +42,7 @@ void microsocket_init();
...
@@ -42,7 +42,7 @@ void microsocket_init();
void
time_init
();
void
time_init
();
void
ffi_init
();
void
ffi_init
();
static
void
execute_from_lexer
(
mp_lexer_t
*
lex
,
mp_parse_input_kind_t
input_kind
,
bool
is_repl
)
{
STATIC
void
execute_from_lexer
(
mp_lexer_t
*
lex
,
mp_parse_input_kind_t
input_kind
,
bool
is_repl
)
{
if
(
lex
==
NULL
)
{
if
(
lex
==
NULL
)
{
return
;
return
;
}
}
...
@@ -94,7 +94,7 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind
...
@@ -94,7 +94,7 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind
}
}
}
}
static
char
*
strjoin
(
const
char
*
s1
,
int
sep_char
,
const
char
*
s2
)
{
STATIC
char
*
strjoin
(
const
char
*
s1
,
int
sep_char
,
const
char
*
s2
)
{
int
l1
=
strlen
(
s1
);
int
l1
=
strlen
(
s1
);
int
l2
=
strlen
(
s2
);
int
l2
=
strlen
(
s2
);
char
*
s
=
malloc
(
l1
+
l2
+
2
);
char
*
s
=
malloc
(
l1
+
l2
+
2
);
...
@@ -108,7 +108,7 @@ static char *strjoin(const char *s1, int sep_char, const char *s2) {
...
@@ -108,7 +108,7 @@ static char *strjoin(const char *s1, int sep_char, const char *s2) {
return
s
;
return
s
;
}
}
static
char
*
prompt
(
char
*
p
)
{
STATIC
char
*
prompt
(
char
*
p
)
{
#if MICROPY_USE_READLINE
#if MICROPY_USE_READLINE
char
*
line
=
readline
(
p
);
char
*
line
=
readline
(
p
);
if
(
line
)
{
if
(
line
)
{
...
@@ -133,7 +133,7 @@ static char *prompt(char *p) {
...
@@ -133,7 +133,7 @@ static char *prompt(char *p) {
return
line
;
return
line
;
}
}
static
void
do_repl
(
void
)
{
STATIC
void
do_repl
(
void
)
{
for
(;;)
{
for
(;;)
{
char
*
line
=
prompt
(
">>> "
);
char
*
line
=
prompt
(
">>> "
);
if
(
line
==
NULL
)
{
if
(
line
==
NULL
)
{
...
@@ -159,12 +159,12 @@ static void do_repl(void) {
...
@@ -159,12 +159,12 @@ static void do_repl(void) {
}
}
}
}
static
void
do_file
(
const
char
*
file
)
{
STATIC
void
do_file
(
const
char
*
file
)
{
mp_lexer_t
*
lex
=
mp_lexer_new_from_file
(
file
);
mp_lexer_t
*
lex
=
mp_lexer_new_from_file
(
file
);
execute_from_lexer
(
lex
,
MP_PARSE_FILE_INPUT
,
false
);
execute_from_lexer
(
lex
,
MP_PARSE_FILE_INPUT
,
false
);
}
}
static
void
do_str
(
const
char
*
str
)
{
STATIC
void
do_str
(
const
char
*
str
)
{
mp_lexer_t
*
lex
=
mp_lexer_new_from_str_len
(
MP_QSTR__lt_stdin_gt_
,
str
,
strlen
(
str
),
false
);
mp_lexer_t
*
lex
=
mp_lexer_new_from_str_len
(
MP_QSTR__lt_stdin_gt_
,
str
,
strlen
(
str
),
false
);
execute_from_lexer
(
lex
,
MP_PARSE_SINGLE_INPUT
,
false
);
execute_from_lexer
(
lex
,
MP_PARSE_SINGLE_INPUT
,
false
);
}
}
...
@@ -174,33 +174,33 @@ typedef struct _test_obj_t {
...
@@ -174,33 +174,33 @@ typedef struct _test_obj_t {
int
value
;
int
value
;
}
test_obj_t
;
}
test_obj_t
;
static
void
test_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
STATIC
void
test_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
test_obj_t
*
self
=
self_in
;
test_obj_t
*
self
=
self_in
;
print
(
env
,
"<test %d>"
,
self
->
value
);
print
(
env
,
"<test %d>"
,
self
->
value
);
}
}
static
mp_obj_t
test_get
(
mp_obj_t
self_in
)
{
STATIC
mp_obj_t
test_get
(
mp_obj_t
self_in
)
{
test_obj_t
*
self
=
self_in
;
test_obj_t
*
self
=
self_in
;
return
mp_obj_new_int
(
self
->
value
);
return
mp_obj_new_int
(
self
->
value
);
}
}
static
mp_obj_t
test_set
(
mp_obj_t
self_in
,
mp_obj_t
arg
)
{
STATIC
mp_obj_t
test_set
(
mp_obj_t
self_in
,
mp_obj_t
arg
)
{
test_obj_t
*
self
=
self_in
;
test_obj_t
*
self
=
self_in
;
self
->
value
=
mp_obj_get_int
(
arg
);
self
->
value
=
mp_obj_get_int
(
arg
);
return
mp_const_none
;
return
mp_const_none
;
}
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
test_get_obj
,
test_get
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
test_get_obj
,
test_get
);
static
MP_DEFINE_CONST_FUN_OBJ_2
(
test_set_obj
,
test_set
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
test_set_obj
,
test_set
);
static
const
mp_map_elem_t
test_locals_dict_table
[]
=
{
STATIC
const
mp_map_elem_t
test_locals_dict_table
[]
=
{
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_get
),
(
mp_obj_t
)
&
test_get_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_get
),
(
mp_obj_t
)
&
test_get_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_set
),
(
mp_obj_t
)
&
test_set_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_set
),
(
mp_obj_t
)
&
test_set_obj
},
};
};
STATIC
MP_DEFINE_CONST_DICT
(
test_locals_dict
,
test_locals_dict_table
);
STATIC
MP_DEFINE_CONST_DICT
(
test_locals_dict
,
test_locals_dict_table
);
static
const
mp_obj_type_t
test_type
=
{
STATIC
const
mp_obj_type_t
test_type
=
{
{
&
mp_type_type
},
{
&
mp_type_type
},
.
name
=
MP_QSTR_Test
,
.
name
=
MP_QSTR_Test
,
.
print
=
test_print
,
.
print
=
test_print
,
...
@@ -249,7 +249,7 @@ mp_obj_t qstr_info(void) {
...
@@ -249,7 +249,7 @@ mp_obj_t qstr_info(void) {
#if MICROPY_ENABLE_GC
#if MICROPY_ENABLE_GC
// TODO: this doesn't belong here
// TODO: this doesn't belong here
static
mp_obj_t
pyb_gc
(
void
)
{
STATIC
mp_obj_t
pyb_gc
(
void
)
{
gc_collect
();
gc_collect
();
return
mp_const_none
;
return
mp_const_none
;
}
}
...
...
This diff is collapsed.
Click to expand it.
unix/socket.c
+
36
−
36
View file @
cd31d826
...
@@ -27,14 +27,14 @@ typedef struct _mp_obj_socket_t {
...
@@ -27,14 +27,14 @@ typedef struct _mp_obj_socket_t {
int
fd
;
int
fd
;
}
mp_obj_socket_t
;
}
mp_obj_socket_t
;
static
const
mp_obj_type_t
microsocket_type
;
STATIC
const
mp_obj_type_t
microsocket_type
;
// Helper functions
// Helper functions
#define RAISE_ERRNO(err_flag, error_val) \
#define RAISE_ERRNO(err_flag, error_val) \
{ if (err_flag == -1) \
{ if (err_flag == -1) \
{ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error_val)); } }
{ nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", error_val)); } }
static
void
get_buffer
(
mp_obj_t
obj
,
buffer_info_t
*
bufinfo
)
{
STATIC
void
get_buffer
(
mp_obj_t
obj
,
buffer_info_t
*
bufinfo
)
{
mp_obj_base_t
*
o
=
(
mp_obj_base_t
*
)
obj
;
mp_obj_base_t
*
o
=
(
mp_obj_base_t
*
)
obj
;
if
(
o
->
type
->
buffer_p
.
get_buffer
==
NULL
)
{
if
(
o
->
type
->
buffer_p
.
get_buffer
==
NULL
)
{
goto
error
;
goto
error
;
...
@@ -49,7 +49,7 @@ error:
...
@@ -49,7 +49,7 @@ error:
nlr_jump
(
mp_obj_new_exception_msg
(
&
mp_type_TypeError
,
"Operation not supported"
));
nlr_jump
(
mp_obj_new_exception_msg
(
&
mp_type_TypeError
,
"Operation not supported"
));
}
}
static
mp_obj_socket_t
*
socket_new
(
int
fd
)
{
STATIC
mp_obj_socket_t
*
socket_new
(
int
fd
)
{
mp_obj_socket_t
*
o
=
m_new_obj
(
mp_obj_socket_t
);
mp_obj_socket_t
*
o
=
m_new_obj
(
mp_obj_socket_t
);
o
->
base
.
type
=
&
microsocket_type
;
o
->
base
.
type
=
&
microsocket_type
;
o
->
fd
=
fd
;
o
->
fd
=
fd
;
...
@@ -57,12 +57,12 @@ static mp_obj_socket_t *socket_new(int fd) {
...
@@ -57,12 +57,12 @@ static mp_obj_socket_t *socket_new(int fd) {
}
}
static
void
socket_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
STATIC
void
socket_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
mp_obj_socket_t
*
self
=
self_in
;
mp_obj_socket_t
*
self
=
self_in
;
print
(
env
,
"<_socket %d>"
,
self
->
fd
);
print
(
env
,
"<_socket %d>"
,
self
->
fd
);
}
}
static
machine_int_t
socket_read
(
mp_obj_t
o_in
,
void
*
buf
,
machine_uint_t
size
,
int
*
errcode
)
{
STATIC
machine_int_t
socket_read
(
mp_obj_t
o_in
,
void
*
buf
,
machine_uint_t
size
,
int
*
errcode
)
{
mp_obj_socket_t
*
o
=
o_in
;
mp_obj_socket_t
*
o
=
o_in
;
machine_int_t
r
=
read
(
o
->
fd
,
buf
,
size
);
machine_int_t
r
=
read
(
o
->
fd
,
buf
,
size
);
if
(
r
==
-
1
)
{
if
(
r
==
-
1
)
{
...
@@ -71,7 +71,7 @@ static machine_int_t socket_read(mp_obj_t o_in, void *buf, machine_uint_t size,
...
@@ -71,7 +71,7 @@ static machine_int_t socket_read(mp_obj_t o_in, void *buf, machine_uint_t size,
return
r
;
return
r
;
}
}
static
machine_int_t
socket_write
(
mp_obj_t
o_in
,
const
void
*
buf
,
machine_uint_t
size
,
int
*
errcode
)
{
STATIC
machine_int_t
socket_write
(
mp_obj_t
o_in
,
const
void
*
buf
,
machine_uint_t
size
,
int
*
errcode
)
{
mp_obj_socket_t
*
o
=
o_in
;
mp_obj_socket_t
*
o
=
o_in
;
machine_int_t
r
=
write
(
o
->
fd
,
buf
,
size
);
machine_int_t
r
=
write
(
o
->
fd
,
buf
,
size
);
if
(
r
==
-
1
)
{
if
(
r
==
-
1
)
{
...
@@ -80,20 +80,20 @@ static machine_int_t socket_write(mp_obj_t o_in, const void *buf, machine_uint_t
...
@@ -80,20 +80,20 @@ static machine_int_t socket_write(mp_obj_t o_in, const void *buf, machine_uint_t
return
r
;
return
r
;
}
}
static
mp_obj_t
socket_close
(
mp_obj_t
self_in
)
{
STATIC
mp_obj_t
socket_close
(
mp_obj_t
self_in
)
{
mp_obj_socket_t
*
self
=
self_in
;
mp_obj_socket_t
*
self
=
self_in
;
close
(
self
->
fd
);
close
(
self
->
fd
);
return
mp_const_none
;
return
mp_const_none
;
}
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
socket_close_obj
,
socket_close
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
socket_close_obj
,
socket_close
);
static
mp_obj_t
socket_fileno
(
mp_obj_t
self_in
)
{
STATIC
mp_obj_t
socket_fileno
(
mp_obj_t
self_in
)
{
mp_obj_socket_t
*
self
=
self_in
;
mp_obj_socket_t
*
self
=
self_in
;
return
MP_OBJ_NEW_SMALL_INT
((
machine_int_t
)
self
->
fd
);
return
MP_OBJ_NEW_SMALL_INT
((
machine_int_t
)
self
->
fd
);
}
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
socket_fileno_obj
,
socket_fileno
);
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
)
{
STATIC
mp_obj_t
socket_connect
(
mp_obj_t
self_in
,
mp_obj_t
addr_in
)
{
mp_obj_socket_t
*
self
=
self_in
;
mp_obj_socket_t
*
self
=
self_in
;
buffer_info_t
bufinfo
;
buffer_info_t
bufinfo
;
get_buffer
(
addr_in
,
&
bufinfo
);
get_buffer
(
addr_in
,
&
bufinfo
);
...
@@ -101,9 +101,9 @@ static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
...
@@ -101,9 +101,9 @@ static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
RAISE_ERRNO
(
r
,
errno
);
RAISE_ERRNO
(
r
,
errno
);
return
mp_const_none
;
return
mp_const_none
;
}
}
static
MP_DEFINE_CONST_FUN_OBJ_2
(
socket_connect_obj
,
socket_connect
);
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
)
{
STATIC
mp_obj_t
socket_bind
(
mp_obj_t
self_in
,
mp_obj_t
addr_in
)
{
mp_obj_socket_t
*
self
=
self_in
;
mp_obj_socket_t
*
self
=
self_in
;
buffer_info_t
bufinfo
;
buffer_info_t
bufinfo
;
get_buffer
(
addr_in
,
&
bufinfo
);
get_buffer
(
addr_in
,
&
bufinfo
);
...
@@ -111,17 +111,17 @@ static mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
...
@@ -111,17 +111,17 @@ static mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
RAISE_ERRNO
(
r
,
errno
);
RAISE_ERRNO
(
r
,
errno
);
return
mp_const_none
;
return
mp_const_none
;
}
}
static
MP_DEFINE_CONST_FUN_OBJ_2
(
socket_bind_obj
,
socket_bind
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
socket_bind_obj
,
socket_bind
);
static
mp_obj_t
socket_listen
(
mp_obj_t
self_in
,
mp_obj_t
backlog_in
)
{
STATIC
mp_obj_t
socket_listen
(
mp_obj_t
self_in
,
mp_obj_t
backlog_in
)
{
mp_obj_socket_t
*
self
=
self_in
;
mp_obj_socket_t
*
self
=
self_in
;
int
r
=
listen
(
self
->
fd
,
MP_OBJ_SMALL_INT_VALUE
(
backlog_in
));
int
r
=
listen
(
self
->
fd
,
MP_OBJ_SMALL_INT_VALUE
(
backlog_in
));
RAISE_ERRNO
(
r
,
errno
);
RAISE_ERRNO
(
r
,
errno
);
return
mp_const_none
;
return
mp_const_none
;
}
}
static
MP_DEFINE_CONST_FUN_OBJ_2
(
socket_listen_obj
,
socket_listen
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
socket_listen_obj
,
socket_listen
);
static
mp_obj_t
socket_accept
(
mp_obj_t
self_in
)
{
STATIC
mp_obj_t
socket_accept
(
mp_obj_t
self_in
)
{
mp_obj_socket_t
*
self
=
self_in
;
mp_obj_socket_t
*
self
=
self_in
;
struct
sockaddr
addr
;
struct
sockaddr
addr
;
socklen_t
addr_len
=
sizeof
(
addr
);
socklen_t
addr_len
=
sizeof
(
addr
);
...
@@ -134,9 +134,9 @@ static mp_obj_t socket_accept(mp_obj_t self_in) {
...
@@ -134,9 +134,9 @@ static mp_obj_t socket_accept(mp_obj_t self_in) {
return
t
;
return
t
;
}
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
socket_accept_obj
,
socket_accept
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
socket_accept_obj
,
socket_accept
);
static
mp_obj_t
socket_recv
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
STATIC
mp_obj_t
socket_recv
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_socket_t
*
self
=
args
[
0
];
mp_obj_socket_t
*
self
=
args
[
0
];
int
sz
=
MP_OBJ_SMALL_INT_VALUE
(
args
[
1
]);
int
sz
=
MP_OBJ_SMALL_INT_VALUE
(
args
[
1
]);
int
flags
=
0
;
int
flags
=
0
;
...
@@ -152,9 +152,9 @@ static mp_obj_t socket_recv(uint n_args, const mp_obj_t *args) {
...
@@ -152,9 +152,9 @@ static mp_obj_t socket_recv(uint n_args, const mp_obj_t *args) {
buf
=
m_realloc
(
buf
,
sz
,
out_sz
);
buf
=
m_realloc
(
buf
,
sz
,
out_sz
);
return
MP_OBJ_NEW_QSTR
(
qstr_from_strn_take
(
buf
,
out_sz
,
out_sz
));
return
MP_OBJ_NEW_QSTR
(
qstr_from_strn_take
(
buf
,
out_sz
,
out_sz
));
}
}
static
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
socket_recv_obj
,
2
,
3
,
socket_recv
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
socket_recv_obj
,
2
,
3
,
socket_recv
);
static
mp_obj_t
socket_send
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
STATIC
mp_obj_t
socket_send
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_socket_t
*
self
=
args
[
0
];
mp_obj_socket_t
*
self
=
args
[
0
];
int
flags
=
0
;
int
flags
=
0
;
...
@@ -169,9 +169,9 @@ static mp_obj_t socket_send(uint n_args, const mp_obj_t *args) {
...
@@ -169,9 +169,9 @@ static mp_obj_t socket_send(uint n_args, const mp_obj_t *args) {
return
MP_OBJ_NEW_SMALL_INT
((
machine_int_t
)
out_sz
);
return
MP_OBJ_NEW_SMALL_INT
((
machine_int_t
)
out_sz
);
}
}
static
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
socket_send_obj
,
2
,
3
,
socket_send
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
socket_send_obj
,
2
,
3
,
socket_send
);
static
mp_obj_t
socket_setsockopt
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
STATIC
mp_obj_t
socket_setsockopt
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_socket_t
*
self
=
args
[
0
];
mp_obj_socket_t
*
self
=
args
[
0
];
int
level
=
MP_OBJ_SMALL_INT_VALUE
(
args
[
1
]);
int
level
=
MP_OBJ_SMALL_INT_VALUE
(
args
[
1
]);
int
option
=
mp_obj_get_int
(
args
[
2
]);
int
option
=
mp_obj_get_int
(
args
[
2
]);
...
@@ -192,9 +192,9 @@ static mp_obj_t socket_setsockopt(uint n_args, const mp_obj_t *args) {
...
@@ -192,9 +192,9 @@ static mp_obj_t socket_setsockopt(uint n_args, const mp_obj_t *args) {
RAISE_ERRNO
(
r
,
errno
);
RAISE_ERRNO
(
r
,
errno
);
return
mp_const_none
;
return
mp_const_none
;
}
}
static
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
socket_setsockopt_obj
,
4
,
4
,
socket_setsockopt
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
socket_setsockopt_obj
,
4
,
4
,
socket_setsockopt
);
static
mp_obj_t
socket_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
STATIC
mp_obj_t
socket_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
int
family
=
AF_INET
;
int
family
=
AF_INET
;
int
type
=
SOCK_STREAM
;
int
type
=
SOCK_STREAM
;
int
proto
=
0
;
int
proto
=
0
;
...
@@ -217,7 +217,7 @@ static mp_obj_t socket_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
...
@@ -217,7 +217,7 @@ static mp_obj_t socket_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
return
socket_new
(
fd
);
return
socket_new
(
fd
);
}
}
static
const
mp_map_elem_t
microsocket_locals_dict_table
[]
=
{
STATIC
const
mp_map_elem_t
microsocket_locals_dict_table
[]
=
{
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_fileno
),
(
mp_obj_t
)
&
socket_fileno_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_fileno
),
(
mp_obj_t
)
&
socket_fileno_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_makefile
),
(
mp_obj_t
)
&
mp_identity_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_makefile
),
(
mp_obj_t
)
&
mp_identity_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_read
),
(
mp_obj_t
)
&
mp_stream_read_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_read
),
(
mp_obj_t
)
&
mp_stream_read_obj
},
...
@@ -240,7 +240,7 @@ static const mp_map_elem_t microsocket_locals_dict_table[] = {
...
@@ -240,7 +240,7 @@ static const mp_map_elem_t microsocket_locals_dict_table[] = {
STATIC
MP_DEFINE_CONST_DICT
(
microsocket_locals_dict
,
microsocket_locals_dict_table
);
STATIC
MP_DEFINE_CONST_DICT
(
microsocket_locals_dict
,
microsocket_locals_dict_table
);
static
const
mp_obj_type_t
microsocket_type
=
{
STATIC
const
mp_obj_type_t
microsocket_type
=
{
{
&
mp_type_type
},
{
&
mp_type_type
},
.
name
=
MP_QSTR_socket
,
.
name
=
MP_QSTR_socket
,
.
print
=
socket_print
,
.
print
=
socket_print
,
...
@@ -254,12 +254,12 @@ static const mp_obj_type_t microsocket_type = {
...
@@ -254,12 +254,12 @@ static const mp_obj_type_t microsocket_type = {
.
locals_dict
=
(
mp_obj_t
)
&
microsocket_locals_dict
,
.
locals_dict
=
(
mp_obj_t
)
&
microsocket_locals_dict
,
};
};
static
mp_obj_t
mod_socket_htons
(
mp_obj_t
arg
)
{
STATIC
mp_obj_t
mod_socket_htons
(
mp_obj_t
arg
)
{
return
MP_OBJ_NEW_SMALL_INT
((
machine_int_t
)
htons
(
MP_OBJ_SMALL_INT_VALUE
(
arg
)));
return
MP_OBJ_NEW_SMALL_INT
((
machine_int_t
)
htons
(
MP_OBJ_SMALL_INT_VALUE
(
arg
)));
}
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
mod_socket_htons_obj
,
mod_socket_htons
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
mod_socket_htons_obj
,
mod_socket_htons
);
static
mp_obj_t
mod_socket_inet_aton
(
mp_obj_t
arg
)
{
STATIC
mp_obj_t
mod_socket_inet_aton
(
mp_obj_t
arg
)
{
assert
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_str
));
assert
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_str
));
const
char
*
s
=
mp_obj_str_get_str
(
arg
);
const
char
*
s
=
mp_obj_str_get_str
(
arg
);
struct
in_addr
addr
;
struct
in_addr
addr
;
...
@@ -269,10 +269,10 @@ static mp_obj_t mod_socket_inet_aton(mp_obj_t arg) {
...
@@ -269,10 +269,10 @@ static mp_obj_t mod_socket_inet_aton(mp_obj_t arg) {
return
mp_obj_new_int
(
addr
.
s_addr
);
return
mp_obj_new_int
(
addr
.
s_addr
);
}
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
mod_socket_inet_aton_obj
,
mod_socket_inet_aton
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
mod_socket_inet_aton_obj
,
mod_socket_inet_aton
);
#if MICROPY_SOCKET_EXTRA
#if MICROPY_SOCKET_EXTRA
static
mp_obj_t
mod_socket_gethostbyname
(
mp_obj_t
arg
)
{
STATIC
mp_obj_t
mod_socket_gethostbyname
(
mp_obj_t
arg
)
{
assert
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_str
));
assert
(
MP_OBJ_IS_TYPE
(
arg
,
&
mp_type_str
));
const
char
*
s
=
mp_obj_str_get_str
(
arg
);
const
char
*
s
=
mp_obj_str_get_str
(
arg
);
struct
hostent
*
h
=
gethostbyname
(
s
);
struct
hostent
*
h
=
gethostbyname
(
s
);
...
@@ -282,10 +282,10 @@ static mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) {
...
@@ -282,10 +282,10 @@ static mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) {
assert
(
h
->
h_length
==
4
);
assert
(
h
->
h_length
==
4
);
return
mp_obj_new_int
(
*
(
int
*
)
*
h
->
h_addr_list
);
return
mp_obj_new_int
(
*
(
int
*
)
*
h
->
h_addr_list
);
}
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
mod_socket_gethostbyname_obj
,
mod_socket_gethostbyname
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
mod_socket_gethostbyname_obj
,
mod_socket_gethostbyname
);
#endif
#endif
static
mp_obj_t
mod_socket_getaddrinfo
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
STATIC
mp_obj_t
mod_socket_getaddrinfo
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
// TODO: Implement all args
// TODO: Implement all args
assert
(
n_args
==
2
);
assert
(
n_args
==
2
);
assert
(
MP_OBJ_IS_STR
(
args
[
0
]));
assert
(
MP_OBJ_IS_STR
(
args
[
0
]));
...
@@ -331,13 +331,13 @@ static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
...
@@ -331,13 +331,13 @@ static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
}
}
return
list
;
return
list
;
}
}
static
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mod_socket_getaddrinfo_obj
,
2
,
6
,
mod_socket_getaddrinfo
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mod_socket_getaddrinfo_obj
,
2
,
6
,
mod_socket_getaddrinfo
);
extern
mp_obj_type_t
sockaddr_in_type
;
extern
mp_obj_type_t
sockaddr_in_type
;
#define C(name) { #name, name }
#define C(name) { #name, name }
static
const
struct
sym_entry
{
STATIC
const
struct
sym_entry
{
const
char
*
sym
;
const
char
*
sym
;
int
val
;
int
val
;
}
constants
[]
=
{
}
constants
[]
=
{
...
...
This diff is collapsed.
Click to expand it.
unix/time.c
+
6
−
6
View file @
cd31d826
...
@@ -10,13 +10,13 @@
...
@@ -10,13 +10,13 @@
#include
"obj.h"
#include
"obj.h"
#include
"runtime.h"
#include
"runtime.h"
static
mp_obj_t
mod_time_time
()
{
STATIC
mp_obj_t
mod_time_time
()
{
return
mp_obj_new_int
((
machine_int_t
)
time
(
NULL
));
return
mp_obj_new_int
((
machine_int_t
)
time
(
NULL
));
}
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
mod_time_time_obj
,
mod_time_time
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
mod_time_time_obj
,
mod_time_time
);
// Note: this is deprecated since CPy3.3, but pystone still uses it.
// Note: this is deprecated since CPy3.3, but pystone still uses it.
static
mp_obj_t
mod_time_clock
()
{
STATIC
mp_obj_t
mod_time_clock
()
{
// return mp_obj_new_int((machine_int_t)clock());
// return mp_obj_new_int((machine_int_t)clock());
// POSIX requires CLOCKS_PER_SEC equals 1000000, so that's what we assume
// POSIX requires CLOCKS_PER_SEC equals 1000000, so that's what we assume
// float cannot represent full range of int32 precisely, so we pre-divide
// float cannot represent full range of int32 precisely, so we pre-divide
...
@@ -24,9 +24,9 @@ static mp_obj_t mod_time_clock() {
...
@@ -24,9 +24,9 @@ static mp_obj_t mod_time_clock() {
// to preserve integer part resolution.
// to preserve integer part resolution.
return
mp_obj_new_float
((
float
)(
clock
()
/
1000
)
/
1000
.
0
);
return
mp_obj_new_float
((
float
)(
clock
()
/
1000
)
/
1000
.
0
);
}
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
mod_time_clock_obj
,
mod_time_clock
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_0
(
mod_time_clock_obj
,
mod_time_clock
);
static
mp_obj_t
mod_time_sleep
(
mp_obj_t
arg
)
{
STATIC
mp_obj_t
mod_time_sleep
(
mp_obj_t
arg
)
{
#if MICROPY_ENABLE_FLOAT
#if MICROPY_ENABLE_FLOAT
struct
timeval
tv
;
struct
timeval
tv
;
mp_float_t
val
=
mp_obj_get_float
(
arg
);
mp_float_t
val
=
mp_obj_get_float
(
arg
);
...
@@ -39,7 +39,7 @@ static mp_obj_t mod_time_sleep(mp_obj_t arg) {
...
@@ -39,7 +39,7 @@ static mp_obj_t mod_time_sleep(mp_obj_t arg) {
#endif
#endif
return
mp_const_none
;
return
mp_const_none
;
}
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
mod_time_sleep_obj
,
mod_time_sleep
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
mod_time_sleep_obj
,
mod_time_sleep
);
void
time_init
()
{
void
time_init
()
{
mp_obj_t
m
=
mp_obj_new_module
(
QSTR_FROM_STR_STATIC
(
"time"
));
mp_obj_t
m
=
mp_obj_new_module
(
QSTR_FROM_STR_STATIC
(
"time"
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment