Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e7a9fcf368fa3f6b9d5ee4bbcacfd2ca2044969847ffbeb327fa3efc34049b3b
Ticket: 1e62dd74f70cf7ba7af3b34f0dfeffc9db529665
User & Date: anonymous on 2021-04-01 20:12:15
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/html"
  4. comment changed to:
    I'm a beginner at Tcl C API and I'm trying to understand how to use it. I have this code that gets a tcl list from <b>get_my_list</b> proc and then I iterate over it to dispatch some info, in this case, info related to attributes <b>A</b>, <b>B</b> and <b>C</b> that I get with <b>get_attr_info</b> proc. When I run it in a very simple example that basically has only this code, everything works perfectly, but when I add this lib in a big tcl project, eventually it crashes. I suspect that it's due to bad usage of reference counting of tcl objects, I mean, their lifetimes. What could I be doing wrong in the example below? I'm using Tcl 8.6.
    
    <pre>
        Tcl_Obj* Get_Info(Tcl_Interp *interp, const char* info, const char* attr) {
            char cmd[256];
            sprintf(cmd, "get_attr_info %s %s", info, attr);
            Tcl_Eval(interp, cmd);
            return Tcl_GetObjResult(interp);
        }
        
        static int Copy_Info(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) {
            Tcl_Eval(interp, "get_my_list");
            Tcl_Obj *const my_list = Tcl_GetObjResult(interp);
            int my_list_size;
            Tcl_ListObjLength(interp, my_list, &my_list_size);
            Tcl_IncrRefCount(my_list);
        
            for (int i = 0; i < my_list_size; ++i) {
                Tcl_Obj* current_info_obj;
                Tcl_ListObjIndex(interp, my_list, i, &current_info_obj);
                const char* current_info_ctr = Tcl_GetStringFromObj(current_info_obj, NULL);
        
                /* getting info A */
                Tcl_Obj* info_a_obj = Get_Info(current_info_ctr, "A");
                const char* info_a = Tcl_GetStringFromObj(info_a_obj, NULL);
                Copy_Info_A(info_a);
        
                /* getting info B */
                Tcl_Obj* info_b_obj = Get_Info(current_info_ctr, "B");
                const char* info_b = Tcl_GetStringFromObj(info_b_obj, NULL);
                Copy_Info_B(info_b);
        
                /* getting info C */
                Tcl_Obj* info_c_obj = Get_Info(current_info_ctr, "C");
                const char* info_c = Tcl_GetStringFromObj(info_c_obj, NULL);
                Copy_Info_C(info_c);
            }
        
            Tcl_DecrRefCount(my_list);
            Tcl_FreeResult(interp);
        
            return TCL_OK;
        }
    </pre>
    
  5. foundin changed to: "8.6.9"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "72f45757fef114fab939039233287ada6529da32"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "07. Variables"
  15. type changed to: "Support"