-
Notifications
You must be signed in to change notification settings - Fork 440
Add several options to the nuttx target in precommit.py #1207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
diff --git a/src/iotjs_util.c b/src/iotjs_util.c | ||
index 62ca214..dd6a978 100644 | ||
--- a/src/iotjs_util.c | ||
+++ b/src/iotjs_util.c | ||
@@ -58,8 +58,18 @@ iotjs_string_t iotjs_file_read(const char* path) { | ||
} | ||
|
||
|
||
+#define SIZEOF_MM_ALLOCNODE 8 | ||
+extern void jmem_heap_stat_alloc(size_t size); | ||
+extern void jmem_heap_stat_free(size_t size); | ||
+ | ||
+ | ||
char* iotjs_buffer_allocate(size_t size) { | ||
char* buffer = (char*)(calloc(size, sizeof(char))); | ||
+ | ||
+ size_t new_size; | ||
+ memcpy(&new_size, (buffer - SIZEOF_MM_ALLOCNODE), sizeof(size_t)); | ||
+ jmem_heap_stat_alloc(new_size - SIZEOF_MM_ALLOCNODE); | ||
+ | ||
IOTJS_ASSERT(buffer != NULL); | ||
return buffer; | ||
} | ||
@@ -67,11 +77,26 @@ char* iotjs_buffer_allocate(size_t size) { | ||
|
||
char* iotjs_buffer_reallocate(char* buffer, size_t size) { | ||
IOTJS_ASSERT(buffer != NULL); | ||
- return (char*)(realloc(buffer, size)); | ||
+ | ||
+ size_t old_size; | ||
+ memcpy(&old_size, (buffer - SIZEOF_MM_ALLOCNODE), sizeof(size_t)); | ||
+ jmem_heap_stat_free(old_size - SIZEOF_MM_ALLOCNODE); | ||
+ | ||
+ char* ptr = (char*)(realloc(buffer, size)); | ||
+ | ||
+ size_t new_size; | ||
+ memcpy(&new_size, (ptr - SIZEOF_MM_ALLOCNODE), sizeof(size_t)); | ||
+ jmem_heap_stat_alloc(new_size - SIZEOF_MM_ALLOCNODE); | ||
+ | ||
+ return ptr; | ||
} | ||
|
||
|
||
void iotjs_buffer_release(char* buffer) { | ||
+ size_t size; | ||
+ memcpy(&size, (buffer - SIZEOF_MM_ALLOCNODE), sizeof(size_t)); | ||
+ jmem_heap_stat_free(size - SIZEOF_MM_ALLOCNODE); | ||
+ | ||
IOTJS_ASSERT(buffer != NULL); | ||
free(buffer); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
diff --git a/jerry-core/api/jerry.c b/jerry-core/api/jerry.c | ||
index 1032881..88db6a3 100644 | ||
--- a/jerry-core/api/jerry.c | ||
+++ b/jerry-core/api/jerry.c | ||
@@ -149,7 +149,7 @@ jerry_init (jerry_init_flag_t flags) /**< combination of Jerry flags */ | ||
} | ||
|
||
/* Zero out all members. */ | ||
- memset (&JERRY_CONTEXT (JERRY_CONTEXT_FIRST_MEMBER), 0, sizeof (jerry_context_t)); | ||
+ // memset (&JERRY_CONTEXT (JERRY_CONTEXT_FIRST_MEMBER), 0, sizeof (jerry_context_t)); | ||
|
||
JERRY_CONTEXT (jerry_init_flags) = flags; | ||
|
||
diff --git a/jerry-core/jmem/jmem-heap.c b/jerry-core/jmem/jmem-heap.c | ||
index f15ba90..8154880 100644 | ||
--- a/jerry-core/jmem/jmem-heap.c | ||
+++ b/jerry-core/jmem/jmem-heap.c | ||
@@ -113,8 +113,8 @@ JERRY_STATIC_ASSERT (sizeof (jmem_heap_t) <= JMEM_HEAP_SIZE, | ||
|
||
#ifdef JMEM_STATS | ||
static void jmem_heap_stat_init (void); | ||
-static void jmem_heap_stat_alloc (size_t num); | ||
-static void jmem_heap_stat_free (size_t num); | ||
+void jmem_heap_stat_alloc (size_t num); | ||
+void jmem_heap_stat_free (size_t num); | ||
|
||
#ifndef JERRY_SYSTEM_ALLOCATOR | ||
static void jmem_heap_stat_skip (void); | ||
@@ -580,7 +580,7 @@ jmem_heap_stats_print (void) | ||
{ | ||
jmem_heap_stats_t *heap_stats = &JERRY_CONTEXT (jmem_heap_stats); | ||
|
||
- JERRY_DEBUG_MSG ("Heap stats:\n" | ||
+ printf ("Heap stats:\n" | ||
" Heap size = %zu bytes\n" | ||
" Allocated = %zu bytes\n" | ||
" Peak allocated = %zu bytes\n" | ||
@@ -632,7 +632,7 @@ jmem_heap_stat_init (void) | ||
/** | ||
* Account allocation | ||
*/ | ||
-static void | ||
+void | ||
jmem_heap_stat_alloc (size_t size) /**< Size of allocated block */ | ||
{ | ||
const size_t aligned_size = (size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT * JMEM_ALIGNMENT; | ||
@@ -658,7 +658,7 @@ jmem_heap_stat_alloc (size_t size) /**< Size of allocated block */ | ||
/** | ||
* Account freeing | ||
*/ | ||
-static void | ||
+void | ||
jmem_heap_stat_free (size_t size) /**< Size of freed block */ | ||
{ | ||
const size_t aligned_size = (size + JMEM_ALIGNMENT - 1) / JMEM_ALIGNMENT * JMEM_ALIGNMENT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
diff --git a/src/unix/fs.c b/src/unix/fs.c | ||
index 4281246..cc0d694 100644 | ||
--- a/src/unix/fs.c | ||
+++ b/src/unix/fs.c | ||
@@ -98,7 +98,7 @@ | ||
if (cb == NULL) { \ | ||
req->path = path; \ | ||
} else { \ | ||
- req->path = strdup(path); \ | ||
+ req->path = uv__strdup(path); \ | ||
if (req->path == NULL) { \ | ||
uv__req_unregister(loop, req); \ | ||
return -ENOMEM; \ | ||
diff --git a/src/uv-common.c b/src/uv-common.c | ||
index 813e499..04a7f18 100644 | ||
--- a/src/uv-common.c | ||
+++ b/src/uv-common.c | ||
@@ -67,7 +67,6 @@ static uv__allocator_t uv__allocator = { | ||
free, | ||
}; | ||
|
||
-#if defined(__APPLE__) | ||
char* uv__strdup(const char* s) { | ||
size_t len = strlen(s) + 1; | ||
char* m = uv__malloc(len); | ||
@@ -75,13 +74,29 @@ char* uv__strdup(const char* s) { | ||
return NULL; | ||
return memcpy(m, s, len); | ||
} | ||
-#endif | ||
+ | ||
+#define SIZEOF_MM_ALLOCNODE 8 | ||
+extern void jmem_heap_stat_alloc (size_t size); | ||
+extern void jmem_heap_stat_free (size_t size); | ||
|
||
void* uv__malloc(size_t size) { | ||
- return uv__allocator.local_malloc(size); | ||
+ char* ptr = (char*)uv__allocator.local_malloc(size); | ||
+ | ||
+ size_t new_size; | ||
+ memcpy(&new_size, (ptr - SIZEOF_MM_ALLOCNODE), sizeof(size_t)); | ||
+ jmem_heap_stat_alloc(new_size - SIZEOF_MM_ALLOCNODE); | ||
+ | ||
+ return (void*)ptr; | ||
} | ||
|
||
void uv__free(void* ptr) { | ||
+ if (ptr == NULL) | ||
+ return; | ||
+ | ||
+ size_t size; | ||
+ memcpy(&size, (char*)ptr - SIZEOF_MM_ALLOCNODE, sizeof(size_t)); | ||
+ jmem_heap_stat_free(size); | ||
+ | ||
int saved_errno; | ||
|
||
/* Libuv expects that free() does not clobber errno. The system allocator | ||
@@ -93,11 +108,31 @@ void uv__free(void* ptr) { | ||
} | ||
|
||
void* uv__calloc(size_t count, size_t size) { | ||
- return uv__allocator.local_calloc(count, size); | ||
+ char* ptr = (char*)uv__allocator.local_calloc(count, size); | ||
+ | ||
+ size_t new_size; | ||
+ memcpy(&new_size, (ptr - SIZEOF_MM_ALLOCNODE), sizeof(size_t)); | ||
+ jmem_heap_stat_alloc(new_size - SIZEOF_MM_ALLOCNODE); | ||
+ | ||
+ return (void*)ptr; | ||
} | ||
|
||
void* uv__realloc(void* ptr, size_t size) { | ||
- return uv__allocator.local_realloc(ptr, size); | ||
+ if (ptr != NULL) { | ||
+ size_t old_size; | ||
+ memcpy(&old_size, (char*)ptr - SIZEOF_MM_ALLOCNODE, sizeof(size_t)); | ||
+ jmem_heap_stat_free(old_size - SIZEOF_MM_ALLOCNODE); | ||
+ | ||
+ char* new_ptr = (char*)uv__allocator.local_realloc(ptr, size); | ||
+ | ||
+ size_t new_size; | ||
+ memcpy(&new_size, (new_ptr - SIZEOF_MM_ALLOCNODE), sizeof(size_t)); | ||
+ jmem_heap_stat_alloc(new_size - SIZEOF_MM_ALLOCNODE); | ||
+ | ||
+ return (void*)new_ptr; | ||
+ } | ||
+ | ||
+ return uv__malloc(size); | ||
} | ||
|
||
uv_buf_t uv_buf_init(char* base, unsigned int len) { | ||
diff --git a/src/uv-common.h b/src/uv-common.h | ||
index 069b5af..a24de69 100644 | ||
--- a/src/uv-common.h | ||
+++ b/src/uv-common.h | ||
@@ -239,9 +239,7 @@ void uv__fs_scandir_cleanup(uv_fs_t* req); | ||
|
||
/* Allocator prototypes */ | ||
void *uv__calloc(size_t count, size_t size); | ||
-#if defined(__APPLE__) | ||
char *uv__strdup(const char* s); | ||
-#endif | ||
void* uv__malloc(size_t size); | ||
void uv__free(void* ptr); | ||
void* uv__realloc(void* ptr, size_t size); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
diff --git a/net/socket/getsockname.c b/net/socket/getsockname.c | ||
index 7bf87c2..79fb7d7 100644 | ||
--- a/net/socket/getsockname.c | ||
+++ b/net/socket/getsockname.c | ||
@@ -151,10 +151,29 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr, | ||
* a single network device and only the network device knows the IP address. | ||
*/ | ||
|
||
+ if (lipaddr == 0) | ||
+ { | ||
+#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP) | ||
+ outaddr->sin_family = AF_INET; | ||
+ outaddr->sin_addr.s_addr = 0; | ||
+ *addrlen = sizeof(struct sockaddr_in); | ||
+#endif | ||
+ | ||
+ return OK; | ||
+ } | ||
+ | ||
net_lock(); | ||
|
||
#ifdef CONFIG_NETDEV_MULTINIC | ||
- /* Find the device matching the IPv4 address in the connection structure */ | ||
+ /* Find the device matching the IPv4 address in the connection structure. | ||
+ * NOTE: listening sockets have no ripaddr. Work around is to use the | ||
+ * lipaddr when ripaddr is not available. | ||
+ */ | ||
+ | ||
+ if (ripaddr == 0) | ||
+ { | ||
+ ripaddr = lipaddr; | ||
+ } | ||
|
||
dev = netdev_findby_ipv4addr(lipaddr, ripaddr); | ||
#else | ||
@@ -274,10 +293,29 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr, | ||
* a single network device and only the network device knows the IP address. | ||
*/ | ||
|
||
+ if (net_ipv6addr_cmp(lipaddr, g_ipv6_allzeroaddr)) | ||
+ { | ||
+#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK) | ||
+ outaddr->sin6_family = AF_INET6; | ||
+ memcpy(outaddr->sin6_addr.in6_u.u6_addr8, g_ipv6_allzeroaddr, 16); | ||
+ *addrlen = sizeof(struct sockaddr_in6); | ||
+#endif | ||
+ | ||
+ return OK; | ||
+ } | ||
+ | ||
net_lock(); | ||
|
||
#ifdef CONFIG_NETDEV_MULTINIC | ||
- /* Find the device matching the IPv6 address in the connection structure */ | ||
+ /* Find the device matching the IPv6 address in the connection structure. | ||
+ * NOTE: listening sockets have no ripaddr. Work around is to use the | ||
+ * lipaddr when ripaddr is not available. | ||
+ */ | ||
+ | ||
+ if (net_ipv6addr_cmp(ripaddr, g_ipv6_allzeroaddr)) | ||
+ { | ||
+ ripaddr = lipaddr; | ||
+ } | ||
|
||
dev = netdev_findby_ipv6addr(*lipaddr, *ripaddr); | ||
#else | ||
diff --git a/net/socket/listen.c b/net/socket/listen.c | ||
index 0d91ccb..4409a0e 100644 | ||
--- a/net/socket/listen.c | ||
+++ b/net/socket/listen.c | ||
@@ -142,7 +142,12 @@ int psock_listen(FAR struct socket *psock, int backlog) | ||
* accept() is called and enables poll()/select() logic. | ||
*/ | ||
|
||
- tcp_listen(conn); | ||
+ errcode = tcp_listen(conn); | ||
+ if (errcode < 0) | ||
+ { | ||
+ errcode = -errcode; | ||
+ goto errout; | ||
+ } | ||
} | ||
#endif /* CONFIG_NET_TCP */ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this is commented out?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to prevent the overflow of the counter. When
jerry_init
called, the allocated memory is not zero, because the IoT.js did some allocation for the environment. So we should not zero out memory statistics here, because it will cause an overflow after thefree
function calls.