Skip to content

Commit

Permalink
Switched tclconfig to a git submodule, changed spelling of TIP 445 AP…
Browse files Browse the repository at this point in the history
…I calls
  • Loading branch information
cyanogilvie committed Nov 18, 2022
1 parent 08ae73a commit 58d79d9
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 124 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tclconfig"]
path = tclconfig
url = https://github.com/tcltk/tclconfig
2 changes: 1 addition & 1 deletion aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ AC_DEFUN([TIP445], [
AC_MSG_CHECKING([whether we need to polyfill TIP 445])
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $TCL_INCLUDE_SPEC"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <tcl.h>]], [[Tcl_ObjIntRep ir;]])],[have_tcl_objintrep=yes],[have_tcl_objintrep=no])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <tcl.h>]], [[Tcl_ObjInternalRep ir;]])],[have_tcl_objintrep=yes],[have_tcl_objintrep=no])
CFLAGS="$saved_CFLAGS"
if test "$have_tcl_objintrep" = yes; then
Expand Down
74 changes: 37 additions & 37 deletions generic/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ int JSON_NewTemplateObj(Tcl_Interp* interp, enum json_types type, Tcl_Obj* key,
//}}}
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;
Tcl_ObjInternalRep* ir;
enum json_types type;

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

Expand All @@ -105,11 +105,11 @@ 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;
Tcl_ObjInternalRep* ir = NULL;
enum json_types t;

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

return (ir == NULL) ? JSON_UNDEF : t-1;
}
Expand Down Expand Up @@ -173,10 +173,10 @@ int JSON_GetObjFromJBooleanObj(Tcl_Interp* interp, Tcl_Obj* jbooleanObj, Tcl_Obj
//}}}
int JSON_JArrayObjAppendElement(Tcl_Interp* interp, Tcl_Obj* arrayObj, Tcl_Obj* elem) //{{{
{
int code = TCL_OK;
enum json_types type;
Tcl_ObjIntRep* ir = NULL;
Tcl_Obj* val = NULL;
int code = TCL_OK;
enum json_types type;
Tcl_ObjInternalRep* ir = NULL;
Tcl_Obj* val = NULL;

if (Tcl_IsShared(arrayObj)) {
// Tcl_Panic?
Expand Down Expand Up @@ -204,11 +204,11 @@ int JSON_JArrayObjAppendElement(Tcl_Interp* interp, Tcl_Obj* arrayObj, Tcl_Obj*
//}}}
int JSON_JArrayObjAppendList(Tcl_Interp* interp, Tcl_Obj* arrayObj, Tcl_Obj* elems /* a JArrayObj or ListObj */ ) //{{{
{
enum json_types type, elems_type;
Tcl_ObjIntRep* ir = NULL;
Tcl_Obj* val = NULL;
Tcl_Obj* elems_val = NULL;
int retval = TCL_OK;
enum json_types type, elems_type;
Tcl_ObjInternalRep* ir = NULL;
Tcl_Obj* val = NULL;
Tcl_Obj* elems_val = NULL;
int retval = TCL_OK;

if (Tcl_IsShared(arrayObj)) {
// Tcl_Panic?
Expand Down Expand Up @@ -263,12 +263,12 @@ int JSON_JArrayObjAppendList(Tcl_Interp* interp, Tcl_Obj* arrayObj, Tcl_Obj* ele
//}}}
int JSON_SetJArrayObj(Tcl_Interp* interp, Tcl_Obj* obj, const int objc, Tcl_Obj* objv[]) //{{{
{
enum json_types type;
Tcl_ObjIntRep* ir = NULL;
Tcl_Obj* val = NULL;
int i, retval = TCL_OK;
Tcl_Obj** jov = NULL;
Tcl_Obj* newlist = NULL;
enum json_types type;
Tcl_ObjInternalRep* ir = NULL;
Tcl_Obj* val = NULL;
int i, retval = TCL_OK;
Tcl_Obj** jov = NULL;
Tcl_Obj* newlist = NULL;

if (Tcl_IsShared(obj)) {
// Tcl_Panic?
Expand Down Expand Up @@ -437,17 +437,17 @@ int JSON_Exists(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj* path, int* exists) //
//}}}
int JSON_Set(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj *path, Tcl_Obj* replacement) //{{{
{
int code = TCL_OK;
int i, pathc;
enum json_types type, newtype;
Tcl_ObjIntRep* ir = NULL;
Tcl_Obj* val = NULL;
Tcl_Obj* step;
Tcl_Obj* src;
Tcl_Obj* target;
Tcl_Obj* newval;
Tcl_Obj* rep = NULL;
Tcl_Obj** pathv = NULL;
int code = TCL_OK;
int i, pathc;
enum json_types type, newtype;
Tcl_ObjInternalRep* ir = NULL;
Tcl_Obj* val = NULL;
Tcl_Obj* step;
Tcl_Obj* src;
Tcl_Obj* target;
Tcl_Obj* newval;
Tcl_Obj* rep = NULL;
Tcl_Obj** pathv = NULL;

if (Tcl_IsShared(obj))
THROW_ERROR_LABEL(finally, code, "JSON_Set called with shared object");
Expand Down Expand Up @@ -675,7 +675,7 @@ int JSON_Unset(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj *path) //{{{
*/

{
Tcl_ObjIntRep* ir = NULL;
Tcl_ObjInternalRep* ir = NULL;
TEST_OK_LABEL(finally, retval, JSON_GetIntrepFromObj(interp, target, &type, &ir));
val = get_unshared_val(ir);
}
Expand Down Expand Up @@ -781,7 +781,7 @@ int JSON_Unset(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_Obj *path) //{{{
}

{
Tcl_ObjIntRep* ir = NULL;
Tcl_ObjInternalRep* ir = NULL;
TEST_OK_LABEL(finally, retval, JSON_GetIntrepFromObj(interp, target, &type, &ir));
val = get_unshared_val(ir);
}
Expand Down Expand Up @@ -961,7 +961,7 @@ int JSON_Template(Tcl_Interp* interp, Tcl_Obj* template, Tcl_Obj* dict, Tcl_Obj*
//struct interp_cx* l = Tcl_GetAssocData(interp, "rl_json", NULL);
Tcl_Obj* actions = NULL;
int retcode = TCL_OK;
Tcl_ObjIntRep* ir;
Tcl_ObjInternalRep* ir;
enum json_types type;

TEST_OK(JSON_GetIntrepFromObj(interp, template, &type, &ir));
Expand Down Expand Up @@ -1397,9 +1397,9 @@ int JSON_Valid(Tcl_Interp* interp, Tcl_Obj* json, int* valid, enum extensions ex
{
if (
l && (
(l->typeInt && Tcl_FetchIntRep(json, l->typeInt) != NULL) ||
(l->typeDouble && Tcl_FetchIntRep(json, l->typeDouble) != NULL) ||
(l->typeBignum && Tcl_FetchIntRep(json, l->typeBignum) != NULL)
(l->typeInt && Tcl_FetchInternalRep(json, l->typeInt) != NULL) ||
(l->typeDouble && Tcl_FetchInternalRep(json, l->typeDouble) != NULL) ||
(l->typeBignum && Tcl_FetchInternalRep(json, l->typeBignum) != NULL)
)
) {
*valid = 1;
Expand Down
84 changes: 42 additions & 42 deletions generic/json_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ Tcl_ObjType json_dyn_literal = {
Tcl_ObjType* g_objtype_for_type[JSON_TYPE_MAX];


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

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

if (_ir == NULL)
Expand All @@ -173,15 +173,15 @@ int JSON_IsJSON(Tcl_Obj* obj, enum json_types* type, Tcl_ObjIntRep** ir) //{{{
}

//}}}
int JSON_GetIntrepFromObj(Tcl_Interp* interp, Tcl_Obj* obj, enum json_types* type, Tcl_ObjIntRep** ir) //{{{
int JSON_GetIntrepFromObj(Tcl_Interp* interp, Tcl_Obj* obj, enum json_types* type, Tcl_ObjInternalRep** ir) //{{{
{
enum json_types t;
Tcl_ObjIntRep* _ir = NULL;
Tcl_ObjType* objtype = NULL;
enum json_types t;
Tcl_ObjInternalRep* _ir = NULL;
Tcl_ObjType* objtype = NULL;

if (!JSON_IsJSON(obj, &t, &_ir)) {
TEST_OK(set_from_any(interp, obj, &objtype, &t));
_ir = Tcl_FetchIntRep(obj, objtype);
_ir = Tcl_FetchInternalRep(obj, objtype);
if (_ir == NULL) Tcl_Panic("Could not retrieve the intrep we just created");
}

Expand All @@ -194,7 +194,7 @@ int JSON_GetIntrepFromObj(Tcl_Interp* interp, Tcl_Obj* obj, enum json_types* typ
//}}}
int JSON_GetJvalFromObj(Tcl_Interp* interp, Tcl_Obj* obj, enum json_types* type, Tcl_Obj** val) //{{{
{
Tcl_ObjIntRep* ir = NULL;
Tcl_ObjInternalRep* ir = NULL;

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

Expand All @@ -206,7 +206,7 @@ int JSON_GetJvalFromObj(Tcl_Interp* interp, Tcl_Obj* obj, enum json_types* type,
//}}}
int JSON_SetIntRep(Tcl_Obj* target, enum json_types type, Tcl_Obj* replacement) //{{{
{
Tcl_ObjIntRep intrep = {0};
Tcl_ObjInternalRep intrep = {0};
Tcl_ObjType* objtype = NULL;
Tcl_Obj* rep = NULL;

Expand All @@ -231,13 +231,13 @@ int JSON_SetIntRep(Tcl_Obj* target, enum json_types type, Tcl_Obj* replacement)

objtype = g_objtype_for_type[type];

Tcl_FreeIntRep(target);
Tcl_FreeInternalRep(target);

// ptr1 is the Tcl_Obj holding the Tcl structure for this value
// ptr2 holds the template actions, if any have been generated for this value
replace_tclobj((Tcl_Obj**)&intrep.twoPtrValue.ptr1, rep);

Tcl_StoreIntRep(target, objtype, &intrep);
Tcl_StoreInternalRep(target, objtype, &intrep);

Tcl_InvalidateStringRep(target);

Expand Down Expand Up @@ -290,9 +290,9 @@ Tcl_Obj* JSON_NewJvalObj(enum json_types type, Tcl_Obj* val)

static void free_internal_rep(Tcl_Obj* obj, Tcl_ObjType* objtype) //{{{
{
Tcl_ObjIntRep* ir = NULL;
Tcl_ObjInternalRep* ir = NULL;

ir = Tcl_FetchIntRep(obj, objtype);
ir = Tcl_FetchInternalRep(obj, objtype);
if (ir != NULL) {
release_tclobj((Tcl_Obj**)&ir->twoPtrValue.ptr1);
release_tclobj((Tcl_Obj**)&ir->twoPtrValue.ptr2);
Expand Down Expand Up @@ -323,10 +323,10 @@ static void free_internal_rep(Tcl_Obj* obj, Tcl_ObjType* objtype) //{{{
//}}}
static void dup_internal_rep(Tcl_Obj* src, Tcl_Obj* dest, Tcl_ObjType* objtype) //{{{
{
Tcl_ObjIntRep* srcir = NULL;
Tcl_ObjIntRep destir;
Tcl_ObjInternalRep* srcir = NULL;
Tcl_ObjInternalRep destir;

srcir = Tcl_FetchIntRep(src, objtype);
srcir = Tcl_FetchInternalRep(src, objtype);
if (srcir == NULL)
Tcl_Panic("dup_internal_rep asked to duplicate for type, but that type wasn't available on the src object");

Expand Down Expand Up @@ -355,13 +355,13 @@ static void dup_internal_rep(Tcl_Obj* src, Tcl_Obj* dest, Tcl_ObjType* objtype)
if (destir.twoPtrValue.ptr1) Tcl_IncrRefCount((Tcl_Obj*)destir.twoPtrValue.ptr1);
if (destir.twoPtrValue.ptr2) Tcl_IncrRefCount((Tcl_Obj*)destir.twoPtrValue.ptr2);

Tcl_StoreIntRep(dest, objtype, &destir);
Tcl_StoreInternalRep(dest, objtype, &destir);
}

//}}}
static void update_string_rep(Tcl_Obj* obj, Tcl_ObjType* objtype) //{{{
{
Tcl_ObjIntRep* ir = Tcl_FetchIntRep(obj, objtype);
Tcl_ObjInternalRep* ir = Tcl_FetchInternalRep(obj, objtype);
struct serialize_context scx;
Tcl_DString ds;

Expand Down Expand Up @@ -391,9 +391,9 @@ static void update_string_rep_string(Tcl_Obj* obj) //{{{
{
update_string_rep(obj, &json_string);
/*
Tcl_ObjIntRep* ir = Tcl_FetchIntRep(obj, &json_string);
const char* str;
int len;
Tcl_ObjInternalRep* ir = Tcl_FetchInternalRep(obj, &json_string);
const char* str;
int len;
str = Tcl_GetStringFromObj((Tcl_Obj*)ir->twoPtrValue.ptr1, &len);
obj->bytes = ckalloc(len+3);
Expand All @@ -408,9 +408,9 @@ static void update_string_rep_string(Tcl_Obj* obj) //{{{
//}}}
static void update_string_rep_number(Tcl_Obj* obj) //{{{
{
Tcl_ObjIntRep* ir = Tcl_FetchIntRep(obj, &json_number);
const char* str;
int len;
Tcl_ObjInternalRep* ir = Tcl_FetchInternalRep(obj, &json_number);
const char* str;
int len;

if (ir->twoPtrValue.ptr1 == obj)
Tcl_Panic("Turtles all the way down!");
Expand All @@ -424,8 +424,8 @@ static void update_string_rep_number(Tcl_Obj* obj) //{{{
//}}}
static void update_string_rep_bool(Tcl_Obj* obj) //{{{
{
Tcl_ObjIntRep* ir = Tcl_FetchIntRep(obj, &json_bool);
int boolval;
Tcl_ObjInternalRep* ir = Tcl_FetchInternalRep(obj, &json_bool);
int boolval;

if (Tcl_GetBooleanFromObj(NULL, (Tcl_Obj*)ir->twoPtrValue.ptr1, &boolval) != TCL_OK)
Tcl_Panic("json_bool's intrep tclobj is not a boolean");
Expand Down Expand Up @@ -454,9 +454,9 @@ static void update_string_rep_dyn_literal(Tcl_Obj* obj) //{{{
{
update_string_rep(obj, &json_dyn_literal);
/*
Tcl_ObjIntRep* ir = Tcl_FetchIntRep(obj, &json_dyn_literal);
const char* str;
int len;
Tcl_ObjInternalRep* ir = Tcl_FetchInternalRep(obj, &json_dyn_literal);
const char* str;
int len;
str = Tcl_GetStringFromObj((Tcl_Obj*)ir->twoPtrValue.ptr1, &len);
obj->bytes = ckalloc(len+6);
Expand Down Expand Up @@ -497,12 +497,12 @@ static int set_from_any(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_ObjType** objtype,
{
if (
l && (
(l->typeInt && Tcl_FetchIntRep(obj, l->typeInt) != NULL) ||
(l->typeDouble && Tcl_FetchIntRep(obj, l->typeDouble) != NULL) ||
(l->typeBignum && Tcl_FetchIntRep(obj, l->typeBignum) != NULL)
(l->typeInt && Tcl_FetchInternalRep(obj, l->typeInt) != NULL) ||
(l->typeDouble && Tcl_FetchInternalRep(obj, l->typeDouble) != NULL) ||
(l->typeBignum && Tcl_FetchInternalRep(obj, l->typeBignum) != NULL)
)
) {
Tcl_ObjIntRep ir = {.twoPtrValue = {0}};
Tcl_ObjInternalRep ir = {.twoPtrValue = {0}};

// Must dup because obj will soon be us, creating a circular ref
replace_tclobj((Tcl_Obj**)&ir.twoPtrValue.ptr1, Tcl_DuplicateObj(obj));
Expand All @@ -511,7 +511,7 @@ static int set_from_any(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_ObjType** objtype,
*out_type = JSON_NUMBER;
*objtype = g_objtype_for_type[JSON_NUMBER];

Tcl_StoreIntRep(obj, *objtype, &ir);
Tcl_StoreInternalRep(obj, *objtype, &ir);
return TCL_OK;
}
}
Expand Down Expand Up @@ -704,12 +704,12 @@ static int set_from_any(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_ObjType** objtype,
goto whitespace_err;
}

//Tcl_FreeIntRep(obj);
//Tcl_FreeInternalRep(obj);

{
Tcl_ObjType* top_objtype = g_objtype_for_type[cx[0].container];
Tcl_ObjIntRep* top_ir = Tcl_FetchIntRep(cx[0].val, top_objtype);
Tcl_ObjIntRep ir = {.twoPtrValue = {0}};
Tcl_ObjType* top_objtype = g_objtype_for_type[cx[0].container];
Tcl_ObjInternalRep* top_ir = Tcl_FetchInternalRep(cx[0].val, top_objtype);
Tcl_ObjInternalRep ir = {.twoPtrValue = {0}};

if (unlikely(top_ir == NULL))
Tcl_Panic("Can't get intrep for the top container");
Expand All @@ -719,7 +719,7 @@ static int set_from_any(Tcl_Interp* interp, Tcl_Obj* obj, Tcl_ObjType** objtype,
release_tclobj((Tcl_Obj**)&ir.twoPtrValue.ptr2);
release_tclobj(&cx[0].val);

Tcl_StoreIntRep(obj, top_objtype, &ir);
Tcl_StoreInternalRep(obj, top_objtype, &ir);
*objtype = top_objtype;
*out_type = cx[0].container;
}
Expand Down Expand Up @@ -756,7 +756,7 @@ int type_is_dynamic(const enum json_types type) //{{{
}

//}}}
Tcl_Obj* get_unshared_val(Tcl_ObjIntRep* ir) //{{{
Tcl_Obj* get_unshared_val(Tcl_ObjInternalRep* 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));
Expand Down
Loading

0 comments on commit 58d79d9

Please sign in to comment.