X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-tcl.git;a=blobdiff_plain;f=base%2Fparse.c;h=911cadd3eb71e34d2bbb2dcbef206dc343480e33;hp=e5e3465c93c450eea9357c55e35718663ed58f03;hb=a43cdb5c69224a60f9e87110093e35a0f1f0b468;hpb=2cf1bfc63e73a424f9f3899c204025a8346b38e0 diff --git a/base/parse.c b/base/parse.c index e5e3465..911cadd 100644 --- a/base/parse.c +++ b/base/parse.c @@ -10,38 +10,38 @@ int pat_charfrom(Tcl_Interp *ip, Tcl_Obj *obj, int *val, return TCL_OK; } -int pat_enum(Tcl_Interp *ip, Tcl_Obj *obj, const void **val, - const void *opts, size_t sz, const char *what) { - *val= enum_lookup_cached_func(ip,obj,opts,sz,what); - if (!*val) return TCL_ERROR; - return TCL_OK; +int pat_int(Tcl_Interp *ip, Tcl_Obj *obj, int *val) { + return Tcl_GetIntFromObj(ip, obj, val); } -int pat_obj(Tcl_Interp *ip, Tcl_Obj *obj, Tcl_Obj **val) { - *val= obj; - return TCL_OK; +int pat_long(Tcl_Interp *ip, Tcl_Obj *obj, long *val) { + return Tcl_GetLongFromObj(ip, obj, val); } - -int pat_int(Tcl_Interp *ip, Tcl_Obj *obj, int *val) { - return Tcl_GetIntFromObj(ip, obj, val); + +int pat_string(Tcl_Interp *ip, Tcl_Obj *obj, const char **val) { + *val= Tcl_GetString(obj); + return TCL_OK; } int pat_hbv(Tcl_Interp *ip, Tcl_Obj *var, HBytes_Var *agg) { int rc; Tcl_Obj *val; - Tcl_IncrRefCount(var); agg->var= var; val= Tcl_ObjGetVar2(ip,var,0,TCL_LEAVE_ERR_MSG); if (!val) return TCL_ERROR; - if (Tcl_IsShared(val)) val= Tcl_DuplicateObj(val); - Tcl_IncrRefCount(val); - agg->obj= val; - + rc= Tcl_ConvertToType(ip,val,&hbytes_type); if (rc) return rc; + if (Tcl_IsShared(val)) { + val= Tcl_DuplicateObj(val); + agg->copied= 1; + } + Tcl_InvalidateStringRep(val); + agg->obj= val; + agg->hb= OBJ_HBYTES(val); return TCL_OK; } @@ -49,14 +49,13 @@ int pat_hbv(Tcl_Interp *ip, Tcl_Obj *var, HBytes_Var *agg) { void fini_hbv(Tcl_Interp *ip, int rc, HBytes_Var *agg) { Tcl_Obj *ro; - Tcl_InvalidateStringRep(agg->obj); if (!rc) { assert(agg->obj); ro= Tcl_ObjSetVar2(ip,agg->var,0,agg->obj,TCL_LEAVE_ERR_MSG); if (!ro) rc= TCL_ERROR; } - if (agg->obj) Tcl_DecrRefCount(agg->obj); - if (agg->var) Tcl_DecrRefCount(agg->var); + if (rc && agg->copied) + Tcl_DecrRefCount(agg->obj); } int pat_hb(Tcl_Interp *ip, Tcl_Obj *obj, HBytes_Value *val) { @@ -75,11 +74,10 @@ Tcl_Obj *ret_hb(Tcl_Interp *ip, HBytes_Value val) { return obj; } -Tcl_Obj *ret_obj(Tcl_Interp *ip, Tcl_Obj *val) { - return val; +Tcl_Obj *ret_long(Tcl_Interp *ip, long val) { + return Tcl_NewLongObj(val); } -void setstringresult(Tcl_Interp *ip, const char *m) { - Tcl_ResetResult(ip); - Tcl_AppendResult(ip, m, (char*)0); +Tcl_Obj *ret_string(Tcl_Interp *ip, const char *val) { + return Tcl_NewStringObj(val,-1); }