Commit 526d21da authored by Johny Mattsson's avatar Johny Mattsson Committed by Terry Ellison
Browse files

Major cleanup - c_whatever is finally history. (#2838)

The PR removed the bulk of non-newlib headers from the NodeMCU source base.  
app/libc has now been cut down to the bare minimum overrides to shadow the 
corresponding functions in the SDK's libc. The old c_xyz.h headerfiles have been 
nuked in favour of the standard <xyz.h> headers, with a few exceptions over in 
sdk-overrides. Again, shipping a libc.a without headers is a terrible thing to do. We're 
still living on a prayer that libc was configured the same was as a default-configured
xtensa gcc toolchain assumes it is. That part I cannot do anything about, unfortunately, 
but it's no worse than it has been before.

This enables our source files to compile successfully using the standard header files, 
and use the typical malloc()/calloc()/realloc()/free(), the strwhatever()s and 
memwhatever()s. These end up, through macro and linker magic, mapped to the 
appropriate SDK or ROM functions.
parent 9f8b74de
......@@ -3,7 +3,7 @@
* vowstar@gmail.com
* 2015-12-29
*******************************************************************************/
#include <c_stdlib.h>
#include <stdlib.h>
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
......@@ -92,7 +92,7 @@ static void http_callback( char * response, int http_status, char ** full_respon
}
if (full_response_p && *full_response_p) {
c_free(*full_response_p);
free(*full_response_p);
*full_response_p = NULL;
}
......
......@@ -4,8 +4,8 @@
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_string.h"
#include <stdlib.h>
#include <string.h>
#include "user_interface.h"
static uint8_t data_pin;
static uint8_t clk_pin;
......
......@@ -6,8 +6,8 @@
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_string.h"
#include <stdlib.h>
#include <string.h>
static const uint32_t i2c_id = 0;
static const uint8_t i2c_addr = 0x69;
......
......@@ -3,11 +3,11 @@
#include "module.h"
#include "lauxlib.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include <alloca.h>
#include "c_types.h"
#include "mem.h"
#include "lwip/ip_addr.h"
#include "nodemcu_mdns.h"
#include "user_interface.h"
......@@ -43,16 +43,16 @@ static int mdns_register(lua_State *L)
luaL_checktype(L, -2, LUA_TSTRING);
const char *key = luaL_checkstring(L, -2);
if (c_strcmp(key, "port") == 0) {
if (strcmp(key, "port") == 0) {
info.service_port = luaL_checknumber(L, -1);
} else if (c_strcmp(key, "service") == 0) {
} else if (strcmp(key, "service") == 0) {
info.service_name = luaL_checkstring(L, -1);
} else if (c_strcmp(key, "description") == 0) {
} else if (strcmp(key, "description") == 0) {
info.host_desc = luaL_checkstring(L, -1);
} else {
int len = c_strlen(key) + 1;
int len = strlen(key) + 1;
const char *value = luaL_checkstring(L, -1);
char *p = alloca(len + c_strlen(value) + 1);
char *p = alloca(len + strlen(value) + 1);
strcpy(p, key);
strcat(p, "=");
strcat(p, value);
......
......@@ -4,8 +4,8 @@
#include "lauxlib.h"
#include "platform.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "c_types.h"
#include "mem.h"
......@@ -133,7 +133,7 @@ static void mqtt_socket_disconnected(void *arg) // tcp only
}
if(mud->mqtt_state.recv_buffer) {
c_free(mud->mqtt_state.recv_buffer);
free(mud->mqtt_state.recv_buffer);
mud->mqtt_state.recv_buffer = NULL;
}
mud->mqtt_state.recv_buffer_size = 0;
......@@ -142,9 +142,9 @@ static void mqtt_socket_disconnected(void *arg) // tcp only
if(mud->pesp_conn){
mud->pesp_conn->reverse = NULL;
if(mud->pesp_conn->proto.tcp)
c_free(mud->pesp_conn->proto.tcp);
free(mud->pesp_conn->proto.tcp);
mud->pesp_conn->proto.tcp = NULL;
c_free(mud->pesp_conn);
free(mud->pesp_conn);
mud->pesp_conn = NULL;
}
......@@ -303,7 +303,7 @@ static void mqtt_socket_received(void *arg, char *pdata, unsigned short len)
// Last buffer had so few byte that we could not determine message length.
// Store in a local heap buffer and operate on this, as if was the regular pdata buffer.
// Avoids having to repeat message size/overflow logic.
temp_pdata = c_zalloc(mud->mqtt_state.recv_buffer_size + len);
temp_pdata = calloc(1,mud->mqtt_state.recv_buffer_size + len);
if(temp_pdata == NULL) {
NODE_DBG("MQTT[buffering-short]: Failed to allocate %u bytes, disconnecting...\n", mud->mqtt_state.recv_buffer_size + len);
#ifdef CLIENT_SSL_ENABLE
......@@ -320,7 +320,7 @@ static void mqtt_socket_received(void *arg, char *pdata, unsigned short len)
NODE_DBG("MQTT[buffering-short]: Continuing with %u + %u bytes\n", mud->mqtt_state.recv_buffer_size, len);
memcpy(temp_pdata, mud->mqtt_state.recv_buffer, mud->mqtt_state.recv_buffer_size);
memcpy(temp_pdata + mud->mqtt_state.recv_buffer_size, pdata, len);
c_free(mud->mqtt_state.recv_buffer);
free(mud->mqtt_state.recv_buffer);
mud->mqtt_state.recv_buffer = NULL;
mud->mqtt_state.recv_buffer_state = MQTT_RECV_NORMAL;
......@@ -533,7 +533,7 @@ READPACKET:
// max_message_length is 16bit.
uint16_t alloc_size = message_length > 0 ? (uint16_t)message_length : in_buffer_length;
mud->mqtt_state.recv_buffer = c_zalloc(alloc_size);
mud->mqtt_state.recv_buffer = calloc(1,alloc_size);
if (mud->mqtt_state.recv_buffer == NULL) {
NODE_DBG("MQTT: Failed to allocate %u bytes, disconnecting...\n", alloc_size);
#ifdef CLIENT_SSL_ENABLE
......@@ -674,7 +674,7 @@ RX_MESSAGE_PROCESSED:
if(continuation_buffer != NULL) {
NODE_DBG("MQTT[buffering]: buffered message finished. Continuing with rest of rx buffer (%u)\n",
len);
c_free(mud->mqtt_state.recv_buffer);
free(mud->mqtt_state.recv_buffer);
mud->mqtt_state.recv_buffer = NULL;
in_buffer = continuation_buffer;
......@@ -698,7 +698,7 @@ RX_MESSAGE_PROCESSED:
RX_PACKET_FINISHED:
if(temp_pdata != NULL) {
c_free(temp_pdata);
free(temp_pdata);
}
mqtt_send_if_possible(pesp_conn);
......@@ -902,12 +902,12 @@ static int mqtt_socket_client( lua_State* L )
lmqtt_userdata *mud;
char tempid[20] = {0};
c_sprintf(tempid, "%s%x", "NodeMCU_", system_get_chip_id() );
sprintf(tempid, "%s%x", "NodeMCU_", system_get_chip_id() );
NODE_DBG(tempid);
NODE_DBG("\n");
const char *clientId = tempid, *username = NULL, *password = NULL;
size_t idl = c_strlen(tempid);
size_t idl = strlen(tempid);
size_t unl = 0, pwl = 0;
int keepalive = 0;
int stack = 1;
......@@ -917,7 +917,7 @@ static int mqtt_socket_client( lua_State* L )
// create a object
mud = (lmqtt_userdata *)lua_newuserdata(L, sizeof(lmqtt_userdata));
c_memset(mud, 0, sizeof(*mud));
memset(mud, 0, sizeof(*mud));
// pre-initialize it, in case of errors
mud->self_ref = LUA_NOREF;
mud->cb_connect_ref = LUA_NOREF;
......@@ -989,30 +989,30 @@ static int mqtt_socket_client( lua_State* L )
}
// TODO: check the zalloc result.
mud->connect_info.client_id = (uint8_t *)c_zalloc(idl+1);
mud->connect_info.username = (uint8_t *)c_zalloc(unl + 1);
mud->connect_info.password = (uint8_t *)c_zalloc(pwl + 1);
mud->connect_info.client_id = (uint8_t *)calloc(1,idl+1);
mud->connect_info.username = (uint8_t *)calloc(1,unl + 1);
mud->connect_info.password = (uint8_t *)calloc(1,pwl + 1);
if(!mud->connect_info.client_id || !mud->connect_info.username || !mud->connect_info.password){
if(mud->connect_info.client_id) {
c_free(mud->connect_info.client_id);
free(mud->connect_info.client_id);
mud->connect_info.client_id = NULL;
}
if(mud->connect_info.username) {
c_free(mud->connect_info.username);
free(mud->connect_info.username);
mud->connect_info.username = NULL;
}
if(mud->connect_info.password) {
c_free(mud->connect_info.password);
free(mud->connect_info.password);
mud->connect_info.password = NULL;
}
return luaL_error(L, "not enough memory");
}
c_memcpy(mud->connect_info.client_id, clientId, idl);
memcpy(mud->connect_info.client_id, clientId, idl);
mud->connect_info.client_id[idl] = 0;
c_memcpy(mud->connect_info.username, username, unl);
memcpy(mud->connect_info.username, username, unl);
mud->connect_info.username[unl] = 0;
c_memcpy(mud->connect_info.password, password, pwl);
memcpy(mud->connect_info.password, password, pwl);
mud->connect_info.password[pwl] = 0;
NODE_DBG("MQTT: Init info: %s, %s, %s\r\n", mud->connect_info.client_id, mud->connect_info.username, mud->connect_info.password);
......@@ -1055,9 +1055,9 @@ static int mqtt_delete( lua_State* L )
if(mud->pesp_conn){ // for client connected to tcp server, this should set NULL in disconnect cb
mud->pesp_conn->reverse = NULL;
if(mud->pesp_conn->proto.tcp)
c_free(mud->pesp_conn->proto.tcp);
free(mud->pesp_conn->proto.tcp);
mud->pesp_conn->proto.tcp = NULL;
c_free(mud->pesp_conn);
free(mud->pesp_conn);
mud->pesp_conn = NULL; // for socket, it will free this when disconnected
}
while(mud->mqtt_state.pending_msg_q) {
......@@ -1066,34 +1066,34 @@ static int mqtt_delete( lua_State* L )
// ---- alloc-ed in mqtt_socket_lwt()
if(mud->connect_info.will_topic){
c_free(mud->connect_info.will_topic);
free(mud->connect_info.will_topic);
mud->connect_info.will_topic = NULL;
}
if(mud->connect_info.will_message){
c_free(mud->connect_info.will_message);
free(mud->connect_info.will_message);
mud->connect_info.will_message = NULL;
}
// ----
//--------- alloc-ed in mqtt_socket_received()
if(mud->mqtt_state.recv_buffer) {
c_free(mud->mqtt_state.recv_buffer);
free(mud->mqtt_state.recv_buffer);
mud->mqtt_state.recv_buffer = NULL;
}
// ----
//--------- alloc-ed in mqtt_socket_client()
if(mud->connect_info.client_id){
c_free(mud->connect_info.client_id);
free(mud->connect_info.client_id);
mud->connect_info.client_id = NULL;
}
if(mud->connect_info.username){
c_free(mud->connect_info.username);
free(mud->connect_info.username);
mud->connect_info.username = NULL;
}
if(mud->connect_info.password){
c_free(mud->connect_info.password);
free(mud->connect_info.password);
mud->connect_info.password = NULL;
}
// -------
......@@ -1203,7 +1203,7 @@ static sint8 socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
if(ipaddr->addr != 0)
{
dns_reconn_count = 0;
c_memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4);
memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4);
NODE_DBG("TCP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr)));
NODE_DBG("\n");
......@@ -1241,7 +1241,7 @@ static int mqtt_socket_connect( lua_State* L )
struct espconn *pesp_conn = mud->pesp_conn;
if(!pesp_conn) {
pesp_conn = mud->pesp_conn = (struct espconn *)c_zalloc(sizeof(struct espconn));
pesp_conn = mud->pesp_conn = (struct espconn *)calloc(1,sizeof(struct espconn));
} else {
espconn_delete(pesp_conn);
}
......@@ -1249,9 +1249,9 @@ static int mqtt_socket_connect( lua_State* L )
if(!pesp_conn)
return luaL_error(L, "not enough memory");
if (!pesp_conn->proto.tcp)
pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp));
pesp_conn->proto.tcp = (esp_tcp *)calloc(1,sizeof(esp_tcp));
if(!pesp_conn->proto.tcp){
c_free(pesp_conn);
free(pesp_conn);
pesp_conn = mud->pesp_conn = NULL;
return luaL_error(L, "not enough memory");
}
......@@ -1271,7 +1271,7 @@ static int mqtt_socket_connect( lua_State* L )
domain = "127.0.0.1";
}
ipaddr.addr = ipaddr_addr(domain);
c_memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4);
memcpy(pesp_conn->proto.tcp->remote_ip, &ipaddr.addr, 4);
NODE_DBG("TCP ip is set: ");
NODE_DBG(IPSTR, IP2STR(&ipaddr.addr));
NODE_DBG("\n");
......@@ -1340,7 +1340,7 @@ static int mqtt_socket_connect( lua_State* L )
//My guess: If in doubt, resume the timer
// timer started in socket_connect()
if((ipaddr.addr == IPADDR_NONE) && (c_memcmp(domain,"255.255.255.255",16) != 0))
if((ipaddr.addr == IPADDR_NONE) && (memcmp(domain,"255.255.255.255",16) != 0))
{
host_ip.addr = 0;
dns_reconn_count = 0;
......@@ -1434,25 +1434,25 @@ static int mqtt_socket_on( lua_State* L )
luaL_checkanyfunction(L, 3);
lua_pushvalue(L, 3); // copy argument (func) to the top of stack
if( sl == 7 && c_strcmp(method, "connect") == 0){
if( sl == 7 && strcmp(method, "connect") == 0){
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_connect_ref);
mud->cb_connect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if( sl == 7 && c_strcmp(method, "offline") == 0){
}else if( sl == 7 && strcmp(method, "offline") == 0){
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_disconnect_ref);
mud->cb_disconnect_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if( sl == 7 && c_strcmp(method, "message") == 0){
}else if( sl == 7 && strcmp(method, "message") == 0){
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_message_ref);
mud->cb_message_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if( sl == 8 && c_strcmp(method, "overflow") == 0){
}else if( sl == 8 && strcmp(method, "overflow") == 0){
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_overflow_ref);
mud->cb_overflow_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if( sl == 6 && c_strcmp(method, "puback") == 0){
}else if( sl == 6 && strcmp(method, "puback") == 0){
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_puback_ref);
mud->cb_puback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if( sl == 6 && c_strcmp(method, "suback") == 0){
}else if( sl == 6 && strcmp(method, "suback") == 0){
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_suback_ref);
mud->cb_suback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else if( sl == 8 && c_strcmp(method, "unsuback") == 0){
}else if( sl == 8 && strcmp(method, "unsuback") == 0){
luaL_unref(L, LUA_REGISTRYINDEX, mud->cb_unsuback_ref);
mud->cb_unsuback_ref = luaL_ref(L, LUA_REGISTRYINDEX);
}else{
......@@ -1795,30 +1795,30 @@ static int mqtt_socket_lwt( lua_State* L )
}
stack++;
if(mud->connect_info.will_topic){ // free the previous one if there is any
c_free(mud->connect_info.will_topic);
free(mud->connect_info.will_topic);
mud->connect_info.will_topic = NULL;
}
if(mud->connect_info.will_message){
c_free(mud->connect_info.will_message);
free(mud->connect_info.will_message);
mud->connect_info.will_message = NULL;
}
mud->connect_info.will_topic = (uint8_t*) c_zalloc( topicSize + 1 );
mud->connect_info.will_message = (uint8_t*) c_zalloc( msgSize + 1 );
mud->connect_info.will_topic = (uint8_t*) calloc(1, topicSize + 1 );
mud->connect_info.will_message = (uint8_t*) calloc(1, msgSize + 1 );
if(!mud->connect_info.will_topic || !mud->connect_info.will_message){
if(mud->connect_info.will_topic){
c_free(mud->connect_info.will_topic);
free(mud->connect_info.will_topic);
mud->connect_info.will_topic = NULL;
}
if(mud->connect_info.will_message){
c_free(mud->connect_info.will_message);
free(mud->connect_info.will_message);
mud->connect_info.will_message = NULL;
}
return luaL_error( L, "not enough memory");
}
c_memcpy(mud->connect_info.will_topic, lwtTopic, topicSize);
memcpy(mud->connect_info.will_topic, lwtTopic, topicSize);
mud->connect_info.will_topic[topicSize] = 0;
c_memcpy(mud->connect_info.will_message, lwtMsg, msgSize);
memcpy(mud->connect_info.will_message, lwtMsg, msgSize);
mud->connect_info.will_message[msgSize] = 0;
if ( lua_isnumber(L, stack) )
......
......@@ -5,8 +5,9 @@
#include "platform.h"
#include "lmem.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "c_types.h"
#include "mem.h"
......@@ -875,14 +876,14 @@ static void net_dns_static_cb(const char *name, ip_addr_t *ipaddr, void *callbac
addr = *ipaddr;
else addr.addr = 0xFFFFFFFF;
int cb_ref = ((int*)callback_arg)[0];
c_free(callback_arg);
free(callback_arg);
lua_State *L = lua_getstate();
lua_rawgeti(L, LUA_REGISTRYINDEX, cb_ref);
lua_pushnil(L);
if (addr.addr != 0xFFFFFFFF) {
char iptmp[20];
size_t ipl = c_sprintf(iptmp, IPSTR, IP2STR(&addr.addr));
size_t ipl = sprintf(iptmp, IPSTR, IP2STR(&addr.addr));
lua_pushlstring(L, iptmp, ipl);
} else {
lua_pushnil(L);
......@@ -906,7 +907,7 @@ static int net_dns_static( lua_State* L ) {
if (cbref == LUA_NOREF) {
return luaL_error(L, "wrong callback");
}
int *cbref_ptr = c_zalloc(sizeof(int));
int *cbref_ptr = calloc(1, sizeof(int));
cbref_ptr[0] = cbref;
ip_addr_t addr;
err_t err = dns_gethostbyname(domain, &addr, net_dns_static_cb, cbref_ptr);
......@@ -917,7 +918,7 @@ static int net_dns_static( lua_State* L ) {
return 0;
} else {
int e = lwip_lua_checkerr(L, err);
c_free(cbref_ptr);
free(cbref_ptr);
return e;
}
return 0;
......@@ -958,7 +959,7 @@ static int net_getdnsserver( lua_State* L ) {
lua_pushnil( L );
} else {
char temp[20] = {0};
c_sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) );
sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) );
lua_pushstring( L, temp );
}
......
......@@ -17,7 +17,7 @@
#include "platform.h"
#include "lflash.h"
#include "c_types.h"
#include "c_string.h"
#include <string.h>
#include "driver/uart.h"
#include "user_interface.h"
#include "flash_api.h"
......@@ -189,7 +189,7 @@ static int output_redir_ref = LUA_NOREF;
static int serial_debug = 1;
void output_redirect(const char *str) {
lua_State *L = lua_getstate();
// if(c_strlen(str)>=TX_BUFF_SIZE){
// if(strlen(str)>=TX_BUFF_SIZE){
// NODE_ERR("output too long.\n");
// return;
// }
......@@ -260,18 +260,18 @@ static int node_compile( lua_State* L )
size_t len;
const char *fname = luaL_checklstring( L, 1, &len );
const char *basename = vfs_basename( fname );
luaL_argcheck(L, c_strlen(basename) <= FS_OBJ_NAME_LEN && c_strlen(fname) == len, 1, "filename invalid");
luaL_argcheck(L, strlen(basename) <= FS_OBJ_NAME_LEN && strlen(fname) == len, 1, "filename invalid");
char *output = luaM_malloc( L, len+1 );
c_strcpy(output, fname);
strcpy(output, fname);
// check here that filename end with ".lua".
if (len < 4 || (c_strcmp( output + len - 4, ".lua") != 0) ) {
if (len < 4 || (strcmp( output + len - 4, ".lua") != 0) ) {
luaM_free( L, output );
return luaL_error(L, "not a .lua file");
}
output[c_strlen(output) - 2] = 'c';
output[c_strlen(output) - 1] = '\0';
output[strlen(output) - 2] = 'c';
output[strlen(output) - 1] = '\0';
NODE_DBG(output);
NODE_DBG("\n");
if (luaL_loadfsfile(L, fname) != 0) {
......@@ -622,7 +622,7 @@ static int node_getpartitiontable (lua_State *L) {
static void insert_partition(partition_item_t *p, int n, uint32_t type, uint32_t addr) {
if (n>0)
c_memmove(p+1, p, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */
memmove(p+1, p, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */
p->type = type;
p->addr = addr;
p->size = 0;
......@@ -630,7 +630,7 @@ static void insert_partition(partition_item_t *p, int n, uint32_t type, uint32_t
static void delete_partition(partition_item_t *p, int n) {
if (n>0)
c_memmove(p, p+1, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */
memmove(p, p+1, n*sizeof(partition_item_t)); /* overlapped so must be move not cpy */
}
#define SKIP (~0)
......@@ -668,7 +668,7 @@ static int node_setpartitiontable (lua_State *L) {
*/
lua_newuserdata(L, (n+2)*sizeof(partition_item_t));
pt = lua_touserdata (L, -1);
c_memcpy(pt, rcr_pt, n*sizeof(partition_item_t));
memcpy(pt, rcr_pt, n*sizeof(partition_item_t));
pt[n].type = 0; pt[n+1].type = 0;
for (i = 0; i < n; i ++) {
......
......@@ -3,8 +3,8 @@
#include "module.h"
#include "lauxlib.h"
#include "task/task.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "pcm.h"
#include "pcm_drv.h"
......@@ -43,11 +43,11 @@ static int pcm_drv_free( lua_State *L )
UNREF_CB( cfg->self_ref );
if (cfg->bufs[0].data) {
c_free( cfg->bufs[0].data );
free( cfg->bufs[0].data );
cfg->bufs[0].data = NULL;
}
if (cfg->bufs[1].data) {
c_free( cfg->bufs[1].data );
free( cfg->bufs[1].data );
cfg->bufs[1].data = NULL;
}
......@@ -152,19 +152,19 @@ static int pcm_drv_on( lua_State *L )
is_func = TRUE;
}
if ((len == 4) && (c_strcmp( event, "data" ) == 0)) {
if ((len == 4) && (strcmp( event, "data" ) == 0)) {
luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_data_ref);
cfg->cb_data_ref = COND_REF( is_func );
} else if ((len == 7) && (c_strcmp( event, "drained" ) == 0)) {
} else if ((len == 7) && (strcmp( event, "drained" ) == 0)) {
luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_drained_ref);
cfg->cb_drained_ref = COND_REF( is_func );
} else if ((len == 6) && (c_strcmp( event, "paused" ) == 0)) {
} else if ((len == 6) && (strcmp( event, "paused" ) == 0)) {
luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_paused_ref);
cfg->cb_paused_ref = COND_REF( is_func );
} else if ((len == 7) && (c_strcmp( event, "stopped" ) == 0)) {
} else if ((len == 7) && (strcmp( event, "stopped" ) == 0)) {
luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_stopped_ref);
cfg->cb_stopped_ref = COND_REF( is_func );
} else if ((len == 2) && (c_strcmp( event, "vu" ) == 0)) {
} else if ((len == 2) && (strcmp( event, "vu" ) == 0)) {
luaL_unref( L, LUA_REGISTRYINDEX, cfg->cb_vu_ref);
cfg->cb_vu_ref = COND_REF( is_func );
......
......@@ -9,7 +9,7 @@
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "c_stdlib.h"
#include <stdlib.h>
#include "module.h"
#include "lauxlib.h"
......
......@@ -12,7 +12,7 @@
#include "c_types.h"
#include "user_interface.h"
#include "driver/rotary.h"
#include "../libc/c_stdlib.h"
#include <stdlib.h>
#define MASK(x) (1 << ROTARY_ ## x ## _INDEX)
......@@ -145,7 +145,7 @@ static int lrotary_setup( lua_State* L )
callback_free(L, id, ROTARY_ALL);
if (!data[id]) {
data[id] = (DATA *) c_zalloc(sizeof(DATA));
data[id] = (DATA *) calloc(1, sizeof(DATA));
if (!data[id]) {
return -1;
}
......@@ -211,7 +211,7 @@ static int lrotary_close( lua_State* L )
DATA *d = data[id];
if (d) {
data[id] = NULL;
c_free(d);
free(d);
}
if (rotary_close( id )) {
......
......@@ -6,6 +6,7 @@
#include "rtc/rtctime.h"
#define RTCTIME_SLEEP_ALIGNED rtctime_deep_sleep_until_aligned_us
#include "rtc/rtcfifo.h"
#include <string.h>
// rtcfifo.prepare ([{sensor_count=n, interval_us=m, storage_begin=x, storage_end=y}])
static int rtcfifo_prepare (lua_State *L)
......
......@@ -6,9 +6,9 @@
#ifndef LOCAL_LUA
#include "module.h"
#include "c_string.h"
#include "c_math.h"
#include "c_limits.h"
#include <string.h>
#include <math.h>
#include <limits.h>
#endif
#include "json_config.h"
......
......@@ -38,7 +38,7 @@
#include "os_type.h"
#include "osapi.h"
#include "lwip/udp.h"
#include "c_stdlib.h"
#include <stdlib.h>
#include "user_modules.h"
#include "lwip/dns.h"
#include "task/task.h"
......@@ -180,18 +180,18 @@ static void cleanup (lua_State *L)
luaL_unref (L, LUA_REGISTRYINDEX, state->sync_cb_ref);
luaL_unref (L, LUA_REGISTRYINDEX, state->err_cb_ref);
luaL_unref (L, LUA_REGISTRYINDEX, state->list_ref);
os_free (state);
free (state);
state = 0;
}
static ip_addr_t* get_free_server() {
ip_addr_t* temp = (ip_addr_t *) c_malloc((server_count + 1) * sizeof(ip_addr_t));
ip_addr_t* temp = (ip_addr_t *) malloc((server_count + 1) * sizeof(ip_addr_t));
if (server_count > 0) {
memcpy(temp, serverp, server_count * sizeof(ip_addr_t));
}
if (serverp) {
c_free(serverp);
free(serverp);
}
serverp = temp;
......@@ -671,7 +671,7 @@ static void sntp_dolookups (lua_State *L) {
}
static char *state_init(lua_State *L) {
state = (sntp_state_t *)c_malloc (sizeof (sntp_state_t));
state = (sntp_state_t *)malloc (sizeof (sntp_state_t));
if (!state)
return ("out of memory");
......@@ -700,7 +700,7 @@ static char *set_repeat_mode(lua_State *L, bool enable)
{
if (enable) {
set_repeat_mode(L, FALSE);
repeat = (sntp_repeat_t *) c_malloc(sizeof(sntp_repeat_t));
repeat = (sntp_repeat_t *) malloc(sizeof(sntp_repeat_t));
if (!repeat) {
return "no memory";
}
......@@ -722,7 +722,7 @@ static char *set_repeat_mode(lua_State *L, bool enable)
luaL_unref (L, LUA_REGISTRYINDEX, repeat->sync_cb_ref);
luaL_unref (L, LUA_REGISTRYINDEX, repeat->err_cb_ref);
luaL_unref (L, LUA_REGISTRYINDEX, repeat->list_ref);
c_free(repeat);
free(repeat);
repeat = NULL;
}
}
......@@ -811,7 +811,7 @@ static int sntp_sync (lua_State *L)
for (i = 0; i < 4; i++) {
lua_pushnumber(L, i + 1);
char buf[64];
c_sprintf(buf, "%d.nodemcu.pool.ntp.org", i);
sprintf(buf, "%d.nodemcu.pool.ntp.org", i);
lua_pushstring(L, buf);
lua_settable(L, -3);
}
......@@ -835,7 +835,7 @@ error:
{
if (state->pcb)
udp_remove (state->pcb);
c_free (state);
free (state);
state = 0;
}
return luaL_error (L, errmsg);
......
......@@ -31,7 +31,7 @@
#define SQLITE_OMIT_PROGRESS_CALLBACK 1
#include <c_stdlib.h>
#include <c_string.h>
#include <string.h>
#include <assert.h>
#define LUA_LIB
......@@ -273,7 +273,7 @@ static int dbvm_tostring(lua_State *L) {
if (svm->vm == NULL)
strcpy(buff, "closed");
else
c_sprintf(buff, "%p", svm);
sprintf(buff, "%p", svm);
lua_pushfstring(L, "sqlite virtual machine (%s)", buff);
return 1;
}
......@@ -743,7 +743,7 @@ static int cleanupdb(lua_State *L, sdb *db) {
luaL_unref(L, LUA_REGISTRYINDEX, func->fn_step);
luaL_unref(L, LUA_REGISTRYINDEX, func->fn_finalize);
luaL_unref(L, LUA_REGISTRYINDEX, func->udata);
c_free(func);
free(func);
func = func_next;
}
db->func = NULL;
......@@ -800,7 +800,7 @@ static int lcontext_tostring(lua_State *L) {
if (ctx->ctx == NULL)
strcpy(buff, "closed");
else
c_sprintf(buff, "%p", ctx->ctx);
sprintf(buff, "%p", ctx->ctx);
lua_pushfstring(L, "sqlite function context (%s)", buff);
return 1;
}
......@@ -1156,7 +1156,7 @@ static int db_register_function(lua_State *L, int aggregate) {
if (aggregate) luaL_checktype(L, 5, LUA_TFUNCTION);
/* maybe an alternative way to allocate memory should be used/avoided */
func = (sdb_func*)c_malloc(sizeof(sdb_func));
func = (sdb_func*)malloc(sizeof(sdb_func));
if (func == NULL) {
luaL_error(L, "out of memory");
}
......@@ -1194,7 +1194,7 @@ static int db_register_function(lua_State *L, int aggregate) {
}
else {
/* free allocated memory */
c_free(func);
free(func);
}
lua_pushboolean(L, result == SQLITE_OK ? 1 : 0);
......@@ -1232,7 +1232,7 @@ static int collwrapper(scc *co,int l1,const void *p1,
static void collfree(scc *co) {
if (co) {
luaL_unref(co->L,LUA_REGISTRYINDEX,co->ref);
c_free(co);
free(co);
}
}
......@@ -1246,7 +1246,7 @@ static int db_create_collation(lua_State *L) {
else if (!lua_isnil(L,3))
luaL_error(L,"create_collation: function or nil expected");
if (collfunc != NULL) {
co=(scc *)c_malloc(sizeof(scc)); /* userdata is a no-no as it
co=(scc *)malloc(sizeof(scc)); /* userdata is a no-no as it
will be garbage-collected */
if (co) {
co->L=L;
......@@ -2037,7 +2037,7 @@ static int db_tostring(lua_State *L) {
if (db->db == NULL)
strcpy(buff, "closed");
else
c_sprintf(buff, "%p", lua_touserdata(L, 1));
sprintf(buff, "%p", lua_touserdata(L, 1));
lua_pushfstring(L, "sqlite database (%s)", buff);
return 1;
}
......
......@@ -22,7 +22,7 @@
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "c_math.h"
#include <math.h>
// #define TCS34725_ADDRESS (0x29<<1)
#define TCS34725_ADDRESS (0x29)
......
......@@ -8,8 +8,8 @@
#include "platform.h"
#include "lmem.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "c_types.h"
#include "mem.h"
......@@ -77,10 +77,10 @@ static void tls_socket_cleanup(tls_socket_ud *ud) {
if (ud->pesp_conn) {
espconn_secure_disconnect(ud->pesp_conn);
if (ud->pesp_conn->proto.tcp) {
c_free(ud->pesp_conn->proto.tcp);
free(ud->pesp_conn->proto.tcp);
ud->pesp_conn->proto.tcp = NULL;
}
c_free(ud->pesp_conn);
free(ud->pesp_conn);
ud->pesp_conn = NULL;
}
lua_State *L = lua_getstate();
......@@ -167,7 +167,7 @@ static void tls_socket_dns_cb( const char* domain, const ip_addr_t *ip_addr, tls
lua_pushnil(L);
} else {
char tmp[20];
c_sprintf(tmp, IPSTR, IP2STR(&addr.addr));
sprintf(tmp, IPSTR, IP2STR(&addr.addr));
lua_pushstring(L, tmp);
}
lua_call(L, 2, 0);
......@@ -205,13 +205,13 @@ static int tls_socket_connect( lua_State *L ) {
if (domain == NULL)
return luaL_error(L, "invalid domain");
ud->pesp_conn = (struct espconn*)c_zalloc(sizeof(struct espconn));
ud->pesp_conn = (struct espconn*)calloc(1,sizeof(struct espconn));
if(!ud->pesp_conn)
return luaL_error(L, "not enough memory");
ud->pesp_conn->proto.udp = NULL;
ud->pesp_conn->proto.tcp = (esp_tcp *)c_zalloc(sizeof(esp_tcp));
ud->pesp_conn->proto.tcp = (esp_tcp *)calloc(1,sizeof(esp_tcp));
if(!ud->pesp_conn->proto.tcp){
c_free(ud->pesp_conn);
free(ud->pesp_conn);
ud->pesp_conn = NULL;
return luaL_error(L, "not enough memory");
}
......@@ -349,7 +349,7 @@ static int tls_socket_getpeer( lua_State *L ) {
if(ud->pesp_conn && ud->pesp_conn->proto.tcp->remote_port != 0){
char temp[20] = {0};
c_sprintf(temp, IPSTR, IP2STR( &(ud->pesp_conn->proto.tcp->remote_ip) ) );
sprintf(temp, IPSTR, IP2STR( &(ud->pesp_conn->proto.tcp->remote_ip) ) );
lua_pushstring( L, temp );
lua_pushinteger( L, ud->pesp_conn->proto.tcp->remote_port );
} else {
......@@ -382,10 +382,10 @@ static int tls_socket_delete( lua_State *L ) {
if (ud->pesp_conn) {
espconn_secure_disconnect(ud->pesp_conn);
if (ud->pesp_conn->proto.tcp) {
c_free(ud->pesp_conn->proto.tcp);
free(ud->pesp_conn->proto.tcp);
ud->pesp_conn->proto.tcp = NULL;
}
c_free(ud->pesp_conn);
free(ud->pesp_conn);
ud->pesp_conn = NULL;
}
......@@ -507,7 +507,7 @@ static const char *fill_page_with_pem(lua_State *L, const unsigned char *flash_m
memset(buffer, 0xff, buffer_limit - buffer);
// Lets see if it matches what is already there....
if (c_memcmp(buffer_base, flash_memory, INTERNAL_FLASH_SECTOR_SIZE) != 0) {
if (memcmp(buffer_base, flash_memory, INTERNAL_FLASH_SECTOR_SIZE) != 0) {
// Starts being dangerous
if (platform_flash_erase_sector(flash_offset / INTERNAL_FLASH_SECTOR_SIZE) != PLATFORM_OK) {
luaM_free(L, buffer_base);
......
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_string.h"
#include <stdlib.h>
#include <string.h>
#include "user_interface.h"
static inline uint32_t _getCycleCount(void) {
......@@ -68,7 +68,7 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L)
const char *rgb = luaL_checklstring(L, 2, &length);
// dont modify lua-internal lstring - make a copy instead
char *buffer = (char *)c_malloc(length);
char *buffer = (char *)malloc(length);
// Ignore incomplete Byte triples at the end of buffer
length -= length % 3;
......@@ -95,7 +95,7 @@ static int ICACHE_FLASH_ATTR tm1829_write(lua_State* L)
os_delay_us(500); // reset time
c_free(buffer);
free(buffer);
return 0;
}
......
......@@ -78,7 +78,7 @@ typedef struct{
uint32_t interval;
uint8_t mode;
}timer_struct_t;
typedef timer_struct_t* timer_t;
typedef timer_struct_t* tmr_t;
// The previous implementation extended the rtc counter to 64 bits, and then
// applied rtc2sec with the current calibration value to that 64 bit value.
......@@ -97,7 +97,7 @@ static sint32_t soft_watchdog = -1;
static os_timer_t rtc_timer;
static void alarm_timer_common(void* arg){
timer_t tmr = (timer_t)arg;
tmr_t tmr = (tmr_t)arg;
lua_State* L = lua_getstate();
if(tmr->lua_ref == LUA_NOREF)
return;
......@@ -142,16 +142,16 @@ static int tmr_now(lua_State* L){
return 1;
}
static timer_t tmr_get( lua_State *L, int stack ) {
timer_t t = (timer_t)luaL_checkudata(L, stack, "tmr.timer");
static tmr_t tmr_get( lua_State *L, int stack ) {
tmr_t t = (tmr_t)luaL_checkudata(L, stack, "tmr.timer");
if (t == NULL)
return (timer_t)luaL_error(L, "timer object expected");
return (tmr_t)luaL_error(L, "timer object expected");
return t;
}
// Lua: tmr.register( ref, interval, mode, function )
static int tmr_register(lua_State* L){
timer_t tmr = tmr_get(L, 1);
tmr_t tmr = tmr_get(L, 1);
uint32_t interval = luaL_checkinteger(L, 2);
uint8_t mode = luaL_checkinteger(L, 3);
......@@ -176,7 +176,7 @@ static int tmr_register(lua_State* L){
// Lua: tmr.start( id / ref )
static int tmr_start(lua_State* L){
timer_t tmr = tmr_get(L, 1);
tmr_t tmr = tmr_get(L, 1);
if (tmr->self_ref == LUA_NOREF) {
lua_pushvalue(L, 1);
......@@ -202,7 +202,7 @@ static int tmr_alarm(lua_State* L){
// Lua: tmr.stop( id / ref )
static int tmr_stop(lua_State* L){
timer_t tmr = tmr_get(L, 1);
tmr_t tmr = tmr_get(L, 1);
if (tmr->self_ref != LUA_REFNIL) {
luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref);
......@@ -244,7 +244,7 @@ static int tmr_resume_all (lua_State *L){
// Lua: tmr.unregister( id / ref )
static int tmr_unregister(lua_State* L){
timer_t tmr = tmr_get(L, 1);
tmr_t tmr = tmr_get(L, 1);
if (tmr->self_ref != LUA_REFNIL) {
luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref);
......@@ -262,7 +262,7 @@ static int tmr_unregister(lua_State* L){
// Lua: tmr.interval( id / ref, interval )
static int tmr_interval(lua_State* L){
timer_t tmr = tmr_get(L, 1);
tmr_t tmr = tmr_get(L, 1);
uint32_t interval = luaL_checkinteger(L, 2);
luaL_argcheck(L, (interval > 0 && interval <= MAX_TIMEOUT), 2, MAX_TIMEOUT_ERR_STR);
......@@ -278,7 +278,7 @@ static int tmr_interval(lua_State* L){
// Lua: tmr.state( id / ref )
static int tmr_state(lua_State* L){
timer_t tmr = tmr_get(L, 1);
tmr_t tmr = tmr_get(L, 1);
if(tmr->mode == TIMER_MODE_OFF){
lua_pushnil(L);
......@@ -355,7 +355,7 @@ static int tmr_softwd( lua_State* L ){
// Lua: tmr.create()
static int tmr_create( lua_State *L ) {
timer_t ud = (timer_t)lua_newuserdata(L, sizeof(timer_struct_t));
tmr_t ud = (tmr_t)lua_newuserdata(L, sizeof(timer_struct_t));
if (!ud) return luaL_error(L, "not enough memory");
luaL_getmetatable(L, "tmr.timer");
lua_setmetatable(L, -2);
......
......@@ -5,7 +5,7 @@
#include "platform.h"
#include "c_types.h"
#include "c_string.h"
#include <string.h>
#include "rom.h"
static int uart_receive_rf = LUA_NOREF;
......@@ -67,7 +67,7 @@ static int l_uart_on( lua_State* L )
} else {
lua_pushnil(L);
}
if(sl == 4 && c_strcmp(method, "data") == 0){
if(sl == 4 && strcmp(method, "data") == 0){
run_input = true;
if(uart_receive_rf != LUA_NOREF){
luaL_unref(L, LUA_REGISTRYINDEX, uart_receive_rf);
......
......@@ -14,8 +14,8 @@
#include "module.h"
#include "c_types.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "websocketclient.h"
......@@ -191,14 +191,14 @@ static int websocketclient_connect(lua_State *L) {
static header_t *realloc_headers(header_t *headers, int new_size) {
if(headers) {
for(header_t *header = headers; header->key; header++) {
c_free(header->value);
c_free(header->key);
free(header->value);
free(header->key);
}
c_free(headers);
free(headers);
}
if(!new_size)
return NULL;
return (header_t *)c_malloc(sizeof(header_t) * (new_size + 1));
return (header_t *)malloc(sizeof(header_t) * (new_size + 1));
}
static int websocketclient_config(lua_State *L) {
......@@ -225,8 +225,8 @@ static int websocketclient_config(lua_State *L) {
lua_pushnil(L);
while(lua_next(L, -2)) {
header->key = c_strdup(lua_tostring(L, -2));
header->value = c_strdup(lua_tostring(L, -1));
header->key = strdup(lua_tostring(L, -2));
header->value = strdup(lua_tostring(L, -1));
header++;
lua_pop(L, 1);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment