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
...@@ -8,11 +8,7 @@ ...@@ -8,11 +8,7 @@
#ifndef lobject_h #ifndef lobject_h
#define lobject_h #define lobject_h
#ifdef LUA_CROSS_COMPILER
#include <stdarg.h> #include <stdarg.h>
#else
#include "c_stdarg.h"
#endif
#include "llimits.h" #include "llimits.h"
#include "lua.h" #include "lua.h"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#define LUAC_CROSS_FILE #define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING #include <string.h>
#include "lcode.h" #include "lcode.h"
#include "ldebug.h" #include "ldebug.h"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define LUAC_CROSS_FILE #define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING #include <string.h>
#include "lrotable.h" #include "lrotable.h"
#include "lauxlib.h" #include "lauxlib.h"
#include "lstring.h" #include "lstring.h"
...@@ -100,7 +100,7 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) { ...@@ -100,7 +100,7 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) {
unsigned l = key ? key->tsv.len : sizeof("__metatable")-1; unsigned l = key ? key->tsv.len : sizeof("__metatable")-1;
if (pentry) { if (pentry) {
if (j >= 0 && !c_strcmp(pentry[j].key, strkey)) { if (j >= 0 && !strcmp(pentry[j].key, strkey)) {
if (ppos) if (ppos)
*ppos = j; *ppos = j;
//dbg_printf("%3d hit %p %s\n", (hash>>2) & (LA_LINES-1), rotable, strkey); //dbg_printf("%3d hit %p %s\n", (hash>>2) & (LA_LINES-1), rotable, strkey);
...@@ -112,11 +112,11 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) { ...@@ -112,11 +112,11 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) {
* is included so a "on\0" has a mask of 0xFFFFFF and "a\0" has 0xFFFF. * is included so a "on\0" has a mask of 0xFFFFFF and "a\0" has 0xFFFF.
*/ */
unsigned name4, mask4 = l > 2 ? (~0u) : (~0u)>>((3-l)*8); unsigned name4, mask4 = l > 2 ? (~0u) : (~0u)>>((3-l)*8);
c_memcpy(&name4, strkey, sizeof(name4)); memcpy(&name4, strkey, sizeof(name4));
for(;pentry->key != NULL; i++, pentry++) { for(;pentry->key != NULL; i++, pentry++) {
if (((*(unsigned *)pentry->key ^ name4) & mask4) == 0 && if (((*(unsigned *)pentry->key ^ name4) & mask4) == 0 &&
!c_strcmp(pentry->key, strkey)) { !strcmp(pentry->key, strkey)) {
//dbg_printf("%p %s hit after %d probes \n", rotable, strkey, (int)(rotable-pentry)); //dbg_printf("%p %s hit after %d probes \n", rotable, strkey, (int)(rotable-pentry));
if (ppos) if (ppos)
*ppos = i; *ppos = i;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#define LUAC_CROSS_FILE #define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING #include <string.h>
#include "lmem.h" #include "lmem.h"
#include "lobject.h" #include "lobject.h"
...@@ -67,7 +67,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, ...@@ -67,7 +67,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l,
ts->tsv.marked = luaC_white(G(L)); ts->tsv.marked = luaC_white(G(L));
ts->tsv.tt = LUA_TSTRING; ts->tsv.tt = LUA_TSTRING;
if (!readonly) { if (!readonly) {
c_memcpy(ts+1, str, l*sizeof(char)); memcpy(ts+1, str, l*sizeof(char));
((char *)(ts+1))[l] = '\0'; /* ending 0 */ ((char *)(ts+1))[l] = '\0'; /* ending 0 */
} else { } else {
*(char **)(ts+1) = (char *)str; *(char **)(ts+1) = (char *)str;
...@@ -106,7 +106,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { ...@@ -106,7 +106,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
o != NULL; o != NULL;
o = o->gch.next) { o = o->gch.next) {
TString *ts = rawgco2ts(o); TString *ts = rawgco2ts(o);
if (ts->tsv.len == l && (c_memcmp(str, getstr(ts), l) == 0)) { if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
/* string may be dead */ /* string may be dead */
if (isdead(G(L), o)) changewhite(o); if (isdead(G(L), o)) changewhite(o);
return ts; return ts;
...@@ -131,7 +131,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { ...@@ -131,7 +131,7 @@ LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
/* New additions to the RAM strt are tagged as readonly if the string address /* New additions to the RAM strt are tagged as readonly if the string address
* is in the CTEXT segment (target only, not luac.cross) */ * is in the CTEXT segment (target only, not luac.cross) */
int readonly = (lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) && int readonly = (lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) &&
l == c_strlen(str) ? LUAS_READONLY_STRING : LUAS_REGULAR_STRING); l == strlen(str) ? LUAS_READONLY_STRING : LUAS_REGULAR_STRING);
return newlstr(L, str, l, h, readonly); /* not found */ return newlstr(L, str, l, h, readonly); /* not found */
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#define sizeudata(u) (sizeof(union Udata)+(u)->len) #define sizeudata(u) (sizeof(union Udata)+(u)->len)
#define luaS_new(L, s) (luaS_newlstr(L, s, c_strlen(s))) #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
(sizeof(s)/sizeof(char))-1)) (sizeof(s)/sizeof(char))-1))
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#define LUAC_CROSS_FILE #define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STDIO #include <stdio.h>
#include C_HEADER_STRING #include <string.h>
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
...@@ -352,7 +352,7 @@ static const char *match_capture (MatchState *ms, const char *s, int l) { ...@@ -352,7 +352,7 @@ static const char *match_capture (MatchState *ms, const char *s, int l) {
l = check_capture(ms, l); l = check_capture(ms, l);
len = ms->capture[l].len; len = ms->capture[l].len;
if ((size_t)(ms->src_end-s) >= len && if ((size_t)(ms->src_end-s) >= len &&
c_memcmp(ms->capture[l].init, s, len) == 0) memcmp(ms->capture[l].init, s, len) == 0)
return s+len; return s+len;
else return NULL; else return NULL;
} }
...@@ -447,7 +447,7 @@ static const char *lmemfind (const char *s1, size_t l1, ...@@ -447,7 +447,7 @@ static const char *lmemfind (const char *s1, size_t l1,
l1 = l1-l2; /* `s2' cannot be found after that */ l1 = l1-l2; /* `s2' cannot be found after that */
while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {
init++; /* 1st char is already checked */ init++; /* 1st char is already checked */
if (c_memcmp(init, s2+1, l2) == 0) if (memcmp(init, s2+1, l2) == 0)
return init-1; return init-1;
else { /* correct `l1' and `s1' to try again */ else { /* correct `l1' and `s1' to try again */
l1 -= init-s1; l1 -= init-s1;
...@@ -496,7 +496,7 @@ static int str_find_aux (lua_State *L, int find) { ...@@ -496,7 +496,7 @@ static int str_find_aux (lua_State *L, int find) {
if (init < 0) init = 0; if (init < 0) init = 0;
else if ((size_t)(init) > l1) init = (ptrdiff_t)l1; else if ((size_t)(init) > l1) init = (ptrdiff_t)l1;
if (find && (lua_toboolean(L, 4) || /* explicit request? */ if (find && (lua_toboolean(L, 4) || /* explicit request? */
c_strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */ strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
/* do a plain search */ /* do a plain search */
const char *s2 = lmemfind(s+init, l1-init, p, l2); const char *s2 = lmemfind(s+init, l1-init, p, l2);
if (s2) { if (s2) {
...@@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { ...@@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
const char *p = strfrmt; const char *p = strfrmt;
while (*p != '\0' && c_strchr(FLAGS, *p) != NULL) p++; /* skip flags */ while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
luaL_error(L, "invalid format (repeated flags)"); luaL_error(L, "invalid format (repeated flags)");
if (isdigit(uchar(*p))) p++; /* skip width */ if (isdigit(uchar(*p))) p++; /* skip width */
...@@ -736,7 +736,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { ...@@ -736,7 +736,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
if (isdigit(uchar(*p))) if (isdigit(uchar(*p)))
luaL_error(L, "invalid format (width or precision too long)"); luaL_error(L, "invalid format (width or precision too long)");
*(form++) = '%'; *(form++) = '%';
c_strncpy(form, strfrmt, p - strfrmt + 1); strncpy(form, strfrmt, p - strfrmt + 1);
form += p - strfrmt + 1; form += p - strfrmt + 1;
*form = '\0'; *form = '\0';
return p; return p;
...@@ -744,9 +744,9 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { ...@@ -744,9 +744,9 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
static void addintlen (char *form) { static void addintlen (char *form) {
size_t l = c_strlen(form); size_t l = strlen(form);
char spec = form[l - 1]; char spec = form[l - 1];
c_strcpy(form + l - 1, LUA_INTFRMLEN); strcpy(form + l - 1, LUA_INTFRMLEN);
form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
} }
...@@ -773,23 +773,23 @@ static int str_format (lua_State *L) { ...@@ -773,23 +773,23 @@ static int str_format (lua_State *L) {
strfrmt = scanformat(L, strfrmt, form); strfrmt = scanformat(L, strfrmt, form);
switch (*strfrmt++) { switch (*strfrmt++) {
case 'c': { case 'c': {
c_sprintf(buff, form, (int)luaL_checknumber(L, arg)); sprintf(buff, form, (int)luaL_checknumber(L, arg));
break; break;
} }
case 'd': case 'i': { case 'd': case 'i': {
addintlen(form); addintlen(form);
c_sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg)); sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
break; break;
} }
case 'o': case 'u': case 'x': case 'X': { case 'o': case 'u': case 'x': case 'X': {
addintlen(form); addintlen(form);
c_sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg)); sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
break; break;
} }
#if !defined LUA_NUMBER_INTEGRAL #if !defined LUA_NUMBER_INTEGRAL
case 'e': case 'E': case 'f': case 'e': case 'E': case 'f':
case 'g': case 'G': { case 'g': case 'G': {
c_sprintf(buff, form, (double)luaL_checknumber(L, arg)); sprintf(buff, form, (double)luaL_checknumber(L, arg));
break; break;
} }
#endif #endif
...@@ -800,7 +800,7 @@ static int str_format (lua_State *L) { ...@@ -800,7 +800,7 @@ static int str_format (lua_State *L) {
case 's': { case 's': {
size_t l; size_t l;
const char *s = luaL_checklstring(L, arg, &l); const char *s = luaL_checklstring(L, arg, &l);
if (!c_strchr(form, '.') && l >= 100) { if (!strchr(form, '.') && l >= 100) {
/* no precision and string is too long to be formatted; /* no precision and string is too long to be formatted;
keep original string */ keep original string */
lua_pushvalue(L, arg); lua_pushvalue(L, arg);
...@@ -808,7 +808,7 @@ static int str_format (lua_State *L) { ...@@ -808,7 +808,7 @@ static int str_format (lua_State *L) {
continue; /* skip the `addsize' at the end */ continue; /* skip the `addsize' at the end */
} }
else { else {
c_sprintf(buff, form, s); sprintf(buff, form, s);
break; break;
} }
} }
...@@ -817,7 +817,7 @@ static int str_format (lua_State *L) { ...@@ -817,7 +817,7 @@ static int str_format (lua_State *L) {
LUA_QL("format"), *(strfrmt - 1)); LUA_QL("format"), *(strfrmt - 1));
} }
} }
luaL_addlstring(&b, buff, c_strlen(buff)); luaL_addlstring(&b, buff, strlen(buff));
} }
} }
luaL_pushresult(&b); luaL_pushresult(&b);
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
#define LUAC_CROSS_FILE #define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_MATH #include <math.h>
#include C_HEADER_STRING #include <string.h>
#include "ldebug.h" #include "ldebug.h"
#include "ldo.h" #include "ldo.h"
...@@ -86,7 +86,7 @@ static Node *hashnum (const Table *t, lua_Number n) { ...@@ -86,7 +86,7 @@ static Node *hashnum (const Table *t, lua_Number n) {
int i; int i;
if (luai_numeq(n, 0)) /* avoid problems with -0 */ if (luai_numeq(n, 0)) /* avoid problems with -0 */
return gnode(t, 0); return gnode(t, 0);
c_memcpy(a, &n, sizeof(a)); memcpy(a, &n, sizeof(a));
for (i = 1; i < numints; i++) a[0] += a[i]; for (i = 1; i < numints; i++) a[0] += a[i];
return hashmod(t, a[0]); return hashmod(t, a[0]);
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#define LUAC_CROSS_FILE #define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING #include <string.h>
#include "lobject.h" #include "lobject.h"
#include "lstate.h" #include "lstate.h"
......
...@@ -5,10 +5,9 @@ ...@@ -5,10 +5,9 @@
*/ */
// #include "c_signal.h" #include <stdio.h>
#include "c_stdio.h" #include <stdlib.h>
#include "c_stdlib.h" #include <string.h>
#include "c_string.h"
#include "user_interface.h" #include "user_interface.h"
#include "user_version.h" #include "user_version.h"
#include "driver/readline.h" #include "driver/readline.h"
...@@ -32,9 +31,9 @@ static const char *progname = LUA_PROGNAME; ...@@ -32,9 +31,9 @@ static const char *progname = LUA_PROGNAME;
static void l_message (const char *pname, const char *msg) { static void l_message (const char *pname, const char *msg) {
#if defined(LUA_USE_STDIO) #if defined(LUA_USE_STDIO)
if (pname) c_fprintf(c_stderr, "%s: ", pname); if (pname) fprintf(c_stderr, "%s: ", pname);
c_fprintf(c_stderr, "%s\n", msg); fprintf(c_stderr, "%s\n", msg);
c_fflush(c_stderr); fflush(c_stderr);
#else #else
if (pname) luai_writestringerror("%s: ", pname); if (pname) luai_writestringerror("%s: ", pname);
luai_writestringerror("%s\n", msg); luai_writestringerror("%s\n", msg);
...@@ -122,7 +121,7 @@ static int dofsfile (lua_State *L, const char *name) { ...@@ -122,7 +121,7 @@ static int dofsfile (lua_State *L, const char *name) {
static int dostring (lua_State *L, const char *s, const char *name) { static int dostring (lua_State *L, const char *s, const char *name) {
int status = luaL_loadbuffer(L, s, c_strlen(s), name) || docall(L, 0, 1); int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
return report(L, status); return report(L, status);
} }
...@@ -148,7 +147,7 @@ static int incomplete (lua_State *L, int status) { ...@@ -148,7 +147,7 @@ static int incomplete (lua_State *L, int status) {
size_t lmsg; size_t lmsg;
const char *msg = lua_tolstring(L, -1, &lmsg); const char *msg = lua_tolstring(L, -1, &lmsg);
const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1); const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
if (c_strstr(msg, LUA_QL("<eof>")) == tp) { if (strstr(msg, LUA_QL("<eof>")) == tp) {
lua_pop(L, 1); lua_pop(L, 1);
return 1; return 1;
} }
...@@ -214,7 +213,7 @@ static int runargs (lua_State *L, char **argv, int n) { ...@@ -214,7 +213,7 @@ static int runargs (lua_State *L, char **argv, int n) {
int memlimit=0; int memlimit=0;
if (*limit == '\0') limit = argv[++i]; if (*limit == '\0') limit = argv[++i];
lua_assert(limit != NULL); lua_assert(limit != NULL);
memlimit = c_atoi(limit); memlimit = atoi(limit);
lua_gc(L, LUA_GCSETMEMLIMIT, memlimit); lua_gc(L, LUA_GCSETMEMLIMIT, memlimit);
break; break;
} }
...@@ -307,7 +306,7 @@ int lua_main (int argc, char **argv) { ...@@ -307,7 +306,7 @@ int lua_main (int argc, char **argv) {
gLoad.L = L; gLoad.L = L;
gLoad.firstline = 1; gLoad.firstline = 1;
gLoad.done = 0; gLoad.done = 0;
gLoad.line = c_malloc(LUA_MAXINPUT); gLoad.line = malloc(LUA_MAXINPUT);
gLoad.len = LUA_MAXINPUT; gLoad.len = LUA_MAXINPUT;
gLoad.line_position = 0; gLoad.line_position = 0;
gLoad.prmt = get_prompt(L, 1); gLoad.prmt = get_prompt(L, 1);
...@@ -324,7 +323,7 @@ int lua_main (int argc, char **argv) { ...@@ -324,7 +323,7 @@ int lua_main (int argc, char **argv) {
int lua_put_line(const char *s, size_t l) { int lua_put_line(const char *s, size_t l) {
if (s == NULL || ++l > LUA_MAXINPUT || gLoad.line_position > 0) if (s == NULL || ++l > LUA_MAXINPUT || gLoad.line_position > 0)
return 0; return 0;
c_memcpy(gLoad.line, s, l); memcpy(gLoad.line, s, l);
gLoad.line[l] = '\0'; gLoad.line[l] = '\0';
gLoad.line_position = l; gLoad.line_position = l;
gLoad.done = 1; gLoad.done = 1;
...@@ -336,7 +335,7 @@ void lua_handle_input (bool force) ...@@ -336,7 +335,7 @@ void lua_handle_input (bool force)
{ {
while (gLoad.L && (force || readline (&gLoad))) { while (gLoad.L && (force || readline (&gLoad))) {
NODE_DBG("Handle Input: first=%u, pos=%u, len=%u, actual=%u, line=%s\n", gLoad.firstline, NODE_DBG("Handle Input: first=%u, pos=%u, len=%u, actual=%u, line=%s\n", gLoad.firstline,
gLoad.line_position, gLoad.len, c_strlen(gLoad.line), gLoad.line); gLoad.line_position, gLoad.len, strlen(gLoad.line), gLoad.line);
dojob (&gLoad); dojob (&gLoad);
force = false; force = false;
} }
...@@ -357,7 +356,7 @@ static void dojob(lua_Load *load){ ...@@ -357,7 +356,7 @@ static void dojob(lua_Load *load){
do{ do{
if(load->done == 1){ if(load->done == 1){
l = c_strlen(b); l = strlen(b);
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */ if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
b[l-1] = '\0'; /* remove it */ b[l-1] = '\0'; /* remove it */
if (load->firstline && b[0] == '=') /* first line starts with `=' ? */ if (load->firstline && b[0] == '=') /* first line starts with `=' ? */
...@@ -401,8 +400,8 @@ static void dojob(lua_Load *load){ ...@@ -401,8 +400,8 @@ static void dojob(lua_Load *load){
load->done = 0; load->done = 0;
load->line_position = 0; load->line_position = 0;
c_memset(load->line, 0, load->len); memset(load->line, 0, load->len);
c_puts(load->prmt); puts(load->prmt);
} }
#ifndef uart_putc #ifndef uart_putc
...@@ -468,7 +467,7 @@ static bool readline(lua_Load *load){ ...@@ -468,7 +467,7 @@ static bool readline(lua_Load *load){
if (load->line_position == 0) if (load->line_position == 0)
{ {
/* Get a empty line, then go to get a new line */ /* Get a empty line, then go to get a new line */
c_puts(load->prmt); puts(load->prmt);
continue; continue;
} else { } else {
load->done = 1; load->done = 1;
......
...@@ -11,16 +11,10 @@ ...@@ -11,16 +11,10 @@
#ifdef LUAC_CROSS_FILE #ifdef LUAC_CROSS_FILE
#include "luac_cross.h" #include "luac_cross.h"
#endif #endif
#ifdef LUA_CROSS_COMPILER #include <stdint.h>
#include <stdarg.h> #include "stdarg.h"
#include <stddef.h> #include "stddef.h"
#include <ctype.h> #include "ctype.h"
#else
#include "c_stdarg.h"
#include "c_stddef.h"
#include "c_types.h"
#include <ctype.h>
#endif
#include "luaconf.h" #include "luaconf.h"
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
summary ?= @true summary ?= @true
CCFLAGS:= -I.. -I../../include -I../../libc -I../../uzlib CCFLAGS:= -I.. -I../../include -I../../uzlib
LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile
CCFLAGS += -Wall CCFLAGS += -Wall
...@@ -33,13 +33,12 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c ...@@ -33,13 +33,12 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c
lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c \ lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c \
lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c \ lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c \
ltm.c lundump.c lvm.c lzio.c ltm.c lundump.c lvm.c lzio.c
LIBCSRC := c_stdlib.c
UZSRC := uzlib_deflate.c crc32.c UZSRC := uzlib_deflate.c crc32.c
# #
# This relies on the files being unique on the vpath # This relies on the files being unique on the vpath
# #
SRC := $(LUACSRC) $(LUASRC) $(LIBCSRC) $(UZSRC) SRC := $(LUACSRC) $(LUASRC) $(UZSRC)
vpath %.c .:..:../../libc:../../uzlib vpath %.c .:..:../../libc:../../uzlib
ODIR := .output/$(TARGET)/$(FLAVOR)/obj ODIR := .output/$(TARGET)/$(FLAVOR)/obj
......
...@@ -38,12 +38,11 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c ...@@ -38,12 +38,11 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c
lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c \ lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c \
lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c \ lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c \
ltm.c lundump.c lvm.c lzio.c ltm.c lundump.c lvm.c lzio.c
LIBCSRC := c_stdlib.c
UZSRC := uzlib_deflate.c crc32.c UZSRC := uzlib_deflate.c crc32.c
# #
# This relies on the files being unique on the vpath # This relies on the files being unique on the vpath
# #
SRC := $(LUACSRC) $(LUASRC) $(LIBCSRC) $(UZSRC) SRC := $(LUACSRC) $(LUASRC) $(UZSRC)
vpath %.c .:..:../../libc:../../uzlib vpath %.c .:..:../../libc:../../uzlib
......
...@@ -8,13 +8,9 @@ ...@@ -8,13 +8,9 @@
#ifndef lconfig_h #ifndef lconfig_h
#define lconfig_h #define lconfig_h
#ifdef LUA_CROSS_COMPILER
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
#else #include <stdbool.h>
#include "c_limits.h"
#include "c_stddef.h"
#endif
#include "user_config.h" #include "user_config.h"
/* /*
...@@ -262,11 +258,7 @@ ...@@ -262,11 +258,7 @@
#define lua_stdin_is_tty() isatty(0) #define lua_stdin_is_tty() isatty(0)
#elif defined(LUA_WIN) #elif defined(LUA_WIN)
#include <io.h> #include <io.h>
#ifdef LUA_CROSS_COMPILER
#include <stdio.h> #include <stdio.h>
#else
#include "c_stdio.h"
#endif
#define lua_stdin_is_tty() _isatty(_fileno(stdin)) #define lua_stdin_is_tty() _isatty(_fileno(stdin))
#else #else
...@@ -317,11 +309,11 @@ ...@@ -317,11 +309,11 @@
#define lua_saveline(L,idx) \ #define lua_saveline(L,idx) \
if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
add_history(lua_tostring(L, idx)); /* add it to history */ add_history(lua_tostring(L, idx)); /* add it to history */
#define lua_freeline(L,b) ((void)L, c_free(b)) #define lua_freeline(L,b) ((void)L, free(b))
#else // #if defined(LUA_CROSS_COMPILER) && defined(LUA_USE_READLINE) #else // #if defined(LUA_CROSS_COMPILER) && defined(LUA_USE_READLINE)
#define lua_readline(L,b,p) \ #define lua_readline(L,b,p) \
((void)L, c_fputs(p, c_stdout), c_fflush(c_stdout), /* show prompt */ \ ((void)L, fputs(p, c_stdout), fflush(c_stdout), /* show prompt */ \
c_fgets(b, LUA_MAXINPUT, c_stdin) != NULL) /* get line */ fgets(b, LUA_MAXINPUT, c_stdin) != NULL) /* get line */
#define lua_saveline(L,idx) { (void)L; (void)idx; } #define lua_saveline(L,idx) { (void)L; (void)idx; }
#define lua_freeline(L,b) { (void)L; (void)b; } #define lua_freeline(L,b) { (void)L; (void)b; }
#endif // #if defined(LUA_USE_READLINE) #endif // #if defined(LUA_USE_READLINE)
...@@ -342,8 +334,8 @@ extern int readline4lua(const char *prompt, char *buffer, int length); ...@@ -342,8 +334,8 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
** avoids including 'stdio.h' everywhere.) ** avoids including 'stdio.h' everywhere.)
*/ */
#if !defined(LUA_USE_STDIO) #if !defined(LUA_USE_STDIO)
#define luai_writestring(s, l) c_puts(s) #define luai_writestring(s, l) puts(s)
#define luai_writeline() c_puts("\n") #define luai_writeline() puts("\n")
#endif // defined(LUA_USE_STDIO) #endif // defined(LUA_USE_STDIO)
/* /*
...@@ -622,31 +614,23 @@ extern int readline4lua(const char *prompt, char *buffer, int length); ...@@ -622,31 +614,23 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
#define LUA_NUMBER_SCAN "%lf" #define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g" #define LUA_NUMBER_FMT "%.14g"
#endif // #if defined LUA_NUMBER_INTEGRAL #endif // #if defined LUA_NUMBER_INTEGRAL
#define lua_number2str(s,n) c_sprintf((s), LUA_NUMBER_FMT, (n)) #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
#if defined LUA_NUMBER_INTEGRAL #if defined LUA_NUMBER_INTEGRAL
#if !defined LUA_INTEGRAL_LONGLONG #if !defined LUA_INTEGRAL_LONGLONG
#define lua_str2number(s,p) c_strtol((s), (p), 10) #define lua_str2number(s,p) strtol((s), (p), 10)
#else #else
#define lua_str2number(s,p) c_strtoll((s), (p), 10) #define lua_str2number(s,p) strtoll((s), (p), 10)
#endif // #if !defined LUA_INTEGRAL_LONGLONG #endif // #if !defined LUA_INTEGRAL_LONGLONG
#else #else
#ifdef _MSC_VER //what's wrong with stdlib strtod?
#define lua_str2number(s,p) strtod((s), (p)) #define lua_str2number(s,p) strtod((s), (p))
#else
#define lua_str2number(s,p) c_strtod((s), (p))
#endif
#endif // #if defined LUA_NUMBER_INTEGRAL #endif // #if defined LUA_NUMBER_INTEGRAL
/* /*
@@ The luai_num* macros define the primitive operations over numbers. @@ The luai_num* macros define the primitive operations over numbers.
*/ */
#if defined(LUA_CORE) || defined(LUA_LIB) #if defined(LUA_CORE) || defined(LUA_LIB)
#ifdef LUA_CROSS_COMPILER
#include <math.h> #include <math.h>
#else
#include "c_math.h"
#endif
#define luai_numadd(a,b) ((a)+(b)) #define luai_numadd(a,b) ((a)+(b))
#define luai_numsub(a,b) ((a)-(b)) #define luai_numsub(a,b) ((a)-(b))
#define luai_nummul(a,b) ((a)*(b)) #define luai_nummul(a,b) ((a)*(b))
...@@ -801,7 +785,7 @@ union luai_Cast { double l_d; long l_l; }; ...@@ -801,7 +785,7 @@ union luai_Cast { double l_d; long l_l; };
#include <unistd.h> #include <unistd.h>
#define LUA_TMPNAMBUFSIZE 32 #define LUA_TMPNAMBUFSIZE 32
#define lua_tmpnam(b,e) { \ #define lua_tmpnam(b,e) { \
c_strcpy(b, "/tmp/lua_XXXXXX"); \ strcpy(b, "/tmp/lua_XXXXXX"); \
e = mkstemp(b); \ e = mkstemp(b); \
if (e != -1) close(e); \ if (e != -1) close(e); \
e = (e == -1); } e = (e == -1); }
...@@ -821,7 +805,7 @@ union luai_Cast { double l_d; long l_l; }; ...@@ -821,7 +805,7 @@ union luai_Cast { double l_d; long l_l; };
*/ */
#if defined(LUA_USE_POPEN) #if defined(LUA_USE_POPEN)
#define lua_popen(L,c,m) ((void)L, c_fflush(NULL), popen(c,m)) #define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
#define lua_pclose(L,file) ((void)L, (pclose(file) != -1)) #define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
#elif defined(LUA_WIN) #elif defined(LUA_WIN)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#define LUAC_CROSS_FILE #define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING #include <string.h>
#include "ldebug.h" #include "ldebug.h"
#include "ldo.h" #include "ldo.h"
...@@ -309,7 +309,7 @@ static void LoadHeader(LoadState* S) ...@@ -309,7 +309,7 @@ static void LoadHeader(LoadState* S)
S->numsize=h[10]=s[10]; /* length of lua_Number */ S->numsize=h[10]=s[10]; /* length of lua_Number */
S->toflt=(s[11]>intck); /* check if conversion from int lua_Number to flt is needed */ S->toflt=(s[11]>intck); /* check if conversion from int lua_Number to flt is needed */
if(S->toflt) s[11]=h[11]; if(S->toflt) s[11]=h[11];
IF (c_memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header"); IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
} }
/* /*
...@@ -338,7 +338,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name) ...@@ -338,7 +338,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
void luaU_header (char* h) void luaU_header (char* h)
{ {
int x=1; int x=1;
c_memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1); memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
h+=sizeof(LUA_SIGNATURE)-1; h+=sizeof(LUA_SIGNATURE)-1;
*h++=(char)LUAC_VERSION; *h++=(char)LUAC_VERSION;
*h++=(char)LUAC_FORMAT; *h++=(char)LUAC_FORMAT;
......
...@@ -7,11 +7,7 @@ ...@@ -7,11 +7,7 @@
#ifndef lundump_h #ifndef lundump_h
#define lundump_h #define lundump_h
#ifdef LUA_CROSS_COMPILER
#include <stdint.h> #include <stdint.h>
#else
#include "c_stdint.h"
#endif
#include "lobject.h" #include "lobject.h"
#include "lzio.h" #include "lzio.h"
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
#define LUAC_CROSS_FILE #define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STDIO #include <stdio.h>
#include C_HEADER_STRING #include <string.h>
#include C_HEADER_MATH #include <math.h>
#include "ldebug.h" #include "ldebug.h"
#include "ldo.h" #include "ldo.h"
...@@ -252,10 +252,10 @@ static int l_strcmp (const TString *ls, const TString *rs) { ...@@ -252,10 +252,10 @@ static int l_strcmp (const TString *ls, const TString *rs) {
const char *r = getstr(rs); const char *r = getstr(rs);
size_t lr = rs->tsv.len; size_t lr = rs->tsv.len;
for (;;) { for (;;) {
int temp = c_strcoll(l, r); int temp = strcoll(l, r);
if (temp != 0) return temp; if (temp != 0) return temp;
else { /* strings are equal up to a `\0' */ else { /* strings are equal up to a `\0' */
size_t len = c_strlen(l); /* index of first `\0' in both strings */ size_t len = strlen(l); /* index of first `\0' in both strings */
if (len == lr) /* r is finished? */ if (len == lr) /* r is finished? */
return (len == ll) ? 0 : 1; return (len == ll) ? 0 : 1;
else if (len == ll) /* l is finished? */ else if (len == ll) /* l is finished? */
...@@ -363,7 +363,7 @@ void luaV_concat (lua_State *L, int total, int last) { ...@@ -363,7 +363,7 @@ void luaV_concat (lua_State *L, int total, int last) {
tl = 0; tl = 0;
for (i=n; i>0; i--) { /* concat all strings */ for (i=n; i>0; i--) { /* concat all strings */
size_t l = tsvalue(top-i)->len; size_t l = tsvalue(top-i)->len;
c_memcpy(buffer+tl, svalue(top-i), l); memcpy(buffer+tl, svalue(top-i), l);
tl += l; tl += l;
} }
setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl)); setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#define LUAC_CROSS_FILE #define LUAC_CROSS_FILE
#include "lua.h" #include "lua.h"
#include C_HEADER_STRING #include <string.h>
#include "llimits.h" #include "llimits.h"
#include "lmem.h" #include "lmem.h"
...@@ -62,7 +62,7 @@ size_t luaZ_read (ZIO *z, void *b, size_t n) { ...@@ -62,7 +62,7 @@ size_t luaZ_read (ZIO *z, void *b, size_t n) {
return n; /* return number of missing bytes */ return n; /* return number of missing bytes */
m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
if (b) if (b)
c_memcpy(b, z->p, m); memcpy(b, z->p, m);
z->n -= m; z->n -= m;
z->i += m; z->i += m;
z->p += m; z->p += m;
......
...@@ -25,15 +25,6 @@ ...@@ -25,15 +25,6 @@
#include MBEDTLS_CONFIG_FILE #include MBEDTLS_CONFIG_FILE
#endif #endif
// XXX Espressif are hacks sometimes. This is BS, but is taken from
// the mbedtls platform.c from their SDK. Really, this should go
// somewhere else. Note that the prototype here for vPortFree differs (!)
// from the one in sdk-overrides.h. That's above my pay grade.
// --nwf; 2018 Feb 18
extern void *pvPortCalloc(unsigned int count, unsigned int size);
extern void vPortFree( void *pv );
#if defined(MBEDTLS_PLATFORM_C) #if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
......
#include <stdlib.h>
void *mbedtls_calloc(size_t n, size_t sz) { return calloc(n, sz); }
void mbedtls_free(void *p) { free(p); }
#include <stdlib.h>
void *mbedtls_calloc_wrap(size_t n, size_t sz) { return calloc(n, sz); }
void mbedtls_free_wrap(void *p) { free(p); }
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