Fossil

Check-in [b04d5ab4]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:When there are no command line arguments, set the argv script variable to an empty list.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tcl-argv-handling-v2
Files: files | file ages | folders
SHA1:b04d5ab4af33e31214f45f5cc1120196f1ef04fa
User & Date: mistachkin 2012-08-22 11:33:20
Context
2012-08-22
11:42
Always call Tcl_FindExecutable, even when the command line arguments are invalid. Closed-Leaf check-in: a7392129 user: mistachkin tags: tcl-argv-handling-v2
11:33
When there are no command line arguments, set the argv script variable to an empty list. check-in: b04d5ab4 user: mistachkin tags: tcl-argv-handling-v2
11:15
Modify the Tcl argument handling to deal with object reference counts and errors. check-in: 46864ac9 user: mistachkin tags: tcl-argv-handling-v2
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/th_tcl.c.

379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
...
399
400
401
402
403
404
405
406
407
408

409
410
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
  Tcl_Interp *pInterp,
  int argc,
  char **argv
){
  Tcl_Obj *objPtr;
  Tcl_Obj *resultObjPtr;
  Tcl_Obj *listPtr;
  int rc;
  if( argc<=0 || !argv ){
    return TCL_OK;
  }
  objPtr = Tcl_NewStringObj(argv[0], -1);
  Tcl_IncrRefCount(objPtr);
  resultObjPtr = Tcl_SetVar2Ex(pInterp, "argv0", NULL, objPtr,
      TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
................................................................................
  Tcl_IncrRefCount(objPtr);
  resultObjPtr = Tcl_SetVar2Ex(pInterp, "argc", NULL, objPtr,
      TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
  Tcl_DecrRefCount(objPtr);
  if( !resultObjPtr ){
    return TCL_ERROR;
  }
  if( argc>1 ){
    listPtr = Tcl_NewListObj(0, NULL);
    Tcl_IncrRefCount(listPtr);

    while( --argc ){
      objPtr = Tcl_NewStringObj(*++argv, -1);
      Tcl_IncrRefCount(objPtr);
      rc = Tcl_ListObjAppendElement(pInterp, listPtr, objPtr);
      Tcl_DecrRefCount(objPtr);
      if( rc!=TCL_OK ){
        break;
      }
    }

    if( rc==TCL_OK ){
      resultObjPtr = Tcl_SetVar2Ex(pInterp, "argv", NULL, listPtr,
          TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
      if( !resultObjPtr ){
        rc = TCL_ERROR;
      }
    }
    Tcl_DecrRefCount(listPtr);
  }
  return rc;
}

/*
** Creates and initializes a Tcl interpreter for use with the specified TH1
** interpreter.  Stores the created Tcl interpreter in the Tcl context supplied
** by the caller.







|







 







<
|
|
>









>
|
|
|
|
|
|
|
|
<







379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
...
399
400
401
402
403
404
405

406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426

427
428
429
430
431
432
433
  Tcl_Interp *pInterp,
  int argc,
  char **argv
){
  Tcl_Obj *objPtr;
  Tcl_Obj *resultObjPtr;
  Tcl_Obj *listPtr;
  int rc = TCL_OK;
  if( argc<=0 || !argv ){
    return TCL_OK;
  }
  objPtr = Tcl_NewStringObj(argv[0], -1);
  Tcl_IncrRefCount(objPtr);
  resultObjPtr = Tcl_SetVar2Ex(pInterp, "argv0", NULL, objPtr,
      TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
................................................................................
  Tcl_IncrRefCount(objPtr);
  resultObjPtr = Tcl_SetVar2Ex(pInterp, "argc", NULL, objPtr,
      TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
  Tcl_DecrRefCount(objPtr);
  if( !resultObjPtr ){
    return TCL_ERROR;
  }

  listPtr = Tcl_NewListObj(0, NULL);
  Tcl_IncrRefCount(listPtr);
  if( argc>1 ){
    while( --argc ){
      objPtr = Tcl_NewStringObj(*++argv, -1);
      Tcl_IncrRefCount(objPtr);
      rc = Tcl_ListObjAppendElement(pInterp, listPtr, objPtr);
      Tcl_DecrRefCount(objPtr);
      if( rc!=TCL_OK ){
        break;
      }
    }
  }
  if( rc==TCL_OK ){
    resultObjPtr = Tcl_SetVar2Ex(pInterp, "argv", NULL, listPtr,
        TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
    if( !resultObjPtr ){
      rc = TCL_ERROR;
    }
  }
  Tcl_DecrRefCount(listPtr);

  return rc;
}

/*
** Creates and initializes a Tcl interpreter for use with the specified TH1
** interpreter.  Stores the created Tcl interpreter in the Tcl context supplied
** by the caller.