1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Make funcfiftlib compilation compatible with modern compilers (#618)

* wip: make funcfiftlib compilation compatible with modern compilers

* wip: add methods needed for another compiler

* fix: tdutils port config if emscripten

* feat: func source and realpath callback

* fix: invalid fift compilation exceptions

---------

Co-authored-by: krigga <krigga7@gmail.com>
This commit is contained in:
Dan Volkov 2023-03-09 18:37:15 +04:00 committed by GitHub
parent 82e231d0a7
commit 4590ed381b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 142 additions and 31 deletions

View file

@ -30,6 +30,7 @@
#include "td/utils/JsonBuilder.h"
#include "fift/utils.h"
#include "td/utils/base64.h"
#include "td/utils/Status.h"
#include <sstream>
#include <iomanip>
@ -99,6 +100,40 @@ td::Result<std::string> compile_internal(char *config_json) {
return result_json.string_builder().as_cslice().str();
}
/// Callback used to retrieve additional source files or data.
///
/// @param _kind The kind of callback (a string).
/// @param _data The data for the callback (a string).
/// @param o_contents A pointer to the contents of the file, if found. Allocated via malloc().
/// @param o_error A pointer to an error message, if there is one. Allocated via malloc().
///
/// The callback implementor must use malloc() to allocate storage for
/// contents or error. The callback implementor must use free() to free
/// said storage after func_compile returns.
///
/// If the callback is not supported, *o_contents and *o_error must be set to NULL.
typedef void (*CStyleReadFileCallback)(char const* _kind, char const* _data, char** o_contents, char** o_error);
funC::ReadCallback::Callback wrapReadCallback(CStyleReadFileCallback _readCallback)
{
funC::ReadCallback::Callback readCallback;
if (_readCallback) {
readCallback = [=](funC::ReadCallback::Kind _kind, char const* _data) -> td::Result<std::string> {
char* contents_c = nullptr;
char* error_c = nullptr;
_readCallback(funC::ReadCallback::kindString(_kind).data(), _data, &contents_c, &error_c);
if (!contents_c && !error_c) {
return td::Status::Error("Callback not supported");
}
if (contents_c) {
return contents_c;
}
return td::Status::Error(std::string(error_c));
};
}
return readCallback;
}
extern "C" {
const char* version() {
@ -111,7 +146,13 @@ const char* version() {
return strdup(version_json.string_builder().as_cslice().c_str());
}
const char *func_compile(char *config_json) {
const char *func_compile(char *config_json, CStyleReadFileCallback callback) {
if (callback) {
funC::read_callback = wrapReadCallback(callback);
} else {
funC::read_callback = funC::fs_read_callback;
}
auto res = compile_internal(config_json);
if (res.is_error()) {