Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

I am the wandering glitch -- catch me if you can.


devel / comp.lang.tcl / Re: TCL "c" api question

SubjectAuthor
* TCL "c" api questionaotto1968
+* Re: TCL "c" api questionRich
|`- Re: TCL "c" api questionted@loft.tnolan.com (Ted Nolan
`* Re: TCL "c" api questionRalf Fassel
 `- Re: TCL "c" api questionaotto1968

1
TCL "c" api question

<uvlh7b$sk0s$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13660&group=comp.lang.tcl#13660

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: TCL "c" api question
Date: Tue, 16 Apr 2024 11:43:05 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <uvlh7b$sk0s$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 16 Apr 2024 11:43:07 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ec0e78604693d5e92f6c660bea279a7c";
logging-data="938012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185NrfdbC6NAlcv8oesY759i6AbJWKvz3Y="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:HGVCMFKt6DyrgxfCq7m22hDzouI=
Content-Language: en-US
 by: aotto1968 - Tue, 16 Apr 2024 09:43 UTC

Hi,

→ the tcl "C" structure "Tcl_Obj" is defined in "man Tcl_NewObj" like:

THE TCL_OBJ STRUCTURE
Each Tcl value is represented by a Tcl_Obj structure which is defined as follows.

typedef struct Tcl_Obj {
int refCount;
char *bytes;
int length;
const Tcl_ObjType *typePtr;
union {
long longValue;
double doubleValue;
void *otherValuePtr;
Tcl_WideInt wideValue;
struct {
void *ptr1;
void *ptr2;
} twoPtrValue;
struct {
void *ptr;
unsigned long value;
} ptrAndLongRep;
} internalRep;
} Tcl_Obj;

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.

usually a pointer can be addend to a PROC or an OO-OBJECT including
a "destructor" to cleanup the data if the PROC or an OO-OBJECT is deleted.

> the "Tcl_Obj" has no official "interface" for adding a pointer etc.

→ I'm aware that the "ptrAndLongRep" solution has a memory-leak because if the "Tcl_Obj" disappears
the "ptrAndLongRep" pointer is lost.

→ the "alternative" is that I always re-parse the "Tcl_Obj", even if the same "Tcl_Obj" is used ~1 Mio times
in a loop

mfg, ao

Re: TCL "c" api question

<uvm19o$100nc$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13662&group=comp.lang.tcl#13662

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: TCL "c" api question
Date: Tue, 16 Apr 2024 14:17:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <uvm19o$100nc$1@dont-email.me>
References: <uvlh7b$sk0s$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 16 Apr 2024 16:17:29 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="438ac2c61fe534e5390aa9379719fb7a";
logging-data="1049324"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18g5cfGppaVw+/vXapxSRgc"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:ma27w9uxWlulRptBERnVc35H9OA=
 by: Rich - Tue, 16 Apr 2024 14:17 UTC

aotto1968 <aotto1968@t-online.de> wrote:
> → 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.

Re: TCL "c" api question

<l87hfhFcdd2U1@mid.individual.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13663&group=comp.lang.tcl#13663

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: @ednolan (ted@loft.tnolan.com (Ted Nolan)
Newsgroups: comp.lang.tcl
Subject: Re: TCL "c" api question
Date: 16 Apr 2024 14:49:21 GMT
Organization: loft
Lines: 50
Message-ID: <l87hfhFcdd2U1@mid.individual.net>
References: <uvlh7b$sk0s$1@dont-email.me> <uvm19o$100nc$1@dont-email.me>
X-Trace: individual.net x1sGVeULu3LKZrDwsQoUwgOHFL2Pvvc3bMz25pBt8nzqvvKcZd
X-Orig-Path: not-for-mail
Cancel-Lock: sha1:OZ1NFLLNnHXH8D6XRgmlijOlptA= sha256:ZBlIo/XGulaD93kxNNmKj/r4Q4tiECOVBbjcQorcedg=
X-Newsreader: trn 4.0-test76 (Apr 2, 2001)
 by: ted@loft.tnolan.com - Tue, 16 Apr 2024 14:49 UTC

In article <uvm19o$100nc$1@dont-email.me>, Rich <rich@example.invalid> wrote:
>aotto1968 <aotto1968@t-online.de> wrote:
>> → 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.

In wrapping various libraries, I have often just returned pointer values
to Tcl as integers. As long as the Tcl code treats it as opaque and
just passes it back in when needed, it works fine. From time to time
I have also passed structures in and out as base64 encoded text which
also works fine as long as you are careful at the C level. Not the
most efficient thing in the world, but not a problem for my cases.
--
columbiaclosings.com
What's not in Columbia anymore..

Re: TCL "c" api question

<ygacyqpia8m.fsf@panther.akutech-local.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13664&group=comp.lang.tcl#13664

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: TCL "c" api question
Date: Tue, 16 Apr 2024 17:43:37 +0200
Lines: 13
Message-ID: <ygacyqpia8m.fsf@panther.akutech-local.de>
References: <uvlh7b$sk0s$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net FjUWq1V0vHz+0uSaX6tTQg292MwDkgFoNpyctPgcYqWEeTfz0=
Cancel-Lock: sha1:I1WZ16RQimVxeVvHq3H0lTHjxdM= sha1:I6kE/QL8eqkqZ5JLLR087AyHX4g= sha256:wVIdzcjpMswYL902l0MXIdFGtVFKNdy1AvpRJPo7zY0=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Tue, 16 Apr 2024 15:43 UTC

* 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'

Re: TCL "c" api question

<uvmcqp$12gdd$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13666&group=comp.lang.tcl#13666

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: Re: TCL "c" api question
Date: Tue, 16 Apr 2024 19:34:17 +0200
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <uvmcqp$12gdd$1@dont-email.me>
References: <uvlh7b$sk0s$1@dont-email.me>
<ygacyqpia8m.fsf@panther.akutech-local.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 16 Apr 2024 19:34:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ec0e78604693d5e92f6c660bea279a7c";
logging-data="1130925"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+uAWKNGHyc0GhyECniFAWfsFrlGhfqqEY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:PNVGmMTQonNfFqZFA2mMYqgWsz0=
Content-Language: en-US
In-Reply-To: <ygacyqpia8m.fsf@panther.akutech-local.de>
 by: aotto1968 - Tue, 16 Apr 2024 17:34 UTC

On 16.04.24 17:43, Ralf Fassel wrote:
> * 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'

I know that a new object type could do the job but I thing this is "over-engineering" just to store an
pointer in a "Tcl_Obj"

The "integer" idea is not working because the INPUT "Tcl_Obj" is *shared* with the calling *level*

mfg

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor