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

Fix windows vs2022 problems #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ json get {
{ "name": "first" },
{ "name": "second" },
{ "name": "third" }
}
]
}
} foo end-1 name
~~~
Expand Down
84 changes: 42 additions & 42 deletions generic/api.c
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
#include "rl_jsonInt.h"
#include "parser.h"

Tcl_Obj* JSON_NewJSONObj(Tcl_Interp* interp, Tcl_Obj* from) //{{{
DLLEXPORT Tcl_Obj* JSON_NewJSONObj(Tcl_Interp* interp, Tcl_Obj* from) //{{{
{
return as_json(interp, from);
}

//}}}
int JSON_NewJStringObj(Tcl_Interp* interp, Tcl_Obj* string, Tcl_Obj** new) //{{{
DLLEXPORT int JSON_NewJStringObj(Tcl_Interp* interp, Tcl_Obj* string, Tcl_Obj**new_obj) //{{{
{
replace_tclobj(new, JSON_NewJvalObj(JSON_STRING, string));
replace_tclobj(new_obj, JSON_NewJvalObj(JSON_STRING, string));

return TCL_OK;
}

//}}}
int JSON_NewJNumberObj(Tcl_Interp* interp, Tcl_Obj* number, Tcl_Obj** new) //{{{
DLLEXPORT int JSON_NewJNumberObj(Tcl_Interp* interp, Tcl_Obj* number, Tcl_Obj**new_obj) //{{{
{
Tcl_Obj* forced = NULL;
struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
struct interp_cx* l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json",NULL);

TEST_OK(force_json_number(interp, l, number, &forced));
replace_tclobj(new, JSON_NewJvalObj(JSON_NUMBER, forced));
replace_tclobj(new_obj, JSON_NewJvalObj(JSON_NUMBER, forced));
release_tclobj(&forced);

return TCL_OK;
}

//}}}
int JSON_NewJBooleanObj(Tcl_Interp* interp, Tcl_Obj* boolean, Tcl_Obj** new) //{{{
DLLEXPORT int JSON_NewJBooleanObj(Tcl_Interp* interp, Tcl_Obj* boolean, Tcl_Obj**new_obj) //{{{
{
struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
int bool;
struct interp_cx* l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json", NULL);
int bool_value;

TEST_OK(Tcl_GetBooleanFromObj(interp, boolean, &bool));
replace_tclobj(new, bool ? l->json_true : l->json_false);
TEST_OK(Tcl_GetBooleanFromObj(interp, boolean, &bool_value));
replace_tclobj(new_obj,bool_value? l->json_true : l->json_false);

return TCL_OK;
}

//}}}
int JSON_NewJNullObj(Tcl_Interp* interp, Tcl_Obj* *new) //{{{
DLLEXPORT int JSON_NewJNullObj(Tcl_Interp* interp, Tcl_Obj* *new_obj) //{{{
{
struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
struct interp_cx* l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json", NULL);

replace_tclobj(new, l->json_null);
replace_tclobj(new_obj, l->json_null);

return TCL_OK;
}

//}}}
int JSON_NewJObjectObj(Tcl_Interp* interp, Tcl_Obj** new) //{{{
DLLEXPORT int JSON_NewJObjectObj(Tcl_Interp* interp, Tcl_Obj**new_obj) //{{{
{
struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
struct interp_cx* l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json", NULL);

replace_tclobj(new, JSON_NewJvalObj(JSON_OBJECT, l->tcl_empty_dict));
replace_tclobj(new_obj, JSON_NewJvalObj(JSON_OBJECT, l->tcl_empty_dict));

return TCL_OK;
}

//}}}
int JSON_NewJArrayObj(Tcl_Interp* interp, int objc, Tcl_Obj* objv[], Tcl_Obj** new) //{{{
DLLEXPORT int JSON_NewJArrayObj(Tcl_Interp* interp, int objc, Tcl_Obj* objv[], Tcl_Obj**new_obj) //{{{
{
struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
struct interp_cx* l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json", NULL);

if (objc == 0) {
replace_tclobj(new, JSON_NewJvalObj(JSON_OBJECT, l->tcl_empty_list));
replace_tclobj(new_obj, JSON_NewJvalObj(JSON_OBJECT, l->tcl_empty_list));
} else {
int i;

for (i=0; i<objc; i++) TEST_OK(JSON_ForceJSON(interp, objv[i]));

replace_tclobj(new, JSON_NewJvalObj(JSON_OBJECT, Tcl_NewListObj(objc, objv)));
replace_tclobj(new_obj, JSON_NewJvalObj(JSON_OBJECT, Tcl_NewListObj(objc, objv)));
}

return TCL_OK;
}

