Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a489c5d28da421ecff040db7d9741275bec51f4b
Ticket: 624919ffffffffffffffffffffffffffffffffff
Tcl_AppendToObj docs confusing
User & Date: nobody on 2002-10-21 23:55:12
Changes

  1. icomment:
    Logged In: NO 
    
    Fair enough. Here's a sample that fails.
    
    C Source code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #ifdef _MSC_VER
    #include <io.h>
    #include <fcntl.h>
    #include <winsock.h>
    #endif
    #include "tcl.h"
    
    int test_tcl(ClientData clientData, Tcl_Interp *interp, int argc, 
    char **argv) {
    int i;
    char buffer[512];
    Tcl_Obj *element, *theList, *theString;
    
    theString = Tcl_NewStringObj("ELEMENTLIST", -
    1);
    theList = Tcl_NewListObj(1, &theString);
    
    sprintf(buffer,"");
    element = Tcl_NewStringObj(buffer, strlen(buffer));
    
    strcpy(buffer,"21 test");
    i = strlen(buffer);
    buffer[i] = (char) NULL;
    i++;
    Tcl_AppendToObj(element,buffer,i);
    
    Tcl_ListObjAppendElement(NULL,theList,element);
    Tcl_SetObjResult(interp,theList);
    return(TCL_OK);
    }
    
    #ifdef WIN32
    __declspec(dllexport)
    #endif
    int Testtcl_Init(Tcl_Interp *interp)
    {
    Tcl_CreateCommand
    (interp, "testobject", test_tcl, (ClientData) NULL, 
    (Tcl_CmdDeleteProc *)NULL);
    return(TCL_OK);
    }
    
    Compile the source into a shared library (I've done this on 
    both PC and SGI, and both fail).
    
    Then start tclsh and execute this script:
    % load testtcl.dll
    % array set a [testobject]
    % parray a
    a(ELEMENTLIST) = 21 test
    % set b $a(ELEMENTLIST)
    21 test
    % string length $b
    8
    % set r($b) 2
    2
    % puts $r($b)
    2
    % info exists r($b)
    0
    
    -Mahlon
    
    
  2. login: "nobody"
  3. mimetype: "text/plain"
  4. username: "nobody"