Reduced LUAL_BUFFERSIZE to 256. Should free up some stack (#1530)

This commit is contained in:
Philip Gladstone 2016-10-16 08:18:03 -04:00 committed by Marcel Stör
parent 880bd9850b
commit f9533ed85a
4 changed files with 12 additions and 19 deletions

View File

@ -343,28 +343,19 @@ static int read_line (lua_State *L, int f) {
static int read_line (lua_State *L, int f) { static int read_line (lua_State *L, int f) {
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
char *p = luaL_prepbuffer(&b); signed char c;
signed char c = EOF; do {
int i = 0;
do{
c = (signed char)vfs_getc(f); c = (signed char)vfs_getc(f);
if(c==EOF){ if (c==EOF) {
break; break;
} }
p[i++] = c; if (c != '\n') {
}while((c!=EOF) && (c!='\n') && (i<LUAL_BUFFERSIZE) ); luaL_addchar(&b, c);
}
} while (c != '\n');
if(i>0 && p[i-1] == '\n')
i--; /* do not include `eol' */
if(i==0){
luaL_pushresult(&b); /* close buffer */
return (lua_objlen(L, -1) > 0); /* check whether read something */
}
luaL_addsize(&b, i);
luaL_pushresult(&b); /* close buffer */ luaL_pushresult(&b); /* close buffer */
return 1; /* read at least an `eol' */ return (lua_objlen(L, -1) > 0); /* check whether read something */
} }
#endif #endif

View File

@ -556,7 +556,7 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
** For example: If set to 4K a call to string.gsub will need more than ** For example: If set to 4K a call to string.gsub will need more than
** 5k C stack space. ** 5k C stack space.
*/ */
#define LUAL_BUFFERSIZE BUFSIZ #define LUAL_BUFFERSIZE 256
/* }================================================================== */ /* }================================================================== */

View File

@ -134,6 +134,8 @@ static int ow_read_bytes( lua_State *L )
if( size == 0 ) if( size == 0 )
return 0; return 0;
luaL_argcheck(L, size <= LUAL_BUFFERSIZE, 2, "Attempt to read too many characters");
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit( L, &b ); luaL_buffinit( L, &b );
char *p = luaL_prepbuffer(&b); char *p = luaL_prepbuffer(&b);

View File

@ -84,7 +84,7 @@ Reads multi bytes.
#### Parameters #### Parameters
- `pin` 1~12, I/O index - `pin` 1~12, I/O index
- `size` number of bytes to be read from slave device - `size` number of bytes to be read from slave device (up to 256)
#### Returns #### Returns
`string` bytes read from slave device `string` bytes read from slave device