//}}}
int JSON_NewTemplateObj(Tcl_Interp* interp, enum json_types type, Tcl_Obj* key, Tcl_Obj** new) //{{{
DLLEXPORT int JSON_NewTemplateObj(Tcl_Interp* interp, enum json_types type, Tcl_Obj* key, Tcl_Obj**new_obj) //{{{
{
if (!type_is_dynamic(type)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf("Requested type is not a valid template type: %s", type_names_int[type]));
return TCL_ERROR;
}

replace_tclobj(new, JSON_NewJvalObj(type, key));
replace_tclobj(new_obj, JSON_NewJvalObj(type, key));

return TCL_OK;
}

//}}}
int JSON_ForceJSON(Tcl_Interp* interp, Tcl_Obj* obj) // Force a conversion to a JSON objtype, or throw an exception {{{
DLLEXPORT int JSON_ForceJSON(Tcl_Interp* interp, Tcl_Obj* obj) // Force a conversion to a JSON objtype, or throw an exception {{{
{
Tcl_ObjIntRep* ir;
enum json_types type;
Expand All @@ -106,12 +106,12 @@ int JSON_ForceJSON(Tcl_Interp* interp, Tcl_Obj* obj) // Force a conversion to a
enum json_types JSON_GetJSONType(Tcl_Obj* obj) //{{{
{
Tcl_ObjIntRep* ir = NULL;
enum json_types t;
int t;

for (t=JSON_OBJECT; t<JSON_TYPE_MAX && ir==NULL; t++)
ir = Tcl_FetchIntRep(obj, g_objtype_for_type[t]);

return (ir == NULL) ? JSON_UNDEF : t-1;
return (ir == NULL) ? JSON_UNDEF : (enum json_types)(t-1);
}

//}}}
Expand Down Expand Up @@ -276,7 +276,7 @@ int JSON_SetJArrayObj(Tcl_Interp* interp, Tcl_Obj* obj, const int objc, Tcl_Obj*
return TCL_ERROR;
}

jov = ckalloc(sizeof(Tcl_Obj*) * objc);
jov = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj*) * objc);
for (i=0; i<objc; i++)
Tcl_IncrRefCount(jov[i] = as_json(interp, objv[i]));

Expand Down Expand Up @@ -347,7 +347,7 @@ int JSON_JArrayObjReplace(Tcl_Interp* interp, Tcl_Obj* arrayObj, int first, int
return TCL_ERROR;
}

jov = ckalloc(sizeof(Tcl_Obj*) * objc);
jov =(Tcl_Obj **)ckalloc(sizeof(Tcl_Obj*) * objc);
for (i=0; i<objc; i++)
Tcl_IncrRefCount(jov[i] = as_json(interp, objv[i]));

