Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch kext to use GVAR_FUNC_*ARGS #31

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions src/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static UChar * outputUnicodeChar(UChar * s, UInt val)
return s;
}

Obj JSON_ESCAPE_STRING(Obj self, Obj param)
static Obj FuncJSON_ESCAPE_STRING(Obj self, Obj param)
{
if(!IS_STRING(param))
{
Expand Down Expand Up @@ -241,7 +241,7 @@ void JSON_AppendCStr(Obj str, const char * buf, UInt len)
CHARS_STRING(str)[newlen] = '\0'; // add terminator
}

Obj GAP_LIST_TO_JSON_STRING(Obj self, Obj string, Obj stream, Obj list) {
static Obj FuncGAP_LIST_TO_JSON_STRING(Obj self, Obj string, Obj stream, Obj list) {
RequireDenseList("list", list);
Int len = LEN_LIST(list);
char buf[50] = {};
Expand All @@ -258,7 +258,7 @@ Obj GAP_LIST_TO_JSON_STRING(Obj self, Obj string, Obj stream, Obj list) {
snprintf(buf, sizeof(buf), "%ld", INT_INTOBJ(val));
JSON_AppendCStr(string, buf, strlen(buf));
} else if(IS_LIST(val) && !(IS_STRING(val))) {
GAP_LIST_TO_JSON_STRING(self, string, stream, val);
FuncGAP_LIST_TO_JSON_STRING(self, string, stream, val);
} else {
CALL_2ARGS(_GapToJsonStreamInternal, stream, val);
// Convert back in case this call modified the string
Expand Down Expand Up @@ -350,7 +350,7 @@ struct CleanupCacheGuard
{ callGAPFunction(ClearGAPCacheFunction); }
};

Obj JSON_STREAM_TO_GAP(Obj self, Obj stream)
static Obj FuncJSON_STREAM_TO_GAP(Obj self, Obj stream)
{
JSON_setupGAPFunctions();
CleanupCacheGuard ccg;
Expand Down Expand Up @@ -414,7 +414,7 @@ static GapStringToInputIterator endGapStringIterator(Obj obj)
return g;
}

Obj JSON_STRING_TO_GAP(Obj self, Obj param)
static Obj FuncJSON_STRING_TO_GAP(Obj self, Obj param)
{
JSON_setupGAPFunctions();
CleanupCacheGuard ccg;
Expand Down Expand Up @@ -473,20 +473,12 @@ Obj JSON_STRING_TO_GAP(Obj self, Obj param)
return JsonToGap(v);
}

typedef Obj (* GVarFunc)(/*arguments*/);

#define GVAR_FUNC_TABLE_ENTRY(srcfile, name, nparam, params) \
{#name, nparam, \
params, \
(GVarFunc)name, \
srcfile ":Func" #name }

// Table of functions to export
static StructGVarFunc GVarFuncs [] = {
GVAR_FUNC_TABLE_ENTRY("json.c", JSON_STRING_TO_GAP, 1, "string"),
GVAR_FUNC_TABLE_ENTRY("json.c", JSON_ESCAPE_STRING, 1, "string"),
GVAR_FUNC_TABLE_ENTRY("json.c", JSON_STREAM_TO_GAP, 1, "string"),
GVAR_FUNC_TABLE_ENTRY("json.c", GAP_LIST_TO_JSON_STRING, 3, "string, stream, list"),
GVAR_FUNC_1ARGS(JSON_STRING_TO_GAP, string),
GVAR_FUNC_1ARGS(JSON_ESCAPE_STRING, string),
GVAR_FUNC_1ARGS(JSON_STREAM_TO_GAP, string),
GVAR_FUNC_3ARGS(GAP_LIST_TO_JSON_STRING, string, stream, list),

{ 0 } /* Finish with an empty entry */

Expand Down
Loading