diff --git a/README.md b/README.md index 564e017..cc8c7fe 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ json get { { "name": "first" }, { "name": "second" }, { "name": "third" } - } + ] } } foo end-1 name ~~~ diff --git a/generic/api.c b/generic/api.c index e303d62..31ed57e 100644 --- a/generic/api.c +++ b/generic/api.c @@ -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; itwoPtrValue.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: @@ -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; @@ -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; @@ -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 {{{ diff --git a/generic/json_types.c b/generic/json_types.c index ab9da7f..965d347 100644 --- a/generic/json_types.c +++ b/generic/json_types.c @@ -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; ttwoPtrValue.ptr1; + *val =(Tcl_Obj *)(ir->twoPtrValue.ptr1); return TCL_OK; } @@ -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; } } @@ -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 { @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -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 {{{ @@ -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)); } @@ -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); @@ -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 @@ -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; } //}}} diff --git a/generic/parser.c b/generic/parser.c index 6bd22af..fa38aaa 100644 --- a/generic/parser.c +++ b/generic/parser.c @@ -20,7 +20,7 @@ void throw_parse_error(Tcl_Interp* interp, struct parse_error* details) //{{{ { char char_ofs_buf[20]; // 20 bytes allows for 19 bytes of decimal max 64 bit size_t, plus null terminator - snprintf(char_ofs_buf, 20, "%ld", details->char_ofs); + snprintf(char_ofs_buf, 20, "%ld", (long)(details->char_ofs)); Tcl_SetObjResult(interp, Tcl_ObjPrintf("Error parsing JSON value: %s at offset %ld", details->errmsg, details->char_ofs)); Tcl_SetErrorCode(interp, "RL", "JSON", "PARSE", details->errmsg, details->doc, char_ofs_buf, NULL); @@ -30,39 +30,39 @@ void throw_parse_error(Tcl_Interp* interp, struct parse_error* details) //{{{ struct parse_context* push_parse_context(struct parse_context* cx, const enum json_types container, const size_t char_ofs) //{{{ { struct parse_context* last = cx->last; - struct parse_context* new; + struct parse_context* new_obj; if (last->container == JSON_UNDEF) { - new = last; + new_obj = last; } else if (likely((ptrdiff_t)last >= (ptrdiff_t)cx && (ptrdiff_t)last < (ptrdiff_t)(cx + CX_STACK_SIZE - 1))) { // Space remains on the cx array stack - new = cx->last+1; + new_obj= cx->last+1; } else { - new = (struct parse_context*)malloc(sizeof(*new)); + new_obj= (struct parse_context*)malloc(sizeof(*new_obj)); } - new->prev = last; + new_obj->prev = last; if (last->mode == VALIDATE) { - new->val = NULL; + new_obj->val = NULL; } else { Tcl_IncrRefCount( - new->val = JSON_NewJvalObj(container, container == JSON_OBJECT ? + new_obj->val = JSON_NewJvalObj(container, container == JSON_OBJECT ? (cx->l ? cx->l->tcl_empty_dict : Tcl_NewDictObj()) : (cx->l ? cx->l->tcl_empty_list : Tcl_NewListObj(0, NULL)) )); } - new->hold_key = NULL; - new->char_ofs = char_ofs; - new->container = container; - new->closed = 0; - new->objtype = g_objtype_for_type[container]; - new->l = last->l; - new->mode = last->mode; + new_obj->hold_key = NULL; + new_obj->char_ofs = char_ofs; + new_obj->container = container; + new_obj->closed = 0; + new_obj->objtype = g_objtype_for_type[container]; + new_obj->l = last->l; + new_obj->mode = last->mode; - cx->last = new; + cx->last = new_obj; - return new; + return new_obj; } //}}} @@ -283,12 +283,12 @@ int value_type(struct interp_cx* l, const unsigned char* doc, const unsigned cha len = p-chunk; if (likely(out == NULL)) { - replace_tclobj(&out, get_string(l, (const char*)chunk, len)); + replace_tclobj(&out, get_string(l, (const char*)chunk, (int)len)); } else if (len > 0) { if (unlikely(Tcl_IsShared(out))) replace_tclobj(&out, Tcl_DuplicateObj(out)); - Tcl_AppendToObj(out, (const char*)chunk, len); + Tcl_AppendToObj(out, (const char*)chunk, (int)len); } if (likely(*p == '"')) { @@ -458,7 +458,7 @@ append_mapped: Tcl_AppendToObj(out, &mapped, 1); // Weird, but arranged this *type = JSON_NUMBER; if (val) - replace_tclobj(val, get_string(l, (const char*)start, p-start)); + replace_tclobj(val, get_string(l, (const char*)start,(int)(p-start))); } } diff --git a/generic/rl_json.c b/generic/rl_json.c index 2c97878..8d52d2d 100644 --- a/generic/rl_json.c +++ b/generic/rl_json.c @@ -5,7 +5,9 @@ #endif #if defined(_WIN32) +#include #define snprintf _snprintf +#define unlink _unlink #endif static const char* dyn_prefix[] = { @@ -257,7 +259,7 @@ static void append_json_string(const struct serialize_context* scx, Tcl_Obj* obj while (p < e) { adv = Tcl_UtfToUniChar(p, &c); if (unlikely(c <= 0x1f || c == '\\' || c == '"')) { - Tcl_DStringAppend(ds, chunk, p-chunk); + Tcl_DStringAppend(ds, chunk, (int)(p-chunk)); switch (c) { case '"': Tcl_DStringAppend(ds, "\\\"", 2); break; case '\\': Tcl_DStringAppend(ds, "\\\\", 2); break; @@ -280,7 +282,7 @@ static void append_json_string(const struct serialize_context* scx, Tcl_Obj* obj } if (likely(p > chunk)) - Tcl_DStringAppend(ds, chunk, p-chunk); + Tcl_DStringAppend(ds, chunk, (int)(p-chunk)); Tcl_DStringAppend(ds, "\"", 1); } @@ -581,7 +583,7 @@ static int get_modifier(Tcl_Interp* interp, Tcl_Obj* modobj, enum modifiers* mod int index; TEST_OK(Tcl_GetIndexFromObj(interp, modobj, modstrings, "modifier", TCL_EXACT, &index)); - *modifier = index; + *modifier = (enum modifiers)index; return TCL_OK; } @@ -591,7 +593,7 @@ int resolve_path(Tcl_Interp* interp, Tcl_Obj* src, Tcl_Obj *const pathv[], int p { int i, modstrlen; enum json_types type; - struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL); + struct interp_cx* l = (struct interp_cx *)Tcl_GetAssocData(interp, "rl_json", NULL); const char* modstr; enum modifiers modifier; Tcl_Obj* val = NULL; @@ -725,9 +727,9 @@ int resolve_path(Tcl_Interp* interp, Tcl_Obj* src, Tcl_Obj *const pathv[], int p //}}} case JSON_OBJECT: //{{{ { - Tcl_Obj* new = NULL; - TEST_OK_LABEL(done, retval, Tcl_DictObjGet(interp, val, step, &new)); - replace_tclobj(&t, new); + Tcl_Obj* new_obj = NULL; + TEST_OK_LABEL(done, retval, Tcl_DictObjGet(interp, val, step, &new_obj)); + replace_tclobj(&t, new_obj); } if (t == NULL) { EXISTS(0); @@ -860,19 +862,19 @@ int convert_to_tcl(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj** out) //{{{ Tcl_Obj* k = NULL; Tcl_Obj* v = NULL; Tcl_Obj* vo = NULL; - Tcl_Obj* new = NULL; + Tcl_Obj* new_obj= NULL; - replace_tclobj(&new, Tcl_NewDictObj()); + replace_tclobj(&new_obj, Tcl_NewDictObj()); TEST_OK(Tcl_DictObjFirst(interp, val, &search, &k, &v, &done)); for (; !done; Tcl_DictObjNext(&search, &k, &v, &done)) { TEST_OK_BREAK(res, convert_to_tcl(interp, v, &vo)); - TEST_OK_BREAK(res, Tcl_DictObjPut(interp, new, k, vo)); + TEST_OK_BREAK(res, Tcl_DictObjPut(interp, new_obj, k, vo)); } Tcl_DictObjDone(&search); release_tclobj(&vo); - if (res == TCL_OK) replace_tclobj(out, new); - release_tclobj(&new); + if (res == TCL_OK) replace_tclobj(out, new_obj); + release_tclobj(&new_obj); } break; @@ -881,18 +883,18 @@ int convert_to_tcl(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj** out) //{{{ int i, oc; Tcl_Obj** ov = NULL; Tcl_Obj* elem = NULL; - Tcl_Obj* new = NULL; + Tcl_Obj* new_obj= NULL; - replace_tclobj(&new, Tcl_NewListObj(0, NULL)); + replace_tclobj(&new_obj, Tcl_NewListObj(0, NULL)); TEST_OK(Tcl_ListObjGetElements(interp, val, &oc, &ov)); for (i=0; itcl_empty); } break; @@ -968,7 +970,7 @@ static void foreach_state_free(struct foreach_state* state) //{{{ if (state->it[i].search.dictionaryPtr != NULL) Tcl_DictObjDone(&state->it[i].search); - for (j=0; j < state->it[i].var_c; j++) + for (j=0; j < (unsigned int)state->it[i].var_c; j++) Tcl_DecrRefCount(state->it[i].var_v[j]); release_tclobj(&state->it[i].varlist); @@ -985,7 +987,7 @@ static void foreach_state_free(struct foreach_state* state) //{{{ //}}} static int NRforeach_next_loop_top(Tcl_Interp* interp, struct foreach_state* state) //{{{ { - 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; //fprintf(stderr, "Starting iteration %d/%d\n", i, max_loops); @@ -995,7 +997,7 @@ static int NRforeach_next_loop_top(Tcl_Interp* interp, struct foreach_state* sta if (this_it->is_array) { // Iterating over a JSON array //fprintf(stderr, "Array iteration, data_i: %d, length %d\n", this_it->data_i, this_it->data_c); - for (k=0; kvar_c; k++) { + for (k=0; k<(unsigned int)this_it->var_c; k++) { Tcl_Obj* it_val; if (this_it->data_i < this_it->data_c) { @@ -1033,7 +1035,7 @@ static int NRforeach_next_loop_top(Tcl_Interp* interp, struct foreach_state* sta static int NRforeach_next_loop_bottom(ClientData cdata[], Tcl_Interp* interp, int retcode) //{{{ { struct foreach_state* state = (struct foreach_state*)cdata[0]; - 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* it_res = NULL; switch (retcode) { @@ -1054,10 +1056,10 @@ static int NRforeach_next_loop_bottom(ClientData cdata[], Tcl_Interp* interp, in Tcl_Obj* val = NULL; // Intrep of state->res if (Tcl_IsShared(state->res)) { - Tcl_Obj* new = NULL; - Tcl_IncrRefCount(new = Tcl_DuplicateObj(state->res)); + Tcl_Obj* new_obj= NULL; + Tcl_IncrRefCount(new_obj= Tcl_DuplicateObj(state->res)); Tcl_DecrRefCount(state->res); - state->res = new; // Transfers ref from new to state->res + state->res = new_obj; // Transfers ref from new to state->res } TEST_OK_LABEL(done, retcode, JSON_GetJvalFromObj(interp, state->res, &type, &val)); @@ -1241,7 +1243,7 @@ static int foreach(Tcl_Interp* interp, int objc, Tcl_Obj *const objv[], enum col THROW_ERROR_LABEL(done, retcode, "Cannot iterate over JSON type ", type_names[type]); } - if (loops > state->max_loops) + if (((unsigned int)loops) > state->max_loops) state->max_loops = loops; } @@ -1275,7 +1277,7 @@ int json_pretty(Tcl_Interp* interp, Tcl_Obj* json, Tcl_Obj* indent, Tcl_Obj* pad scx.ds = ds; scx.serialize_mode = SERIALIZE_NORMAL; scx.fromdict = NULL; - scx.l = Tcl_GetAssocData(interp, "rl_json", NULL); + scx.l =(struct interp_cx *)Tcl_GetAssocData(interp, "rl_json", NULL); scx.allow_null = 1; TEST_OK_LABEL(finally, retval, JSON_GetJvalFromObj(interp, json, &type, &val)); @@ -1404,7 +1406,7 @@ static int json_pretty_dbg(Tcl_Interp* interp, Tcl_Obj* json, Tcl_Obj* indent, T scx.ds = ds; scx.serialize_mode = SERIALIZE_NORMAL; scx.fromdict = NULL; - scx.l = Tcl_GetAssocData(interp, "rl_json", NULL); + scx.l =(struct interp_cx *)Tcl_GetAssocData(interp, "rl_json", NULL); scx.allow_null = 1; TEST_OK_LABEL(finally, retval, JSON_GetJvalFromObj(interp, json, &type, &val)); @@ -1798,14 +1800,14 @@ static int remove_action(Tcl_Interp* interp, struct template_cx* cx, int idx) // } //}}} -static int template_actions(struct template_cx* cx, Tcl_Obj* template, enum action_opcode rep_action, Tcl_Obj* elem) //{{{ +static int template_actions(struct template_cx* cx, Tcl_Obj*template_obj, enum action_opcode rep_action, Tcl_Obj* elem) //{{{ { enum json_types type; Tcl_Obj* val = NULL; Tcl_Interp* interp = cx->interp; int retval = TCL_OK; - TEST_OK(JSON_GetJvalFromObj(interp, template, &type, &val)); + TEST_OK(JSON_GetJvalFromObj(interp, template_obj, &type, &val)); switch (type) { case JSON_STRING: @@ -1821,7 +1823,7 @@ static int template_actions(struct template_cx* cx, Tcl_Obj* template, enum acti Tcl_Obj* k; Tcl_Obj* v; - TEST_OK(emit_action(cx, PUSH_TARGET, Tcl_DuplicateObj(template), NULL)); + TEST_OK(emit_action(cx, PUSH_TARGET, Tcl_DuplicateObj(template_obj), NULL)); TEST_OK(Tcl_DictObjFirst(interp, val, &search, &k, &v, &done)); for (; !done; Tcl_DictObjNext(&search, &k, &v, &done)) { int len; @@ -1874,7 +1876,7 @@ static int template_actions(struct template_cx* cx, Tcl_Obj* template, enum acti Tcl_Obj** ov; Tcl_Obj* arr_elem = NULL; - TEST_OK(emit_action(cx, PUSH_TARGET, Tcl_DuplicateObj(template), NULL)); + TEST_OK(emit_action(cx, PUSH_TARGET, Tcl_DuplicateObj(template_obj), NULL)); TEST_OK(Tcl_ListObjGetElements(interp, val, &oc, &ov)); for (i=0; itcl_empty) + template_actions(&cx, template_obj, REPLACE_ATOM, cx.l->tcl_empty) ); if (cx.slots_used > 1) { // Prepend the template action to allocate the slots @@ -2014,7 +2016,7 @@ static inline void fill_slot(Tcl_Obj** slots, int slot, Tcl_Obj* value) //{{{ } //}}} -int apply_template_actions(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj* actions, Tcl_Obj* dict, Tcl_Obj** res) // dict may be null, which means lookup vars {{{ +int apply_template_actions(Tcl_Interp* interp, Tcl_Obj*template_obj, Tcl_Obj* actions, Tcl_Obj* dict, Tcl_Obj** res) // dict may be null, which means lookup vars {{{ { struct interp_cx* l = NULL; #define STATIC_SLOTS 10 @@ -2035,7 +2037,7 @@ int apply_template_actions(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj* actio TEST_OK_LABEL(finally, retcode, Tcl_ListObjGetElements(interp, actions, &actionc, &actionv)); if (actionc == 0) { - replace_tclobj(res, Tcl_DuplicateObj(template)); + replace_tclobj(res, Tcl_DuplicateObj(template_obj)); Tcl_InvalidateStringRep(*res); // Some code relies on the fact that the result of the template command is a normalized json doc (no unnecessary whitespace / newlines) return TCL_OK; } @@ -2043,7 +2045,7 @@ int apply_template_actions(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj* actio if (actionc % 3 != 0) THROW_ERROR_LABEL(finally, retcode, "Invalid actions (odd number of elements)"); - l = Tcl_GetAssocData(interp, "rl_json", NULL); + l =(struct interp_cx *)Tcl_GetAssocData(interp, "rl_json", NULL); for (i=0; i STATIC_SLOTS) { - slots = ckalloc(sizeof(Tcl_Obj*) * slotslen); + slots =(Tcl_Obj**)ckalloc(sizeof(Tcl_Obj*) * slotslen); } else { slots = stackslots; } @@ -2069,7 +2071,7 @@ int apply_template_actions(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj* actio TEST_OK_LABEL(finally, retcode, Tcl_GetIntFromObj(interp, a, &stacklevels)); if (stacklevels > STATIC_STACK) { - stack = ckalloc(sizeof(struct Tcl_Obj*) * stacklevels); + stack =(Tcl_Obj**)ckalloc(sizeof(struct Tcl_Obj*) * stacklevels); } else { stack = stackstack; // Use the space allocated on the c stack } @@ -2081,9 +2083,9 @@ int apply_template_actions(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj* actio case FETCH_VALUE: //{{{ replace_tclobj(&key, a); // Keep a reference in case we need it for an error message shortly if (dict) { - Tcl_Obj* new = NULL; - TEST_OK_LABEL(finally, retcode, Tcl_DictObjGet(interp, dict, a, &new)); - replace_tclobj(&subst_val, new); + Tcl_Obj* new_obj = NULL; + TEST_OK_LABEL(finally, retcode, Tcl_DictObjGet(interp, dict, a, &new_obj)); + replace_tclobj(&subst_val, new_obj); } else { replace_tclobj(&subst_val, Tcl_ObjGetVar2(interp, a, NULL, 0)); } @@ -2172,7 +2174,7 @@ int apply_template_actions(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj* actio case STORE_TEMPLATE: //{{{ { Tcl_Obj* sub_template_actions = NULL; - Tcl_Obj* new = NULL; + Tcl_Obj* new_obj = NULL; int slot; TEST_OK_LABEL(finally, retcode, Tcl_GetIntFromObj(interp, b, &slot)); @@ -2182,12 +2184,12 @@ int apply_template_actions(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj* actio // recursively fill out sub template if ( TCL_OK == (retcode = build_template_actions(interp, subst_val, &sub_template_actions)) && - TCL_OK == (retcode = apply_template_actions(interp, subst_val, sub_template_actions, dict, &new)) + TCL_OK == (retcode = apply_template_actions(interp, subst_val, sub_template_actions, dict, &new_obj)) ) { // Result of a template substitution is guaranteed to be JSON if the return was TCL_OK //TEST_OK_LABEL(finally, retcode, JSON_ForceJSON(interp, new)); - fill_slot(slots, slot, new); - release_tclobj(&new); + fill_slot(slots, slot, new_obj); + release_tclobj(&new_obj); } release_tclobj(&sub_template_actions); if (retcode != TCL_OK) goto finally; @@ -2918,10 +2920,13 @@ static int jsonNRForeach(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj } //}}} + +#if ENSEMBLE static int jsonForeach(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *const objv[]) //{{{ { return Tcl_NRCallObjProc(interp, jsonNRForeach, cdata, objc, objv); } +#endif // ENSEMBLE //}}} static int jsonNRLmap(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *const objv[]) //{{{ @@ -2930,10 +2935,12 @@ static int jsonNRLmap(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *c } //}}} +#if ENSEMBLE static int jsonLmap(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *const objv[]) //{{{ { return Tcl_NRCallObjProc(interp, jsonNRLmap, cdata, objc, objv); } +#endif // ENSEMBLE //}}} static int jsonNRAmap(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *const objv[]) //{{{ @@ -2942,10 +2949,12 @@ static int jsonNRAmap(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *c } //}}} +#if ENSEMBLE static int jsonAmap(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *const objv[]) //{{{ { return Tcl_NRCallObjProc(interp, jsonNRAmap, cdata, objc, objv); } +#endif // ENSEMBLE //}}} static int jsonNROmap(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *const objv[]) //{{{ @@ -2954,10 +2963,12 @@ static int jsonNROmap(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *c } //}}} +#if ENSEMBLE static int jsonOmap(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *const objv[]) //{{{ { return Tcl_NRCallObjProc(interp, jsonNROmap, cdata, objc, objv); } +#endif // ENSEMBLE //}}} static int jsonFreeCache(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *const objv[]) //{{{ @@ -3010,9 +3021,9 @@ static int jsonValid(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *co { struct interp_cx* l = (struct interp_cx*)cdata; int i, valid, retval=TCL_OK; - struct parse_error details = {}; + struct parse_error details = {NULL,NULL,0}; Tcl_Obj* detailsvar = NULL; - enum extensions extensions = EXT_COMMENTS; // By default, use the default set of extensions we accept + int extensions = EXT_COMMENTS; // By default, use the default set of extensions we accept static const char *options[] = { "-extensions", "-details", @@ -3075,7 +3086,7 @@ static int jsonValid(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *co } } - TEST_OK(JSON_Valid(interp, objv[objc-1], &valid, extensions, &details)); + TEST_OK(JSON_Valid(interp, objv[objc-1], &valid,(enum extensions)extensions, &details)); Tcl_SetObjResult(interp, valid ? l->tcl_true : l->tcl_false); if (!valid && detailsvar) { @@ -3094,7 +3105,7 @@ static int jsonValid(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *co TEST_OK_LABEL(finally, retval, Tcl_DictObjPut(interp, details_obj, k, v)); replace_tclobj(&k, get_string(l, "char_ofs", 8)); - replace_tclobj(&v, Tcl_NewIntObj(details.char_ofs)); + replace_tclobj(&v, Tcl_NewIntObj((int)details.char_ofs)); TEST_OK_LABEL(finally, retval, Tcl_DictObjPut(interp, details_obj, k, v)); if (NULL == Tcl_ObjSetVar2(interp, detailsvar, NULL, details_obj, TCL_LEAVE_ERR_MSG)) @@ -3153,7 +3164,7 @@ static int jsonTemplateActions(ClientData cdata, Tcl_Interp* interp, int objc, T TEST_OK(JSON_GetIntrepFromObj(interp, objv[1], &type, &ir)); - replace_tclobj(&actions, ir->twoPtrValue.ptr2); + replace_tclobj(&actions,(Tcl_Obj *) ir->twoPtrValue.ptr2); if (actions == NULL) { TEST_OK(build_template_actions(interp, objv[1], &actions)); replace_tclobj((Tcl_Obj**)&ir->twoPtrValue.ptr2, actions); @@ -3230,7 +3241,7 @@ static int jsonMerge(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *co static int new_json_value_from_list(Tcl_Interp* interp, int objc, Tcl_Obj *const objv[], 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); int new_type, retval=TCL_OK; static const char* types[] = { "string", @@ -3434,13 +3445,14 @@ static int jsonNRObj(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *co case M_LEAK_OBJ: Tcl_NewObj(); break; case M_LEAK_INFO: { - unsigned long addr; + Tcl_WideInt addr; Tcl_Obj* obj = NULL; const char* s; int len; CHECK_ARGS(2, "addr"); - TEST_OK(Tcl_GetLongFromObj(interp, objv[2], (long*)&addr)); + + TEST_OK(Tcl_GetWideIntFromObj(interp, objv[2], &addr)); obj = (Tcl_Obj*)addr; s = Tcl_GetStringFromObj(obj, &len); fprintf(stderr, "\tLeaked obj: %p[%d] len %d: \"%s\"\n", obj, obj->refCount, len, len < 256 ? s : ""); @@ -3466,7 +3478,7 @@ static int jsonObj(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *cons void free_interp_cx(ClientData cdata, Tcl_Interp* interp) //{{{ { - struct interp_cx* l = cdata; + struct interp_cx* l = (struct interp_cx *)cdata; int i; l->interp = NULL; @@ -3519,8 +3531,7 @@ static int checkmem(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *con Tcl_HashTable seen; Tcl_Obj* res = NULL; #define TEMP_TEMPLATE "/tmp/rl_json_XXXXXX" - char temp[sizeof(TEMP_TEMPLATE)]; - int fd; + char temp[sizeof(TEMP_TEMPLATE)]; #if DEDUP struct interp_cx* l = (struct interp_cx*)cdata; #endif @@ -3529,9 +3540,14 @@ static int checkmem(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *con memcpy(temp, TEMP_TEMPLATE, sizeof(TEMP_TEMPLATE)); +#ifdef _WIN32 + _mktemp_s(temp,sizeof(TEMP_TEMPLATE)); + h_before=fopen(temp,"r"); +#else + int fd; fd = mkstemp(temp); h_before = fdopen(fd, "r"); - +#endif #if DEDUP free_cache(l); #endif @@ -3547,8 +3563,13 @@ static int checkmem(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *con free_cache(l); #endif memcpy(temp, TEMP_TEMPLATE, sizeof(TEMP_TEMPLATE)); +#ifdef _WIN32 + _mktemp_s(temp,sizeof(TEMP_TEMPLATE)); + h_after=fopen(temp,"r"); +#else fd = mkstemp(temp); h_after = fdopen(fd, "r"); +#endif Tcl_DumpActiveMemory(temp); if (unlink(temp) != 0) { Tcl_SetObjResult(interp, Tcl_ObjPrintf("Error removing after tmp file: %s", Tcl_ErrnoMsg(Tcl_GetErrno()))); @@ -3558,27 +3579,27 @@ static int checkmem(ClientData cdata, Tcl_Interp* interp, int objc, Tcl_Obj *con Tcl_InitHashTable(&seen, TCL_STRING_KEYS); while (!feof(h_before)) { - int new, len; + int new_obj, len; line = fgets(linebuf, 1024, h_before); if (line == NULL || strstr(line, " @ ./") == NULL) continue; - len = strnlen(line, 1024); + len = (int)strnlen(line, 1024); if (line[len-1] == '\n') len--; - Tcl_CreateHashEntry(&seen, line, &new); + Tcl_CreateHashEntry(&seen, line, &new_obj); } fclose(h_before); h_before = NULL; replace_tclobj(&res, Tcl_NewListObj(0, NULL)); while (!feof(h_after)) { - int new, len; + int new_obj, len; line = fgets(linebuf, 1024, h_after); if (line == NULL || strstr(line, " @ ./") == NULL) continue; - len = strnlen(line, 1024); + len =(int)strnlen(line, 1024); if (line[len-1] == '\n') len--; - Tcl_CreateHashEntry(&seen, line, &new); - if (new) { + Tcl_CreateHashEntry(&seen, line, &new_obj); + if (new_obj) { retcode = Tcl_ListObjAppendElement(interp, res, Tcl_NewStringObj(line, len)); if (retcode != TCL_OK) break; } @@ -3861,6 +3882,7 @@ DLLEXPORT int Rl_json_Init(Tcl_Interp* interp) //{{{ } #ifdef USE_RL_JSON_STUBS + extern Rl_jsonStubs rl_jsonStubs; TEST_OK(Tcl_PkgProvideEx(interp, PACKAGE_NAME, PACKAGE_VERSION, rl_jsonStubs)); #else TEST_OK(Tcl_PkgProvide(interp, PACKAGE_NAME, PACKAGE_VERSION)); diff --git a/generic/rl_json.h b/generic/rl_json.h index 23a926e..148e3e5 100644 --- a/generic/rl_json.h +++ b/generic/rl_json.h @@ -50,14 +50,15 @@ typedef int (JSON_ForeachBody)(ClientData cdata, Tcl_Interp* interp, Tcl_Obj* lo // Stubs exported API +#include "rl_jsonDecls.h" #ifdef USE_RL_JSON_STUBS -EXTERN CONST char* Rl_jsonInitStubs _ANSI_ARGS_((Tcl_Interp* interp, CONST char* version, int exact)); +RL_JSON_EXTERN CONST char* Rl_jsonInitStubs _ANSI_ARGS_((Tcl_Interp* interp, CONST char* version, int exact)); #else # define Rl_jsonInitStubs(interp, version, exact) Tcl_PkgRequire(interp, "rl_json", version, exact) #endif -#include "rl_jsonDecls.h" -EXTERN int Rl_json_Init _ANSI_ARGS_((Tcl_Interp* interp)); -EXTERN int Rl_json_SafeInit _ANSI_ARGS_((Tcl_Interp* interp)); + +RL_JSON_EXTERN int Rl_json_Init _ANSI_ARGS_((Tcl_Interp* interp)); +RL_JSON_EXTERN int Rl_json_SafeInit _ANSI_ARGS_((Tcl_Interp* interp)); #endif diff --git a/generic/rl_jsonDecls.h b/generic/rl_jsonDecls.h index bb4b50d..8c5f668 100644 --- a/generic/rl_jsonDecls.h +++ b/generic/rl_jsonDecls.h @@ -5,111 +5,130 @@ extern "C" { #endif +#undef RL_JSON_STORAGE_CLASS +#ifdef RL_JSON_EXPORTS +# define RL_JSON_STORAGE_CLASS DLLEXPORT +#else +# ifdef USE_TCL_STUBS +# define RL_JSON_STORAGE_CLASS +# else +# define RL_JSON_STORAGE_CLASS DLLIMPORT +# endif +#endif + +#ifdef __cplusplus +# define RL_JSON_EXTERN extern "C" RL_JSON_STORAGE_CLASS +#else +# define RL_JSON_EXTERN extern RL_JSON_STORAGE_CLASS +#endif + + RL_JSON_EXTERN int Objarray_Init(Tcl_Interp* interp); + /* * Exported function declarations: */ /* 0 */ -EXTERN Tcl_Obj* JSON_NewJSONObj(Tcl_Interp*interp, Tcl_Obj*from); +RL_JSON_EXTERN Tcl_Obj* JSON_NewJSONObj(Tcl_Interp*interp, Tcl_Obj*from); /* 1 */ -EXTERN int JSON_NewJStringObj(Tcl_Interp*interp, Tcl_Obj*string, - Tcl_Obj**new); +RL_JSON_EXTERN int JSON_NewJStringObj(Tcl_Interp*interp, Tcl_Obj*string, + Tcl_Obj**new_obj); /* 2 */ -EXTERN int JSON_NewJNumberObj(Tcl_Interp*interp, Tcl_Obj*number, - Tcl_Obj**new); +RL_JSON_EXTERN int JSON_NewJNumberObj(Tcl_Interp*interp, Tcl_Obj*number, + Tcl_Obj**new_obj); /* 3 */ -EXTERN int JSON_NewJBooleanObj(Tcl_Interp*interp, - Tcl_Obj*boolean, Tcl_Obj**new); +RL_JSON_EXTERN int JSON_NewJBooleanObj(Tcl_Interp*interp, + Tcl_Obj*boolean, Tcl_Obj**new_obj); /* 4 */ -EXTERN int JSON_NewJNullObj(Tcl_Interp*interp, Tcl_Obj**new); +RL_JSON_EXTERN int JSON_NewJNullObj(Tcl_Interp*interp, Tcl_Obj**new_obj); /* 5 */ -EXTERN int JSON_NewJObjectObj(Tcl_Interp*interp, Tcl_Obj**new); +RL_JSON_EXTERN int JSON_NewJObjectObj(Tcl_Interp*interp, Tcl_Obj**new_obj); /* 6 */ -EXTERN int JSON_NewJArrayObj(Tcl_Interp*interp, int objc, - Tcl_Obj*objv[], Tcl_Obj**new); +RL_JSON_EXTERN int JSON_NewJArrayObj(Tcl_Interp*interp, int objc, + Tcl_Obj*objv[], Tcl_Obj**new_obj); /* 7 */ -EXTERN int JSON_NewTemplateObj(Tcl_Interp*interp, +RL_JSON_EXTERN int JSON_NewTemplateObj(Tcl_Interp*interp, enum json_types type, Tcl_Obj*key, - Tcl_Obj**new); + Tcl_Obj**new_obj); /* 8 */ -EXTERN int JSON_ForceJSON(Tcl_Interp*interp, Tcl_Obj*obj); +RL_JSON_EXTERN int JSON_ForceJSON(Tcl_Interp*interp, Tcl_Obj*obj); /* 9 */ -EXTERN enum json_types JSON_GetJSONType(Tcl_Obj*obj); +RL_JSON_EXTERN enum json_types JSON_GetJSONType(Tcl_Obj*obj); /* 10 */ -EXTERN int JSON_GetObjFromJStringObj(Tcl_Interp*interp, +RL_JSON_EXTERN int JSON_GetObjFromJStringObj(Tcl_Interp*interp, Tcl_Obj*jstringObj, Tcl_Obj**stringObj); /* 11 */ -EXTERN int JSON_GetObjFromJNumberObj(Tcl_Interp*interp, +RL_JSON_EXTERN int JSON_GetObjFromJNumberObj(Tcl_Interp*interp, Tcl_Obj*jnumberObj, Tcl_Obj**numberObj); /* 12 */ -EXTERN int JSON_GetObjFromJBooleanObj(Tcl_Interp*interp, +RL_JSON_EXTERN int JSON_GetObjFromJBooleanObj(Tcl_Interp*interp, Tcl_Obj*jbooleanObj, Tcl_Obj**booleanObj); /* 13 */ -EXTERN int JSON_JArrayObjAppendElement(Tcl_Interp*interp, +RL_JSON_EXTERN int JSON_JArrayObjAppendElement(Tcl_Interp*interp, Tcl_Obj*arrayObj, Tcl_Obj*elem); /* 14 */ -EXTERN int JSON_JArrayObjAppendList(Tcl_Interp*interp, +RL_JSON_EXTERN int JSON_JArrayObjAppendList(Tcl_Interp*interp, Tcl_Obj*arrayObj, Tcl_Obj* elems /* a JArrayObj or ListObj */); /* 15 */ -EXTERN int JSON_SetJArrayObj(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_SetJArrayObj(Tcl_Interp*interp, Tcl_Obj*obj, int objc, Tcl_Obj*objv[]); /* 16 */ -EXTERN int JSON_JArrayObjGetElements(Tcl_Interp*interp, +RL_JSON_EXTERN int JSON_JArrayObjGetElements(Tcl_Interp*interp, Tcl_Obj*arrayObj, int*objc, Tcl_Obj***objv); /* 17 */ -EXTERN int JSON_JArrayObjIndex(Tcl_Interp*interp, +RL_JSON_EXTERN int JSON_JArrayObjIndex(Tcl_Interp*interp, Tcl_Obj*arrayObj, int index, Tcl_Obj**elem); /* 18 */ -EXTERN int JSON_JArrayObjReplace(Tcl_Interp*interp, +RL_JSON_EXTERN int JSON_JArrayObjReplace(Tcl_Interp*interp, Tcl_Obj*arrayObj, int first, int count, int objc, Tcl_Obj*objv[]); /* 19 */ -EXTERN int JSON_Get(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_Get(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, Tcl_Obj**res); /* 20 */ -EXTERN int JSON_Extract(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_Extract(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, Tcl_Obj**res); /* 21 */ -EXTERN int JSON_Exists(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_Exists(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, int*exists); /* 22 */ -EXTERN int JSON_Set(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_Set(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, Tcl_Obj*replacement); /* 23 */ -EXTERN int JSON_Unset(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_Unset(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path); /* 24 */ -EXTERN int JSON_Normalize(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_Normalize(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj**normalized); /* 25 */ -EXTERN int JSON_Pretty(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_Pretty(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*indent, Tcl_Obj**prettyString); /* 26 */ -EXTERN int JSON_Template(Tcl_Interp*interp, Tcl_Obj*template, +RL_JSON_EXTERN int JSON_Template(Tcl_Interp*interp, Tcl_Obj*template_obj, Tcl_Obj*dict, Tcl_Obj**res); /* 27 */ -EXTERN int JSON_IsNULL(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_IsNULL(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, int*isnull); /* 28 */ -EXTERN int JSON_Type(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_Type(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, enum json_types*type); /* 29 */ -EXTERN int JSON_Length(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_Length(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, int*length); /* 30 */ -EXTERN int JSON_Keys(Tcl_Interp*interp, Tcl_Obj*obj, +RL_JSON_EXTERN int JSON_Keys(Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, Tcl_Obj**keyslist); /* 31 */ -EXTERN int JSON_Decode(Tcl_Interp*interp, Tcl_Obj*bytes, +RL_JSON_EXTERN int JSON_Decode(Tcl_Interp*interp, Tcl_Obj*bytes, Tcl_Obj*encoding, Tcl_Obj**decodedstring); /* 32 */ -EXTERN int JSON_Foreach(Tcl_Interp*interp, Tcl_Obj*iterators, +RL_JSON_EXTERN int JSON_Foreach(Tcl_Interp*interp, Tcl_Obj*iterators, JSON_ForeachBody*body, enum collecting_mode collect, Tcl_Obj**res, ClientData cdata); /* 33 */ -EXTERN int JSON_Valid(Tcl_Interp*interp, Tcl_Obj*json, +RL_JSON_EXTERN int JSON_Valid(Tcl_Interp*interp, Tcl_Obj*json, int*valid, enum extensions extensions, struct parse_error*details); @@ -118,13 +137,13 @@ typedef struct Rl_jsonStubs { void *hooks; Tcl_Obj* (*jSON_NewJSONObj) (Tcl_Interp*interp, Tcl_Obj*from); /* 0 */ - int (*jSON_NewJStringObj) (Tcl_Interp*interp, Tcl_Obj*string, Tcl_Obj**new); /* 1 */ - int (*jSON_NewJNumberObj) (Tcl_Interp*interp, Tcl_Obj*number, Tcl_Obj**new); /* 2 */ - int (*jSON_NewJBooleanObj) (Tcl_Interp*interp, Tcl_Obj*boolean, Tcl_Obj**new); /* 3 */ - int (*jSON_NewJNullObj) (Tcl_Interp*interp, Tcl_Obj**new); /* 4 */ - int (*jSON_NewJObjectObj) (Tcl_Interp*interp, Tcl_Obj**new); /* 5 */ - int (*jSON_NewJArrayObj) (Tcl_Interp*interp, int objc, Tcl_Obj*objv[], Tcl_Obj**new); /* 6 */ - int (*jSON_NewTemplateObj) (Tcl_Interp*interp, enum json_types type, Tcl_Obj*key, Tcl_Obj**new); /* 7 */ + int (*jSON_NewJStringObj) (Tcl_Interp*interp, Tcl_Obj*string, Tcl_Obj**new_obj); /* 1 */ + int (*jSON_NewJNumberObj) (Tcl_Interp*interp, Tcl_Obj*number, Tcl_Obj**new_obj); /* 2 */ + int (*jSON_NewJBooleanObj) (Tcl_Interp*interp, Tcl_Obj*boolean, Tcl_Obj**new_obj); /* 3 */ + int (*jSON_NewJNullObj) (Tcl_Interp*interp, Tcl_Obj**new_obj); /* 4 */ + int (*jSON_NewJObjectObj) (Tcl_Interp*interp, Tcl_Obj**new_obj); /* 5 */ + int (*jSON_NewJArrayObj) (Tcl_Interp*interp, int objc, Tcl_Obj*objv[], Tcl_Obj**new_obj); /* 6 */ + int (*jSON_NewTemplateObj) (Tcl_Interp*interp, enum json_types type, Tcl_Obj*key, Tcl_Obj**new_obj); /* 7 */ int (*jSON_ForceJSON) (Tcl_Interp*interp, Tcl_Obj*obj); /* 8 */ enum json_types (*jSON_GetJSONType) (Tcl_Obj*obj); /* 9 */ int (*jSON_GetObjFromJStringObj) (Tcl_Interp*interp, Tcl_Obj*jstringObj, Tcl_Obj**stringObj); /* 10 */ @@ -143,7 +162,7 @@ typedef struct Rl_jsonStubs { int (*jSON_Unset) (Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path); /* 23 */ int (*jSON_Normalize) (Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj**normalized); /* 24 */ int (*jSON_Pretty) (Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*indent, Tcl_Obj**prettyString); /* 25 */ - int (*jSON_Template) (Tcl_Interp*interp, Tcl_Obj*template, Tcl_Obj*dict, Tcl_Obj**res); /* 26 */ + int (*jSON_Template) (Tcl_Interp*interp, Tcl_Obj*template_obj, Tcl_Obj*dict, Tcl_Obj**res); /* 26 */ int (*jSON_IsNULL) (Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, int*isnull); /* 27 */ int (*jSON_Type) (Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, enum json_types*type); /* 28 */ int (*jSON_Length) (Tcl_Interp*interp, Tcl_Obj*obj, Tcl_Obj*path, int*length); /* 29 */ diff --git a/generic/rl_jsonInt.h b/generic/rl_jsonInt.h index 9b5fa72..38046ee 100644 --- a/generic/rl_jsonInt.h +++ b/generic/rl_jsonInt.h @@ -242,8 +242,8 @@ Tcl_Obj* as_json(Tcl_Interp* interp, Tcl_Obj* from); const char* get_dyn_prefix(enum json_types type); const char* get_type_name(enum json_types type); Tcl_Obj* get_unshared_val(Tcl_ObjIntRep* ir); -int apply_template_actions(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj* actions, Tcl_Obj* dict, Tcl_Obj** res); -int build_template_actions(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj** actions); +int apply_template_actions(Tcl_Interp* interp, Tcl_Obj*template_obj, Tcl_Obj* actions, Tcl_Obj* dict, Tcl_Obj** res); +int build_template_actions(Tcl_Interp* interp, Tcl_Obj*template_obj, Tcl_Obj** actions); int convert_to_tcl(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj** out); int resolve_path(Tcl_Interp* interp, Tcl_Obj* src, Tcl_Obj *const pathv[], int pathc, Tcl_Obj** target, const int exists, const int modifiers); int json_pretty(Tcl_Interp* interp, Tcl_Obj* json, Tcl_Obj* indent, Tcl_Obj* pad, Tcl_DString* ds); diff --git a/generic/rl_jsonStubLib.c b/generic/rl_jsonStubLib.c index 142940c..a6cf7f8 100644 --- a/generic/rl_jsonStubLib.c +++ b/generic/rl_jsonStubLib.c @@ -1,13 +1,13 @@ #include "rl_json.h" #ifdef USE_RL_JSON_STUBS -MODULE_SCOPE const Rl_jsonStubs* rl_jsonStubsPtr; +extern const Rl_jsonStubs* rl_jsonStubsPtr; const Rl_jsonStubs* Rl_jsonStubsPtr = NULL; #undef rl_jsonInitStubs -EXTERN CONST char* Rl_jsonInitStubs(Tcl_Interp* interp, const char* version, int exact) +RL_JSON_EXTERN CONST char* Rl_jsonInitStubs(Tcl_Interp* interp, const char* version, int exact) { const char* packageName = "rl_json"; const char* errMsg = NULL; diff --git a/gid/pkgIndex.tcl b/gid/pkgIndex.tcl new file mode 100644 index 0000000..390c7c3 --- /dev/null +++ b/gid/pkgIndex.tcl @@ -0,0 +1,21 @@ +# +# Tcl package index file +# +proc load_library_rl_json { dir basename } { + if { $::tcl_platform(pointerSize) == 8 } { + set bits 64 + } else { + set bits 32 + } + set debug "" + # set debug "d" + if { $::tcl_platform(platform) eq "windows"} { + set library ${basename}_${bits}${debug}[ info sharedlibextension] + } else { + set library lib${basename}_${bits}${debug}[ info sharedlibextension] + } + load [file join $dir $library] $basename +} + +package ifneeded rl_json 0.11.4 [list load_library_rl_json $dir rl_json] + diff --git a/vs/rl_json.vcxproj b/vs/rl_json.vcxproj new file mode 100644 index 0000000..3e66a24 --- /dev/null +++ b/vs/rl_json.vcxproj @@ -0,0 +1,212 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + {CE846908-9FB7-45E5-999F-C4EB43375E20} + Win32Proj + rl_json + rl_json + 10.0 + + + + DynamicLibrary + true + MultiByte + v143 + + + DynamicLibrary + true + MultiByte + v143 + + + DynamicLibrary + false + false + MultiByte + v143 + + + DynamicLibrary + false + false + MultiByte + v143 + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)x$(PlatformArchitecture)\$(Configuration)\ + x$(PlatformArchitecture)\$(Configuration)\ + + + true + $(SolutionDir)x$(PlatformArchitecture)\$(Configuration)\ + x$(PlatformArchitecture)\$(Configuration)\ + + + false + $(SolutionDir)x$(PlatformArchitecture)\$(Configuration)\ + x$(PlatformArchitecture)\$(Configuration)\ + + + false + $(SolutionDir)x$(PlatformArchitecture)\$(Configuration)\ + x$(PlatformArchitecture)\$(Configuration)\ + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;RL_JSON_EXPORTS;USE_TCL_STUBS;USE_TCLOO_STUBS;TIP445_SHIM;%(PreprocessorDefinitions) + true + MultiThreadedDebug + ..\..\tcltk\TclTk8.6.12\x$(PlatformArchitecture)\include + + + + Console + true + ..\..\tcltk\TclTk8.6.12\x$(PlatformArchitecture)\lib + tclstub86.lib;%(AdditionalDependencies) + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;RL_JSON_EXPORTS;USE_TCL_STUBS;USE_TCLOO_STUBS;TIP445_SHIM;%(PreprocessorDefinitions) + true + MultiThreadedDebug + ..\..\tcltk\TclTk8.6.12\x$(PlatformArchitecture)\include + + + + + Console + true + ..\..\tcltk\TclTk8.6.12\x$(PlatformArchitecture)\lib + tclstub86.lib;%(AdditionalDependencies) + + + + + Level3 + NotUsing + Full + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;RL_JSON_EXPORTS;USE_TCL_STUBS;USE_TCLOO_STUBS;TIP445_SHIM;%(PreprocessorDefinitions) + true + MultiThreaded + ..\..\tcltk\TclTk8.6.12\x$(PlatformArchitecture)\include + + false + /MP8 %(AdditionalOptions) + None + Default + + + Console + false + true + true + ..\..\tcltk\TclTk8.6.12\x$(PlatformArchitecture)\lib + tclstub86.lib;%(AdditionalDependencies) + Default + + + copy "$(TargetPath)" ..\..\..\scripts\rl_json\rl_json_$(PlatformArchitecture).dll +copy "$(TargetPath)" ..\..\..\rl_json.dll +copy "$(TargetPath)" ..\..\..\lib\x$(PlatformArchitecture)\rl_json.dll + + + + + Level3 + NotUsing + Full + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;RL_JSON_EXPORTS;USE_TCL_STUBS;USE_TCLOO_STUBS;TIP445_SHIM;%(PreprocessorDefinitions) + true + MultiThreaded + ..\..\tcltk\TclTk8.6.12\x$(PlatformArchitecture)\include + + + false + None + CompileAsC + + + Console + false + true + true + ..\..\tcltk\TclTk8.6.12\x$(PlatformArchitecture)\lib + tclstub86.lib;%(AdditionalDependencies) + Default + + + copy "$(TargetPath)" ..\..\..\scripts\rl_json\rl_json_$(PlatformArchitecture).dll +copy "$(TargetPath)" ..\..\..\lib\x$(PlatformArchitecture)\rl_json.dll + + + + + + \ No newline at end of file diff --git a/vs/rl_json.vcxproj.filters b/vs/rl_json.vcxproj.filters new file mode 100644 index 0000000..7afe8b0 --- /dev/null +++ b/vs/rl_json.vcxproj.filters @@ -0,0 +1,63 @@ + + + + + {125cb61f-0f27-4e19-9297-26a8e2e21d2b} + + + {b32d45d9-0ca9-4592-8950-4097e970e773} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file