Expand Down Expand Up @@ -413,7 +413,7 @@ int JSON_Extract(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj* path, Tcl_Obj** res)
//}}}
int JSON_Exists(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj* path, int* exists) //{{{
{
struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
struct interp_cx* l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json", NULL);
Tcl_Obj* target = NULL;
Tcl_Obj** pathv = NULL;
int pathc;
Expand Down Expand Up @@ -936,7 +936,7 @@ int JSON_Pretty(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj* indent, Tcl_Obj** pre
int retval = TCL_OK;
Tcl_DString ds;
Tcl_Obj* pad = NULL;
struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
struct interp_cx* l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json", NULL);

if (indent == NULL)
replace_tclobj(&indent, get_string(l, " ", 4));
Expand All @@ -956,26 +956,26 @@ int JSON_Pretty(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj* indent, Tcl_Obj** pre
}

//}}}
int JSON_Template(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj* dict, Tcl_Obj** res) //{{{
int JSON_Template(Tcl_Interp* interp, Tcl_Obj*template_obj, Tcl_Obj* dict, Tcl_Obj** res) //{{{
{
//struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
//struct interp_cx* l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json", NULL);
Tcl_Obj* actions = NULL;
int retcode = TCL_OK;
Tcl_ObjIntRep* ir;
enum json_types type;

TEST_OK(JSON_GetIntrepFromObj(interp, template, &type, &ir));
TEST_OK(JSON_GetIntrepFromObj(interp, template_obj, &type, &ir));

replace_tclobj(&actions, ir->twoPtrValue.ptr2);
replace_tclobj(&actions,(Tcl_Obj *) ir->twoPtrValue.ptr2);
if (actions == NULL) {
//DBG("Building template actions and storing in intrep ptr2 for %s\n", name(template));
TEST_OK_LABEL(finally, retcode, build_template_actions(interp, template, &actions));
//DBG("Building template actions and storing in intrep ptr2 for %s\n", name(template_obj));
TEST_OK_LABEL(finally, retcode, build_template_actions(interp, template_obj, &actions));
replace_tclobj((Tcl_Obj**)&ir->twoPtrValue.ptr2, actions);
}

//DBG("template %s refcount before: %d\n", name(template), template->refCount);
retcode = apply_template_actions(interp, template, actions, dict, res);
//DBG("template %s refcount after: %d\n", name(template), template->refCount);
//DBG("template %s refcount before: %d\n", name(template_obj), template->refCount);
retcode = apply_template_actions(interp, template_obj, actions, dict, res);
//DBG("template %s refcount after: %d\n", name(template_obj), template->refCount);
release_tclobj(&actions);

finally:
Expand Down Expand Up @@ -1092,7 +1092,7 @@ int JSON_Keys(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj* path, Tcl_Obj** keyslis
//}}}
int JSON_Decode(Tcl_Interp* interp, Tcl_Obj* bytes, Tcl_Obj* encoding, Tcl_Obj** decodedstring) //{{{
{
struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
struct interp_cx* l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json", NULL);
Tcl_Obj* ov[4];
int i, retval;

Expand Down Expand Up @@ -1218,7 +1218,7 @@ int JSON_Foreach(Tcl_Interp* interp, Tcl_Obj* iterators, JSON_ForeachBody* body,
}

while (state->loop_num < state->max_loops) {
struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
struct interp_cx* l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json", NULL);
unsigned int j, k;
Tcl_Obj* loopvars = NULL;

Expand Down Expand Up @@ -1390,7 +1390,7 @@ int JSON_Valid(Tcl_Interp* interp, Tcl_Obj* json, int* valid, enum extensions ex
struct parse_context cx[CX_STACK_SIZE];

if (interp)
l = Tcl_GetAssocData(interp, "rl_json", NULL);
l = (struct interp_cx *) Tcl_GetAssocData(interp, "rl_json", NULL);

#if 1
// Snoop on the intrep for clues on optimized conversions {{{
Expand Down
32 changes: 16 additions & 16 deletions generic/json_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Tcl_ObjType* g_objtype_for_type[JSON_TYPE_MAX];

int JSON_IsJSON(Tcl_Obj* obj, enum json_types* type, Tcl_ObjIntRep** ir) //{{{
{
enum json_types t;
int t;
Tcl_ObjIntRep* _ir = NULL;

for (t=JSON_OBJECT; t<JSON_TYPE_MAX && _ir==NULL; t++)
Expand All @@ -168,7 +168,7 @@ int JSON_IsJSON(Tcl_Obj* obj, enum json_types* type, Tcl_ObjIntRep** ir) //{{{
return 0;

*ir = _ir;
*type = t;
*type = (enum json_types)t;
return 1;
}

Expand Down Expand Up @@ -198,7 +198,7 @@ int JSON_GetJvalFromObj(Tcl_Interp* interp, Tcl_Obj* obj, enum json_types* type,

TEST_OK(JSON_GetIntrepFromObj(interp, obj, type, &ir));

*val = ir->twoPtrValue.ptr1;
*val =(Tcl_Obj *)(ir->twoPtrValue.ptr1);

return TCL_OK;
}
Expand All @@ -224,7 +224,7 @@ int JSON_SetIntRep(Tcl_Obj* target, enum json_types type, Tcl_Obj* replacement)
TEMPLATE_TYPE(str, len, template_type);

if (template_type != type) {
replace_tclobj(&rep, Tcl_NewStringObj(str, strend - str)); // TODO: dedup?
replace_tclobj(&rep, Tcl_NewStringObj(str,(int)(strend - str))); // TODO: dedup?
type = template_type;
}
}
Expand Down Expand Up @@ -343,7 +343,7 @@ static void dup_internal_rep(Tcl_Obj* src, Tcl_Obj* dest, Tcl_ObjType* objtype)
int oc;
// The list type's internal structure sharing on duplicates messes up our sharing,
// rather recreate a fresh list referencing the original element objects instead
if (TCL_OK != Tcl_ListObjGetElements(NULL, srcir->twoPtrValue.ptr1, &oc, &ov))
if (TCL_OK != Tcl_ListObjGetElements(NULL,(Tcl_Obj *) srcir->twoPtrValue.ptr1, &oc, &ov))
Tcl_Panic("Unable to retrieve the array elements from the shadow Tcl list while duplicating json array object");
destir.twoPtrValue.ptr1 = Tcl_NewListObj(oc, ov);
} else {
Expand Down Expand Up @@ -379,7 +379,7 @@ static void update_string_rep(Tcl_Obj* obj, Tcl_ObjType* objtype) //{{{
serialize(NULL, &scx, obj);

obj->length = Tcl_DStringLength(&ds);
obj->bytes = ckalloc(obj->length + 1);
obj->bytes = (char* )ckalloc(obj->length + 1);
memcpy(obj->bytes, Tcl_DStringValue(&ds), obj->length);
obj->bytes[obj->length] = 0;

Expand Down Expand Up @@ -416,7 +416,7 @@ static void update_string_rep_number(Tcl_Obj* obj) //{{{
Tcl_Panic("Turtles all the way down!");

str = Tcl_GetStringFromObj((Tcl_Obj*)ir->twoPtrValue.ptr1, &len);
obj->bytes = ckalloc(len+1);
obj->bytes =(char*) ckalloc(len+1);
memcpy(obj->bytes, str, len+1);
obj->length = len;
}
Expand All @@ -431,11 +431,11 @@ static void update_string_rep_bool(Tcl_Obj* obj) //{{{
Tcl_Panic("json_bool's intrep tclobj is not a boolean");

if (boolval) {
obj->bytes = ckalloc(5);
obj->bytes =(char*)ckalloc(5);
memcpy(obj->bytes, "true", 5);
obj->length = 4;
} else {
obj->bytes = ckalloc(6);
obj->bytes =(char*)ckalloc(6);
memcpy(obj->bytes, "false", 6);
obj->length = 5;
}
Expand All @@ -444,7 +444,7 @@ static void update_string_rep_bool(Tcl_Obj* obj) //{{{
//}}}
static void update_string_rep_null(Tcl_Obj* obj) //{{{
{
obj->bytes = ckalloc(5);
obj->bytes =(char*)ckalloc(5);
memcpy(obj->bytes, "null", 5);
obj->length = 4;
}
Expand Down Expand Up @@ -490,7 +490,7 @@ static int set_from_any(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_ObjType** objtype,
struct parse_error details = {0};

if (interp)
l = Tcl_GetAssocData(interp, "rl_json", NULL);
l = (struct interp_cx *)Tcl_GetAssocData(interp, "rl_json", NULL);

#if 1
// Snoop on the intrep for clues on optimized conversions {{{
Expand Down Expand Up @@ -562,8 +562,8 @@ static int set_from_any(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_ObjType** objtype,
* in the dict key. The template generation code reparses it later.
*/
{
Tcl_Obj* new = Tcl_ObjPrintf("~%c:%s", key_start[2], Tcl_GetString(val));
replace_tclobj(&val, new);
Tcl_Obj* new_obj = Tcl_ObjPrintf("~%c:%s", key_start[2], Tcl_GetString(val));
replace_tclobj(&val, new_obj);
// Can do this because val's ref is on loan from new_stringobj_dedup
//val = Tcl_ObjPrintf("~%c:%s", key_start[2], Tcl_GetString(val));
}
Expand Down Expand Up @@ -715,7 +715,7 @@ static int set_from_any(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_ObjType** objtype,
Tcl_Panic("Can't get intrep for the top container");

// We're transferring the ref from cx[0].val to our intrep
replace_tclobj((Tcl_Obj**)&ir.twoPtrValue.ptr1, top_ir->twoPtrValue.ptr1);
replace_tclobj((Tcl_Obj**)&ir.twoPtrValue.ptr1, (Tcl_Obj* )top_ir->twoPtrValue.ptr1);
release_tclobj((Tcl_Obj**)&ir.twoPtrValue.ptr2);
release_tclobj(&cx[0].val);

Expand Down Expand Up @@ -759,7 +759,7 @@ int type_is_dynamic(const enum json_types type) //{{{
Tcl_Obj* get_unshared_val(Tcl_ObjIntRep* ir) //{{{
{
if (ir->twoPtrValue.ptr1 != NULL && Tcl_IsShared((Tcl_Obj*)ir->twoPtrValue.ptr1))
replace_tclobj((Tcl_Obj**)&ir->twoPtrValue.ptr1, Tcl_DuplicateObj(ir->twoPtrValue.ptr1));
replace_tclobj((Tcl_Obj**)&ir->twoPtrValue.ptr1, Tcl_DuplicateObj((Tcl_Obj *)ir->twoPtrValue.ptr1));

if (ir->twoPtrValue.ptr2) {
// The caller wants val unshared, which implies that they intend to
Expand All @@ -768,7 +768,7 @@ Tcl_Obj* get_unshared_val(Tcl_ObjIntRep* ir) //{{{
release_tclobj((Tcl_Obj**)&ir->twoPtrValue.ptr2);
}

return ir->twoPtrValue.ptr1;
return (Tcl_Obj *)ir->twoPtrValue.ptr1;
}

//}}}
Expand Down
Loading