diff options
author | dgp <dgp@users.sourceforge.net> | 2012-01-27 21:56:52 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2012-01-27 21:56:52 (GMT) |
commit | 6740ac50e9a65342cacd77245cacb8ad443dda00 (patch) | |
tree | f4482a0b82fb53236a1951b0d815fc6f2b21a95e /generic/tclFileName.c | |
parent | 8783392efa27d4df503dc1b7029e8fde6ba03b4a (diff) | |
download | tcl-6740ac50e9a65342cacd77245cacb8ad443dda00.zip tcl-6740ac50e9a65342cacd77245cacb8ad443dda00.tar.gz tcl-6740ac50e9a65342cacd77245cacb8ad443dda00.tar.bz2 |
3479689 New internal routine TclJoinPath().
Refactor all the *Join*Path* routines to give them more useful interfaces
that are easier to manage getting the refcounts right.
Diffstat (limited to 'generic/tclFileName.c')
-rw-r--r-- | generic/tclFileName.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/generic/tclFileName.c b/generic/tclFileName.c index 8ed6f96..adfa2fd 100644 --- a/generic/tclFileName.c +++ b/generic/tclFileName.c @@ -787,32 +787,28 @@ Tcl_FSJoinToPath( int objc, /* Number of array elements to join */ Tcl_Obj *const objv[]) /* Path elements to join. */ { - int i; - Tcl_Obj *lobj, *ret; - if (pathPtr == NULL) { - lobj = Tcl_NewListObj(0, NULL); - } else { - lobj = Tcl_NewListObj(1, &pathPtr); + return TclJoinPath(objc, objv); } - - for (i = 0; i<objc;i++) { - Tcl_ListObjAppendElement(NULL, lobj, objv[i]); + if (objc == 0) { + return TclJoinPath(1, &pathPtr); } - ret = Tcl_FSJoinPath(lobj, -1); - - /* - * It is possible that 'ret' is just a member of the list and is therefore - * going to be freed here. Therefore we must adjust the refCount manually. - * (It would be better if we changed the documentation of this function - * and Tcl_FSJoinPath so that the returned object already has a refCount - * for the caller, hence avoiding these subtleties (and code ugliness)). - */ + if (objc == 1) { + Tcl_Obj *pair[2]; - Tcl_IncrRefCount(ret); - Tcl_DecrRefCount(lobj); - ret->refCount--; - return ret; + pair[0] = pathPtr; + pair[1] = objv[0]; + return TclJoinPath(2, pair); + } else { + int elemc = objc + 1; + Tcl_Obj *ret, **elemv = ckalloc(elemc*sizeof(Tcl_Obj **)); + + elemv[0] = pathPtr; + memcpy(elemv+1, objv, objc*sizeof(Tcl_Obj **)); + ret = TclJoinPath(elemc, elemv); + ckfree(elemv); + return ret; + } } /* |