From e347779446d675c3287b1bddf55237c22ac2d009 Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 18 Apr 2016 06:46:35 -0500 Subject: [PATCH 1/5] fix various typos and incompletely apply very lightweight formatting normalization (continued) --- doc/source/stdlib/stdstringlib.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/source/stdlib/stdstringlib.rst b/doc/source/stdlib/stdstringlib.rst index be92e5c..9078d39 100644 --- a/doc/source/stdlib/stdstringlib.rst +++ b/doc/source/stdlib/stdstringlib.rst @@ -57,7 +57,7 @@ Global Symbols .. js:function:: startswith(str, cmp) - returns `true` if the beginning of the string `str` matches a the string `cmp` otherwise returns `false` + returns `true` if the beginning of the string `str` matches the string `cmp`; otherwise returns `false` .. js:function:: strip(str) @@ -162,13 +162,13 @@ The regexp class .. js:function:: regexp.capture(str [, start]) - returns an array of tables containing two indexs("begin" and "end")of + returns an array of tables containing two indexes ("begin" and "end") of the first match of the regular expression in the string `str`. An array entry is created for each captured sub expressions. If no match occurs returns null. The search starts from the index `start` - of the string, if `start` is omitted the search starts from the beginning of the string. + of the string; if `start` is omitted the search starts from the beginning of the string. - the first element of the returned array(index 0) always contains the complete match. + The first element of the returned array(index 0) always contains the complete match. :: @@ -197,7 +197,7 @@ The regexp class returns a table containing two indexes ("begin" and "end") of the first match of the regular expression in the string `str`, otherwise if no match occurs returns null. The search starts from the index `start` - of the string, if `start` is omitted the search starts from the beginning of the string. + of the string; if `start` is omitted the search starts from the beginning of the string. :: @@ -290,7 +290,7 @@ Regular Expessions searches the first match of the expression in the string delimited by the parameter text_begin and text_end. - if the match is found returns SQTrue and the sets out_begin to the beginning of the + if the match is found returns SQTrue and sets out_begin to the beginning of the match and out_end at the end of the match; otherwise returns SQFalse. .. c:function:: SQInteger sqstd_rex_getsubexpcount(SQRex * exp) @@ -305,7 +305,7 @@ Regular Expessions :param SQRex* exp: a compiled expression :param SQInteger n: the index of the submatch(0 is the complete match) :param SQRexMatch* a: pointer to structure that will store the result - :returns: the function returns SQTrue if n is valid index otherwise SQFalse. + :returns: the function returns SQTrue if n is a valid index; otherwise SQFalse. retrieve the begin and and pointer to the length of the sub expression indexed by n. The result is passed through the struct SQRexMatch. From 7305257b9551f39a9e8562784e2d0fa60690c1f6 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 20 Apr 2016 20:50:53 -0500 Subject: [PATCH 2/5] tidy sq_setreleasehook and sq_getreleasehook --- squirrel/sqapi.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/squirrel/sqapi.cpp b/squirrel/sqapi.cpp index 5b3862e..d7b49eb 100644 --- a/squirrel/sqapi.cpp +++ b/squirrel/sqapi.cpp @@ -1199,29 +1199,24 @@ SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool wakeupret,SQBool retval,SQBool raiseer void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook) { - if(sq_gettop(v) >= 1){ - SQObjectPtr &ud=stack_get(v,idx); - switch( type(ud) ) { - case OT_USERDATA: _userdata(ud)->_hook = hook; break; - case OT_INSTANCE: _instance(ud)->_hook = hook; break; - case OT_CLASS: _class(ud)->_hook = hook; break; - default: break; //shutup compiler - } + SQObjectPtr &ud=stack_get(v,idx); + switch( type(ud) ) { + case OT_USERDATA: _userdata(ud)->_hook = hook; break; + case OT_INSTANCE: _instance(ud)->_hook = hook; break; + case OT_CLASS: _class(ud)->_hook = hook; break; + default: return; } } SQRELEASEHOOK sq_getreleasehook(HSQUIRRELVM v,SQInteger idx) { - if(sq_gettop(v) >= 1){ - SQObjectPtr &ud=stack_get(v,idx); - switch( type(ud) ) { - case OT_USERDATA: return _userdata(ud)->_hook; break; - case OT_INSTANCE: return _instance(ud)->_hook; break; - case OT_CLASS: return _class(ud)->_hook; break; - default: break; //shutup compiler - } + SQObjectPtr &ud=stack_get(v,idx); + switch( type(ud) ) { + case OT_USERDATA: return _userdata(ud)->_hook; break; + case OT_INSTANCE: return _instance(ud)->_hook; break; + case OT_CLASS: return _class(ud)->_hook; break; + default: return NULL; } - return NULL; } void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f) From 72135d9a7f4e0b2b5ca6f25e0de4171783f902cc Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 20 Apr 2016 21:05:06 -0500 Subject: [PATCH 3/5] SQStream should have a virtual dtor, to shut up warnings and probably for some good reason but i dont know --- include/sqstdio.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/sqstdio.h b/include/sqstdio.h index d19ec2e..fbc7451 100644 --- a/include/sqstdio.h +++ b/include/sqstdio.h @@ -7,6 +7,7 @@ #define SQSTD_STREAM_TYPE_TAG 0x80000000 struct SQStream { + virtual ~SQStream() {} virtual SQInteger Read(void *buffer, SQInteger size) = 0; virtual SQInteger Write(void *buffer, SQInteger size) = 0; virtual SQInteger Flush() = 0; From b9fc9317520586f281a52ec3613205cd6b2018d5 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 20 Apr 2016 21:19:24 -0500 Subject: [PATCH 4/5] add some stack-condition error checking to sqstdlib registration routines and to sqstd_dofile --- sqstdlib/sqstdio.cpp | 6 ++++++ sqstdlib/sqstdmath.cpp | 2 ++ sqstdlib/sqstdstring.cpp | 2 ++ sqstdlib/sqstdsystem.cpp | 2 ++ 4 files changed, 12 insertions(+) diff --git a/sqstdlib/sqstdio.cpp b/sqstdlib/sqstdio.cpp index 9aaaccb..83d2b66 100644 --- a/sqstdlib/sqstdio.cpp +++ b/sqstdlib/sqstdio.cpp @@ -399,6 +399,10 @@ SQRESULT sqstd_loadfile(HSQUIRRELVM v,const SQChar *filename,SQBool printerror) SQRESULT sqstd_dofile(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror) { + //at least one entry must exist in order for us to push it as the environment + if(sq_gettop(v) == 0) + return sq_throwerror(v,_SC("environment table expected")); + if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,printerror))) { sq_push(v,-2); if(SQ_SUCCEEDED(sq_call(v,1,retval,SQTrue))) { @@ -468,6 +472,8 @@ static const SQRegFunction iolib_funcs[]={ SQRESULT sqstd_register_iolib(HSQUIRRELVM v) { + if(sq_gettype(v,-1) != OT_TABLE) + return sq_throwerror(v,_SC("table expected")); SQInteger top = sq_gettop(v); //create delegate declare_stream(v,_SC("file"),(SQUserPointer)SQSTD_FILE_TYPE_TAG,_SC("std_file"),_file_methods,iolib_funcs); diff --git a/sqstdlib/sqstdmath.cpp b/sqstdlib/sqstdmath.cpp index c41ffd5..038ba5c 100644 --- a/sqstdlib/sqstdmath.cpp +++ b/sqstdlib/sqstdmath.cpp @@ -88,6 +88,8 @@ static const SQRegFunction mathlib_funcs[] = { SQRESULT sqstd_register_mathlib(HSQUIRRELVM v) { + if(sq_gettype(v,-1) != OT_TABLE) + return sq_throwerror(v,_SC("table expected")); SQInteger i=0; while(mathlib_funcs[i].name!=0) { sq_pushstring(v,mathlib_funcs[i].name,-1); diff --git a/sqstdlib/sqstdstring.cpp b/sqstdlib/sqstdstring.cpp index 5b8074b..8537891 100644 --- a/sqstdlib/sqstdstring.cpp +++ b/sqstdlib/sqstdstring.cpp @@ -473,6 +473,8 @@ static const SQRegFunction stringlib_funcs[]={ SQInteger sqstd_register_stringlib(HSQUIRRELVM v) { + if(sq_gettype(v,-1) != OT_TABLE) + return sq_throwerror(v,_SC("table expected")); sq_pushstring(v,_SC("regexp"),-1); sq_newclass(v,SQFalse); SQInteger i = 0; diff --git a/sqstdlib/sqstdsystem.cpp b/sqstdlib/sqstdsystem.cpp index b008a44..2b4190c 100644 --- a/sqstdlib/sqstdsystem.cpp +++ b/sqstdlib/sqstdsystem.cpp @@ -132,6 +132,8 @@ static const SQRegFunction systemlib_funcs[]={ SQInteger sqstd_register_systemlib(HSQUIRRELVM v) { + if(sq_gettype(v,-1) != OT_TABLE) + return sq_throwerror(v,_SC("table expected")); SQInteger i=0; while(systemlib_funcs[i].name!=0) { From 160184d2ddf0add44b20ba9065934b5646b1b03c Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 21 Apr 2016 21:52:13 -0500 Subject: [PATCH 5/5] Revert "add some stack-condition error checking to sqstdlib registration routines" This reverts part of commit b9fc9317520586f281a52ec3613205cd6b2018d5. --- sqstdlib/sqstdio.cpp | 2 -- sqstdlib/sqstdmath.cpp | 2 -- sqstdlib/sqstdstring.cpp | 2 -- sqstdlib/sqstdsystem.cpp | 2 -- 4 files changed, 8 deletions(-) diff --git a/sqstdlib/sqstdio.cpp b/sqstdlib/sqstdio.cpp index 83d2b66..84c225a 100644 --- a/sqstdlib/sqstdio.cpp +++ b/sqstdlib/sqstdio.cpp @@ -472,8 +472,6 @@ static const SQRegFunction iolib_funcs[]={ SQRESULT sqstd_register_iolib(HSQUIRRELVM v) { - if(sq_gettype(v,-1) != OT_TABLE) - return sq_throwerror(v,_SC("table expected")); SQInteger top = sq_gettop(v); //create delegate declare_stream(v,_SC("file"),(SQUserPointer)SQSTD_FILE_TYPE_TAG,_SC("std_file"),_file_methods,iolib_funcs); diff --git a/sqstdlib/sqstdmath.cpp b/sqstdlib/sqstdmath.cpp index 038ba5c..c41ffd5 100644 --- a/sqstdlib/sqstdmath.cpp +++ b/sqstdlib/sqstdmath.cpp @@ -88,8 +88,6 @@ static const SQRegFunction mathlib_funcs[] = { SQRESULT sqstd_register_mathlib(HSQUIRRELVM v) { - if(sq_gettype(v,-1) != OT_TABLE) - return sq_throwerror(v,_SC("table expected")); SQInteger i=0; while(mathlib_funcs[i].name!=0) { sq_pushstring(v,mathlib_funcs[i].name,-1); diff --git a/sqstdlib/sqstdstring.cpp b/sqstdlib/sqstdstring.cpp index 8537891..5b8074b 100644 --- a/sqstdlib/sqstdstring.cpp +++ b/sqstdlib/sqstdstring.cpp @@ -473,8 +473,6 @@ static const SQRegFunction stringlib_funcs[]={ SQInteger sqstd_register_stringlib(HSQUIRRELVM v) { - if(sq_gettype(v,-1) != OT_TABLE) - return sq_throwerror(v,_SC("table expected")); sq_pushstring(v,_SC("regexp"),-1); sq_newclass(v,SQFalse); SQInteger i = 0; diff --git a/sqstdlib/sqstdsystem.cpp b/sqstdlib/sqstdsystem.cpp index 2b4190c..b008a44 100644 --- a/sqstdlib/sqstdsystem.cpp +++ b/sqstdlib/sqstdsystem.cpp @@ -132,8 +132,6 @@ static const SQRegFunction systemlib_funcs[]={ SQInteger sqstd_register_systemlib(HSQUIRRELVM v) { - if(sq_gettype(v,-1) != OT_TABLE) - return sq_throwerror(v,_SC("table expected")); SQInteger i=0; while(systemlib_funcs[i].name!=0) {