esp8266/posix_helpers: Set ENOMEM on memory alloc failure.
POSIX requires malloc(), etc. to set ENOMEM on the failure, and e.g. BerkeleyDB relies on this: http://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html This should fix confusing OSError exceptions with 0 error code when working with btree module.
This commit is contained in:
parent
5671a11b81
commit
9b4666dad5
@ -26,22 +26,33 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
#include "py/gc.h"
|
#include "py/gc.h"
|
||||||
|
|
||||||
// Functions for external libs like axTLS, BerkeleyDB, etc.
|
// Functions for external libs like axTLS, BerkeleyDB, etc.
|
||||||
|
|
||||||
void *malloc(size_t size) {
|
void *malloc(size_t size) {
|
||||||
return gc_alloc(size, false);
|
void *p = gc_alloc(size, false);
|
||||||
|
if (p == NULL) {
|
||||||
|
// POSIX requires ENOMEM to be set in case of error
|
||||||
|
errno = ENOMEM;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
void free(void *ptr) {
|
void free(void *ptr) {
|
||||||
gc_free(ptr);
|
gc_free(ptr);
|
||||||
}
|
}
|
||||||
void *calloc(size_t nmemb, size_t size) {
|
void *calloc(size_t nmemb, size_t size) {
|
||||||
return m_malloc0(nmemb * size);
|
return malloc(nmemb * size);
|
||||||
}
|
}
|
||||||
void *realloc(void *ptr, size_t size) {
|
void *realloc(void *ptr, size_t size) {
|
||||||
return gc_realloc(ptr, size, true);
|
void *p = gc_realloc(ptr, size, true);
|
||||||
|
if (p == NULL) {
|
||||||
|
// POSIX requires ENOMEM to be set in case of error
|
||||||
|
errno = ENOMEM;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PLATFORM_HTONL(_n) ((uint32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) ))
|
#define PLATFORM_HTONL(_n) ((uint32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) ))
|
||||||
|
Loading…
Reference in New Issue
Block a user