the "Tcl_Obj" has no official "interface" for adding a pointer etc.
→ the tcl "C" structure "Tcl_Obj" is defined in "man Tcl_NewObj" like:
...
struct {
void *ptr;
unsigned long value;
} ptrAndLongRep;
My question is if I can use the "ptrAndLongRep" to store my data?
My "Tcl_Obj" is a string representing of a callback and after the
parsing of the string I create the "struct MkCallS*" data. The core
problem is HOW to store this pointer in a "Tcl_Obj" as if the same
"Tcl_Obj" is given as argument again the parsing have not be done
again.
→ the tcl "C" structure "Tcl_Obj" is defined in "man Tcl_NewObj" like:
...
struct {
void *ptr;
unsigned long value;
} ptrAndLongRep;
My question is if I can use the "ptrAndLongRep" to store my data?
Reading into the man page you quote, this sentence occurs:
Because of this representation invalidation and regeneration, it
is dangerous for extension writers to access Tcl_Obj fields
directly.
Which implies a "no" answer to your question.
My "Tcl_Obj" is a string representing of a callback and after the
parsing of the string I create the "struct MkCallS*" data. The core
problem is HOW to store this pointer in a "Tcl_Obj" as if the same
"Tcl_Obj" is given as argument again the parsing have not be done
again.
Hmm? One idea that comes to mind is to store the pointer in an array
in your extension, and store in the Tcl_Obj an integer that is the
array index of the pointer in your array.
That does add one level of indirection as to get to your pointer you >effectively have to do:
ptr = my_array[ getIntFromObj(Tcl_Obj) ];
But it does mean you wouldn't have to 'reparse' a string back into the >internal struct each time.
Danger of course is any 'integer' would look like any other integer and
so a 'random' integer obj that got used that happened to be within the
range of allocted entries in your array would 'pick' that item, even if
it was not the correct one to pick at that time.
* aotto1968 <aotto1968@t-online.de>
| My "Tcl_Obj" is a string representing of a *callback* and after the parsing of the string I create the
| "struct MkCallS*" data. The core problem is HOW to store this pointer in a "Tcl_Obj" as if the
| same "Tcl_Obj" is given as argument again the parsing have *not* be done again.
Can't you register a new obj type via
https://www.tcl.tk/man/tcl8.5/TclLib/ObjectType.htm
? Seems like that would take care of the "not again" parsing if the Obj
is already of the desired type... Haven't verified that, though...
R'
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 307 |
Nodes: | 16 (2 / 14) |
Uptime: | 66:25:08 |
Calls: | 6,915 |
Files: | 12,379 |
Messages: | 5,431,759 |