Quantcast

infinitе loop in freeIntRepProc()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

infinitе loop in freeIntRepProc()

Александр Митрохин
typedef.c

 94                 case 1:
 95                         assert(obj == Tcl_GetObjResult(TCLOBJ_INTERP(*obj)));
 96                         obj->refCount++;
 97                         Tcl_ResetResult(TCLOBJ_INTERP(*obj));
 98                         obj->refCount--;
 99                         break;

this fradment of code solve trouble, but it looks as hack.

 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: infinitе loop in freeIntRepProc()

Dipl. Ing. Sergey G. Brester

This will not "solve the trouble", but rather will produce a leak.

By the tcl reference counting, you should:

1) never use decrement directly (Tcl_DecrRefCount)

2) by switching of references first always increment then decrement:
```
Tcl_IncrRefCount(newref);
Tcl_DecrRefCount(*oldref);
*oldref = newref;

```
If you'll do it vice versa it may be wrong if coincidentally `*oldref` already equal `newref` (and was the last ref)

3) It looks like you've a cross reference (the interp in object and same object in this interp). If so (resp. it may be possible) you should rethink your referencing concept.
For example using some weak pointer mechanism for the interp inside of the object (instead of the tcl referencing);

4) Tcl_ResetResult decrements a reference of the current result object in the given interpreter. But this object can be a part of something other - any list within this interp (so can be deleted together with the list), etc.

5) If you object represents an interpreter you should additionally use `Tcl_Preserve(interp)` with counterpart `Tcl_Release/Tcl_EventuallyFree` to prevent unexpected deleting the interpreter handle.

You've provided just too few details to say exactly what going wrong here.

Regards,
sebres.

 

Am 24.03.2017 08:27, schrieb Александр Митрохин:

typedef.c

 94                 case 1:
 95                         assert(obj == Tcl_GetObjResult(TCLOBJ_INTERP(*obj)));
 96                         obj->refCount++;
 97                         Tcl_ResetResult(TCLOBJ_INTERP(*obj));
 98                         obj->refCount--;
 99                         break;

this fradment of code solve trouble, but it looks as hack.

 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Tcl-Core mailing list
Tcl-Core@...
https://lists.sourceforge.net/lists/listinfo/tcl-core

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: infinitе loop in freeIntRepProc()

Александр Митрохин
Пятница, 24 марта 2017, 15:09 +07:00 от "Dipl. Ing. Sergey G. Brester" <[hidden email]>:
This will not "solve the trouble", but rather will produce a leak.


By the tcl reference counting, you should:

1) never use decrement directly (Tcl_DecrRefCount)

2) by switching of references first always increment then decrement:
```
Tcl_IncrRefCount(newref);
Tcl_DecrRefCount(*oldref);
*oldref = newref;

```
If you'll do it vice versa it may be wrong if coincidentally `*oldref` already equal `newref` (and was the last ref)

3) It looks like you've a cross reference (the interp in object and same object in this interp). If so (resp. it may be possible) you should rethink your referencing concept.
For example using some weak pointer mechanism for the interp inside of the object (instead of the tcl referencing);

4) Tcl_ResetResult decrements a reference of the current result object in the given interpreter. But this object can be a part of something other - any list within this interp (so can be deleted together with the list), etc.

5) If you object represents an interpreter you should additionally use `Tcl_Preserve(interp)` with counterpart `Tcl_Release/Tcl_EventuallyFree` to prevent unexpected deleting the interpreter handle.

You've provided just too few details to say exactly what going wrong here.


http://tcl.uk.to/typedef.c

I want to reset the pointer interp->objResultPtr from the freeIntRepProc() procedure so that not to call freeIntRepProc(). :)


switch (obj->refCount) {
...
case 1:
    assert(obj == TCLOBJ_INTERP(*obj)->resultObjPtr);
    TCLOBJ_INTERP(*obj)->resultObjPtr = NULL;
    obj->refCount = 0;
    break
...
}

but i have no access to field interp->objResultPtr.

/*
 *----------------------------------------------------------------------------
 * Data structures defined opaquely in this module. The definitions below just
 * provide dummy types. A few fields are made visible in Tcl_Interp
 * structures, namely those used for returning a string result from commands.
 * Direct access to the result field is discouraged in Tcl 8.0. The
 * interpreter result is either an object or a string, and the two values are
 * kept consistent unless some C code sets interp->result directly.
 * Programmers should use either the function Tcl_GetObjResult() or
 * Tcl_GetStringResult() to read the interpreter's result. See the SetResult
 * man page for details.
 *
 * Note: any change to the Tcl_Interp definition below must be mirrored in the
 * "real" definition in tclInt.h.
 *
 * Note: Tcl_ObjCmdProc functions do not directly set result and freeProc.
 * Instead, they set a Tcl_Obj member in the "real" structure that can be
 * accessed with Tcl_GetObjResult() and Tcl_SetObjResult().
 */

typedef struct Tcl_Interp
#ifndef TCL_NO_DEPRECATED
{
    /* TIP #330: Strongly discourage extensions from using the string
     * result. */
#ifdef USE_INTERP_RESULT
    char *result TCL_DEPRECATED_API("use Tcl_GetStringResult/Tcl_SetResult");
                                /* If the last command returned a string
                                 * result, this points to it. */
    void (*freeProc) (char *blockPtr)
            TCL_DEPRECATED_API("use Tcl_GetStringResult/Tcl_SetResult");
                                /* Zero means the string result is statically
                                 * allocated. TCL_DYNAMIC means it was
                                 * allocated with ckalloc and should be freed
                                 * with ckfree. Other values give the address
                                 * of function to invoke to free the result.
                                 * Tcl_Eval must free it before executing next
                                 * command. */
#else
    char *resultDontUse; /* Don't use in extensions! */
    void (*freeProcDontUse) (char *); /* Don't use in extensions! */
#endif
#ifdef USE_INTERP_ERRORLINE
    int errorLine TCL_DEPRECATED_API("use Tcl_GetErrorLine/Tcl_SetErrorLine");
                                /* When TCL_ERROR is returned, this gives the
                                 * line number within the command where the
                                 * error occurred (1 if first line). */
#else
    int errorLineDontUse; /* Don't use in extensions! */
#endif
}
#endif /* TCL_NO_DEPRECATED */
Tcl_Interp;


and i try to set refCount = 2, call Tcl_ResetResult(), and free internal representation late in freeIntRepProc() self...

/swp

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-core
Loading...