Skip to content

Commit

Permalink
Bytecode now disables in standards mode; fixed CI
Browse files Browse the repository at this point in the history
  • Loading branch information
MCJack123 committed Dec 7, 2023
1 parent 9cdfae4 commit 5da725f
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 73 deletions.
4 changes: 4 additions & 0 deletions CraftOS-PC 2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<DisableSpecificWarnings>26812;4005</DisableSpecificWarnings>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
Expand Down Expand Up @@ -420,6 +421,7 @@
<LanguageStandard_C>stdc11</LanguageStandard_C>
<DisableSpecificWarnings>26812;4005</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
Expand Down Expand Up @@ -471,6 +473,7 @@
<LanguageStandard_C>stdc11</LanguageStandard_C>
<DisableSpecificWarnings>26812;4005</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
Expand Down Expand Up @@ -522,6 +525,7 @@
<LanguageStandard_C>stdc17</LanguageStandard_C>
<DisableSpecificWarnings>26812;4005</DisableSpecificWarnings>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
</ClCompile>
<ProjectReference>
<LinkLibraryDependencies>false</LinkLibraryDependencies>
Expand Down
2 changes: 1 addition & 1 deletion craftos2-lua
10 changes: 5 additions & 5 deletions examples/ccemux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ static int ccemux_getVersion(lua_State *L) {

static int ccemux_openEmu(lua_State *L) {
Computer * comp = get_comp(L);
int id = 0;
int id = luaL_optinteger(L, 1, -1);
if (lua_isnumber(L, 1)) id = (int)lua_tointeger(L, 1);
else if (!lua_isnoneornil(L, 1)) luaL_typerror(L, 1, "number");
else {
if (id < 0) {
std::lock_guard<std::mutex> lock(comp->peripherals_mutex);
id = 0;
while (functions->getComputerById(id) != NULL) id++;
}
if (functions->attachPeripheral(comp, "computer_" + std::to_string(id), "computer", NULL, "") == NULL) lua_pushnil(L);
Expand Down Expand Up @@ -233,7 +233,7 @@ static int ccemux_detach(lua_State *L) {
return 0;
}

static struct luaL_reg M[] = {
static struct luaL_Reg M[] = {
{"getVersion", ccemux_getVersion},
{"openEmu", ccemux_openEmu},
{"closeEmu", ccemux_closeEmu},
Expand All @@ -252,7 +252,7 @@ static PluginInfo info("ccemux", 3);

extern "C" {
DLLEXPORT int luaopen_ccemux(lua_State *L) {
luaL_register(L, lua_tostring(L, 1), M);
luaL_newlib(L, M);
functions->addVirtualMount(get_comp(L), emuROM, "/rom");
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/plugin_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {

// add your functions here...

static luaL_reg M[] = {
static luaL_Reg M[] = {
// add functions here as {name, function}...
{NULL, NULL}
};
Expand All @@ -26,7 +26,7 @@ static PluginInfo info("myplugin");
extern "C" {
// replace "myplugin" with the plugin name
DLLEXPORT int luaopen_myplugin(lua_State *L) {
luaL_register(L, "myplugin", M);
luaL_newlib(L, M);
return 1;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ void runComputer(Computer * self, const path_t& bios_name, const std::string& bi
// Override the default loader to allow yielding from `load`
lua_pushcfunction(L, yieldable_load);
lua_setglobal(L, "load");
// Disable bytecode
lua_setdisableflags(L, LUA_DISABLE_BYTECODE);
}

// Load any plugins available
Expand Down
4 changes: 4 additions & 0 deletions src/apis/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ static int config_set(lua_State *L) {
setConfigSetting(monitorsUseMouseEvents, boolean);
setConfigSettingI(defaultWidth);
setConfigSettingI(defaultHeight);
else if (strcmp(name, "standardsMode") == 0) {
config.standardsMode = lua_toboolean(L, 2);
lua_setdisableflags(L, config.standardsMode ? LUA_DISABLE_BYTECODE : 0);
}
setConfigSetting(standardsMode, boolean);
setConfigSetting(useHardwareRenderer, boolean);
else if (strcmp(name, "preferredHardwareDriver") == 0)
Expand Down
14 changes: 2 additions & 12 deletions src/apis/handles/http_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,11 @@
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPServerResponse.h>
#include <Poco/Net/HTTPServerRequest.h>
#include "http_handle.hpp"
#include "../../util.hpp"
#include "http_handle.hpp"

using namespace Poco::Net;

struct http_handle_t {
std::string url;
HTTPClientSession * session;
HTTPResponse * handle;
std::istream * stream;
bool isBinary;
std::string failureReason;
http_handle_t(std::istream * s) : stream(s) {}
};

struct http_res {
std::string body;
HTTPServerResponse * res;
Expand Down Expand Up @@ -82,7 +72,7 @@ int http_handle_readLine(lua_State *L) {
if (retval.empty() && handle->stream->eof()) return 0;
if (lua_toboolean(L, 1)) retval += '\n';
else if (!retval.empty() && retval[retval.size()-1] == '\r') retval = retval.substr(0, retval.size()-1);
const std::string out = handle->isBinary ? retval : makeASCIISafe(retval.c_str(), retval.size());
const std::string out = retval;
lua_pushlstring(L, out.c_str(), out.length());
return 1;
}
Expand Down
8 changes: 8 additions & 0 deletions src/apis/handles/http_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
extern "C" {
#include <lua.h>
}
struct http_handle_t {
std::string url;
std::string failureReason;
Poco::Net::HTTPClientSession * session;
Poco::Net::HTTPResponse * handle;
std::istream * stream;
http_handle_t(std::istream * s) : stream(s) {}
};
extern int http_handle_free(lua_State *L);
extern int http_handle_close(lua_State *L);
extern int http_handle_readAll(lua_State *L);
Expand Down
27 changes: 13 additions & 14 deletions src/apis/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
#include <Poco/Net/HTTPServerRequest.h>
#include <Poco/Net/HTTPServerResponse.h>
#include <Poco/Net/HTTPServer.h>
#include "handles/http_handle.hpp"
#include "../platform.hpp"
#include "../runtime.hpp"
#include "../util.hpp"
#include "handles/http_handle.hpp"

#ifdef __ANDROID__
extern "C" {extern int Android_JNI_SetupThread(void);}
Expand All @@ -58,15 +58,6 @@ struct http_param_t {
double timeout;
};

struct http_handle_t {
std::string url;
HTTPClientSession * session;
HTTPResponse * handle;
std::istream * stream;
std::string failureReason;
http_handle_t(std::istream * s): stream(s) {}
};

struct http_check_t {
std::string url;
std::string status;
Expand Down Expand Up @@ -254,12 +245,20 @@ static void downloadThread(void* arg) {
else if (uri.getScheme() == "http") {
session = new HTTPClientSession(uri.getHost(), uri.getPort());
} else if (uri.getScheme() == "https") {
Context::Ptr context = new Context(Context::CLIENT_USE, "", Context::VERIFY_RELAXED, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
addSystemCertificates(context);
try {
Context::Ptr context = new Context(Context::CLIENT_USE, "", Context::VERIFY_RELAXED, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
addSystemCertificates(context);
#if POCO_VERSION >= 0x010A0000
context->disableProtocols(Context::PROTO_TLSV1_3); // Some sites break under TLS 1.3 - disable it to maintain compatibility until fixed (pocoproject/poco#3395)
context->disableProtocols(Context::PROTO_TLSV1_3); // Some sites break under TLS 1.3 - disable it to maintain compatibility until fixed (pocoproject/poco#3395)
#endif
session = new HTTPSClientSession(uri.getHost(), uri.getPort(), context);
session = new HTTPSClientSession(uri.getHost(), uri.getPort(), context);
} catch (Poco::Exception &e) {
http_handle_t * err = new http_handle_t(NULL);
err->url = param->url;
err->failureReason = e.message();
queueEvent(param->comp, http_failure, err);
goto downloadThread_finish;
}
} else status = "Invalid protocol '" + uri.getScheme() + "'";
}
if (!status.empty()) {
Expand Down
60 changes: 21 additions & 39 deletions src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,46 +139,28 @@ class Value {
};

// For get_comp
typedef union {
void *gc;
void *p;
lua_Number n;
int b;
} lua_Value;

typedef struct lua_TValue {
lua_Value value; int tt;
} TValue;

struct lua_State {
void *next;
unsigned char tt;
unsigned char marked;
unsigned char status;
void* top; /* first free slot in the stack */
void* base; /* base of current function */
void *l_G;
void *ci; /* call info for current function */
void* ctx; /* `savedpc' of current function, or context */
void* stack_last; /* last free slot in the stack */
void* stack; /* stack base */
void *end_ci; /* points after end of ci array*/
void *base_ci; /* array of CallInfo's */
int stacksize;
int size_ci; /* size of array `base_ci' */
unsigned short nCcalls; /* number of nested C calls */
unsigned short baseCcalls; /* nested C calls when resuming coroutine */
unsigned char hookmask;
unsigned char allowhook;
int basehookcount;
int hookcount;
lua_Hook hook;
TValue l_gt; /* table of globals */
TValue env; /* temporary place for environments */
void *openupval; /* list of open upvalues in this stack */
void *gclist;
struct lua_longjmp *errorJmp; /* current error recover point */
ptrdiff_t errfunc; /* current error handling function (stack index) */
void *next; uint8_t tt; uint8_t marked;
uint8_t status;
void* top; /* first free slot in the stack */
void* l_G;
void *ci; /* call info for current function */
const int *oldpc; /* last pc traced */
void* stack_last; /* last free slot in the stack */
void* stack; /* stack base */
int stacksize;
unsigned short nny; /* number of non-yieldable calls in stack */
unsigned short nCcalls; /* number of nested C calls */
uint8_t hookmask;
uint8_t allowhook;
int basehookcount;
int hookcount;
lua_Hook hook;
void *openupval; /* list of open upvalues in this stack */
void *gclist;
struct lua_longjmp *errorJmp; /* current error recover point */
ptrdiff_t errfunc; /* current error handling function (stack index) */
void* base_ci; /* CallInfo for first level (C calling Lua) */
};

inline int log2i(int num) {
Expand Down

0 comments on commit 5da725f

Please sign in to comment.