Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Your boss is a few sandwiches short of a picnic.


comp / comp.lang.tcl / Re: sample extension: how to beam created proc tolkens to unload procedure

SubjectAuthor
* sample extension: how to beam created proc tolkens to unload procedureHarald Oehlmann
`* Re: sample extension: how to beam created proc tolkens to unload procedureEmiliano
 +- Re: sample extension: how to beam created proc tolkens to unload procedureHarald Oehlmann
 +* Re: sample extension: how to beam created proc tolkens to unload procedureHarald Oehlmann
 |`* Re: sample extension: how to beam created proc tolkens to unload procedureEmiliano
 | +* Re: sample extension: how to beam created proc tolkens to unload procedureHarald Oehlmann
 | |`- Re: sample extension: how to beam created proc tolkens to unload procedureRalf Fassel
 | `- Re: sample extension: how to beam created proc tolkens to unload procedureHarald Oehlmann
 `- Re: sample extension: how to beam created proc tolkens to unload procedureHarald Oehlmann

1
Subject: sample extension: how to beam created proc tolkens to unload procedure
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 10 Dec 2024 09:35 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: sample extension: how to beam created proc tolkens to unload
procedure
Date: Tue, 10 Dec 2024 10:35:46 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <vj921g$t4fh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 10 Dec 2024 10:35:45 +0100 (CET)
Injection-Info: dont-email.me; posting-host="1d2bfd6a637209064bb6be6f570006d2";
logging-data="954865"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zjCKSjF1hFQ/A+MAkwXA4"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:s/oEdHSDfk8rVguKcqzd4zNdaug=
Content-Language: en-GB
View all headers

Hi Wizards,

I am soooo desperate with the sample extension.

Standard functionality like the build-info and the dll unload feels so
complicated. How can we put all this burden to the poor extension
developpers?

Ok, enough moaning !

See here:
https://core.tcl-lang.org/sampleextension/info/2c5e0e025efd0b9f

The two commands sha1 and ::sha1::build-info are created in the init
procedure.
They have to be deleted in the unload procedure.
How do I beam the two "tolkens" to the unload procedure ?

struct CmdClientData {
Tcl_Command sha1CmdTolken;
};

Sample_Init:
struct CmdClientData *cmdClientDataPtr;
cmdClientDataPtr = ckalloc(sizeof(struct Sha1ClientData));
cmdClientDataPtr->sha1CmdTolken = Tcl_CreateObjCommand(
interp, "sha1", (Tcl_ObjCmdProc *)Sha1_Cmd,
sha1ClientDataPtr, Sha1_CmdDeleteProc);

Sample_Unload:
??? How to get cmdClientDataPtr access here ???
Tcl_DeleteCommandFromToken(interp, cmdClientDataPtr->sha1CmdTolken);
ckfree(cmdClientDataPtr);

---

And of cause, the git magic is not working for build-info - it does not
build any more without git - info how this may work is nowhere...

But that is the next step.

Thanks for any idea!
Harald

Subject: Re: sample extension: how to beam created proc tolkens to unload procedure
From: Emiliano
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 10 Dec 2024 15:13 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: emil.g@example.invalid (Emiliano)
Newsgroups: comp.lang.tcl
Subject: Re: sample extension: how to beam created proc tolkens to unload
procedure
Date: Tue, 10 Dec 2024 12:13:05 -0300
Organization: A noiseless patient Spider
Lines: 91
Message-ID: <20241210121305.783c35bc867324876cf3ec2b@example.invalid>
References: <vj921g$t4fh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 10 Dec 2024 16:13:10 +0100 (CET)
Injection-Info: dont-email.me; posting-host="35c604c332529d27293aecbe85641275";
logging-data="1076909"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+ioNlAL+Ry2esS+LU9nUMzS+Q1d0DM3c="
Cancel-Lock: sha1:VSwnvdXjSr6bm75f/g+m/ftBJDs=
X-Newsreader: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu)
View all headers

On Tue, 10 Dec 2024 10:35:46 +0100
Harald Oehlmann <wortkarg3@yahoo.com> wrote:

> Hi Wizards,
>
> I am soooo desperate with the sample extension.
>
> Standard functionality like the build-info and the dll unload feels so
> complicated. How can we put all this burden to the poor extension
> developpers?
>
> Ok, enough moaning !
>
> See here:
> https://core.tcl-lang.org/sampleextension/info/2c5e0e025efd0b9f
>
> The two commands sha1 and ::sha1::build-info are created in the init
> procedure.
> They have to be deleted in the unload procedure.
> How do I beam the two "tolkens" to the unload procedure ?

> Sample_Init:
> struct CmdClientData *cmdClientDataPtr;
> cmdClientDataPtr = ckalloc(sizeof(struct Sha1ClientData));
-------------------------------------------^
Shouldn't this be "struct CmdClientDataPtr"?
> cmdClientDataPtr->sha1CmdTolken = Tcl_CreateObjCommand(
> interp, "sha1", (Tcl_ObjCmdProc *)Sha1_Cmd,
> sha1ClientDataPtr, Sha1_CmdDeleteProc);
---------------^
Shouldn't this be "cmdClientDataPtr"?
> Sample_Unload:
> ??? How to get cmdClientDataPtr access here ???
> Tcl_DeleteCommandFromToken(interp, cmdClientDataPtr->sha1CmdTolken);
> ckfree(cmdClientDataPtr);

You get (at least!) three "levels" for storing cliendata to Tcl:

* Per command, using the clientdata argument of Tcl_CreateObjCommand().
* Per interp, using Tcl_{Set|Get}AssocData().
* Per thread, using Tcl_GetThreadData().

In this case, Tcl_GetAssocData is to be used, since you want to wipe the
command out from the current interpreter, leaving other interps alone.
A simple example (untested !!!)

#define MY_PKG_KEY "My great package key"
Tcl_InterpDeleteProc pkgInterpDeleted; /* called when the interp is deleted */
struct CmdClientData {
Tcl_Command sha1CmdToken;
};

Sample_Init:
struct CmdClientData *cmdClientDataPtr;
cmdClientDataPtr = ckalloc(sizeof(struct CmdClientData));
Tcl_SetAssocData(interp, MY_PKG_KEY, pkgInterpDeleted, cmdClientDataPtr);
cmdClientDataPtr->sha1CmdToken = Tcl_CreateObjCommand(
interp, "sha1", (Tcl_ObjCmdProc *)Sha1_Cmd,
cmdClientDataPtr, Sha1_CmdDeleteProc);

Sample_Unload:
struct CmdClientData *cmdClientDataPtr = (struct CmdClientData *)
Tcl_GetAssocData(interp, MY_PKG_KEY, NULL);
/* check whether the pointer is not NULL */
Tcl_DeleteCommandFromToken(interp, cmdClientDataPtr->sha1CmdToken);
ckfree(cmdClientDataPtr);
Tcl_DeleteAssocData(interp, MY_PKG_KEY);

Of course you have to juggle the interaction of Sample_Unload,
Sha1CmdDeleteProc and pkgInterpDeleted, since they can be called when:

* [sha1] cmd is deleted (Sha1_CmdDeleteProc is called).
* interp is destroyed (pkgInterpDeleted is called).
* [unload] is called on the external library (Sample_Unload is called).

Hope this helps.

> And of cause, the git magic is not working for build-info - it does not
> build any more without git - info how this may work is nowhere...
>
> But that is the next step.

No idea here, sorry.

> Thanks for any idea!
> Harald

--
Emiliano

Subject: Re: sample extension: how to beam created proc tolkens to unload procedure
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 10 Dec 2024 15:41 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: sample extension: how to beam created proc tolkens to unload
procedure
Date: Tue, 10 Dec 2024 16:41:53 +0100
Organization: A noiseless patient Spider
Lines: 99
Message-ID: <vj9ng1$t4fh$2@dont-email.me>
References: <vj921g$t4fh$1@dont-email.me>
<20241210121305.783c35bc867324876cf3ec2b@example.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 10 Dec 2024 16:41:54 +0100 (CET)
Injection-Info: dont-email.me; posting-host="1d2bfd6a637209064bb6be6f570006d2";
logging-data="954865"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CF55mNTEkyru9lC5CeTki"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Q0vSTnUg6f94T9zNs9DL2+e4fxg=
In-Reply-To: <20241210121305.783c35bc867324876cf3ec2b@example.invalid>
Content-Language: en-GB
View all headers

Am 10.12.2024 um 16:13 schrieb Emiliano:
> On Tue, 10 Dec 2024 10:35:46 +0100
> Harald Oehlmann <wortkarg3@yahoo.com> wrote:
>
>> Hi Wizards,
>>
>> I am soooo desperate with the sample extension.
>>
>> Standard functionality like the build-info and the dll unload feels so
>> complicated. How can we put all this burden to the poor extension
>> developpers?
>>
>> Ok, enough moaning !
>>
>> See here:
>> https://core.tcl-lang.org/sampleextension/info/2c5e0e025efd0b9f
>>
>> The two commands sha1 and ::sha1::build-info are created in the init
>> procedure.
>> They have to be deleted in the unload procedure.
>> How do I beam the two "tolkens" to the unload procedure ?
>
>> Sample_Init:
>> struct CmdClientData *cmdClientDataPtr;
>> cmdClientDataPtr = ckalloc(sizeof(struct Sha1ClientData));
> -------------------------------------------^
> Shouldn't this be "struct CmdClientDataPtr"?
>> cmdClientDataPtr->sha1CmdTolken = Tcl_CreateObjCommand(
>> interp, "sha1", (Tcl_ObjCmdProc *)Sha1_Cmd,
>> sha1ClientDataPtr, Sha1_CmdDeleteProc);
> ---------------^
> Shouldn't this be "cmdClientDataPtr"?
>
>> Sample_Unload:
>> ??? How to get cmdClientDataPtr access here ???
>> Tcl_DeleteCommandFromToken(interp, cmdClientDataPtr->sha1CmdTolken);
>> ckfree(cmdClientDataPtr);
>
> You get (at least!) three "levels" for storing cliendata to Tcl:
>
> * Per command, using the clientdata argument of Tcl_CreateObjCommand().
> * Per interp, using Tcl_{Set|Get}AssocData().
> * Per thread, using Tcl_GetThreadData().
>
> In this case, Tcl_GetAssocData is to be used, since you want to wipe the
> command out from the current interpreter, leaving other interps alone.
> A simple example (untested !!!)
>
> #define MY_PKG_KEY "My great package key"
> Tcl_InterpDeleteProc pkgInterpDeleted; /* called when the interp is deleted */
> struct CmdClientData {
> Tcl_Command sha1CmdToken;
> };
>
> Sample_Init:
> struct CmdClientData *cmdClientDataPtr;
> cmdClientDataPtr = ckalloc(sizeof(struct CmdClientData));
> Tcl_SetAssocData(interp, MY_PKG_KEY, pkgInterpDeleted, cmdClientDataPtr);
> cmdClientDataPtr->sha1CmdToken = Tcl_CreateObjCommand(
> interp, "sha1", (Tcl_ObjCmdProc *)Sha1_Cmd,
> cmdClientDataPtr, Sha1_CmdDeleteProc);
>
> Sample_Unload:
> struct CmdClientData *cmdClientDataPtr = (struct CmdClientData *)
> Tcl_GetAssocData(interp, MY_PKG_KEY, NULL);
> /* check whether the pointer is not NULL */
> Tcl_DeleteCommandFromToken(interp, cmdClientDataPtr->sha1CmdToken);
> ckfree(cmdClientDataPtr);
> Tcl_DeleteAssocData(interp, MY_PKG_KEY);
>
> Of course you have to juggle the interaction of Sample_Unload,
> Sha1CmdDeleteProc and pkgInterpDeleted, since they can be called when:
>
> * [sha1] cmd is deleted (Sha1_CmdDeleteProc is called).
> * interp is destroyed (pkgInterpDeleted is called).
> * [unload] is called on the external library (Sample_Unload is called).
>
> Hope this helps.

Hi Emiliano,

yes, thanks, it helps a lot. It is worse than expected...

So, it is also a good idea, to handle the command clientData via the
command delete proc. This is hopefully called in all cases and is
disjunct to the other cases.

So, we basically have a cleanup-routine, which may be called:
- on interpreter destruction
- on dll unload

So, the dll is not automatically unloaded on interpreter destruction.

If the commands were destroyed by other means (rename sha1 ""), I
suppose, the Tcl_DeleteCommandFromToken will fail but nothing more.

Thanks for all,
Harald

Subject: Re: sample extension: how to beam created proc tolkens to unload procedure
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 10 Dec 2024 16:11 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: sample extension: how to beam created proc tolkens to unload
procedure
Date: Tue, 10 Dec 2024 17:11:08 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <vj9p6s$t4fh$3@dont-email.me>
References: <vj921g$t4fh$1@dont-email.me>
<20241210121305.783c35bc867324876cf3ec2b@example.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 10 Dec 2024 17:11:09 +0100 (CET)
Injection-Info: dont-email.me; posting-host="1d2bfd6a637209064bb6be6f570006d2";
logging-data="954865"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1875YO7THfyDGfKOsROwuIb"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:50ZdxV44i0aTQIFEwmwaJFbDQf0=
In-Reply-To: <20241210121305.783c35bc867324876cf3ec2b@example.invalid>
Content-Language: en-GB
View all headers

Am 10.12.2024 um 16:13 schrieb Emiliano:
> On Tue, 10 Dec 2024 10:35:46 +0100
>> Sample_Init:
>> struct CmdClientData *cmdClientDataPtr;
>> cmdClientDataPtr = ckalloc(sizeof(struct Sha1ClientData));
> -------------------------------------------^
> Shouldn't this be "struct CmdClientDataPtr"?

Yes, good catch

>> cmdClientDataPtr->sha1CmdTolken = Tcl_CreateObjCommand(
>> interp, "sha1", (Tcl_ObjCmdProc *)Sha1_Cmd,
>> sha1ClientDataPtr, Sha1_CmdDeleteProc);
> ---------------^
> Shouldn't this be "cmdClientDataPtr"?

Well, I use a client data for the command "sha1ClientDataPtr" with the
command state, which is deleted by the command delete proc
"Sha1_CmdDeleteProc".

In addition, there is assoc data of the dll "cmdClientDataPtr" to keep
the command tokens for removal within the unload procedure.

Is this design sensible ?

THanks for all,
Harald

Subject: Re: sample extension: how to beam created proc tolkens to unload procedure
From: Emiliano
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 10 Dec 2024 16:37 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: emil.g@example.invalid (Emiliano)
Newsgroups: comp.lang.tcl
Subject: Re: sample extension: how to beam created proc tolkens to unload
procedure
Date: Tue, 10 Dec 2024 13:37:17 -0300
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <20241210133717.db2e1230270895295813d469@example.invalid>
References: <vj921g$t4fh$1@dont-email.me>
<20241210121305.783c35bc867324876cf3ec2b@example.invalid>
<vj9p6s$t4fh$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 10 Dec 2024 17:38:21 +0100 (CET)
Injection-Info: dont-email.me; posting-host="2f4af88da03218da552e43d8c8f31a14";
logging-data="1107000"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+5BGPMsAsgD2Xa95FNNbqKBpMQ17OUlyg="
Cancel-Lock: sha1:UrOhmNqwRycz6HhRwm7Csf8F6qw=
X-Newsreader: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu)
View all headers

On Tue, 10 Dec 2024 17:11:08 +0100
Harald Oehlmann <wortkarg3@yahoo.com> wrote:

> Am 10.12.2024 um 16:13 schrieb Emiliano:
> > On Tue, 10 Dec 2024 10:35:46 +0100
> >> Sample_Init:
> >> struct CmdClientData *cmdClientDataPtr;
> >> cmdClientDataPtr = ckalloc(sizeof(struct Sha1ClientData));
> > -------------------------------------------^
> > Shouldn't this be "struct CmdClientDataPtr"?
>
> Yes, good catch
>
> >> cmdClientDataPtr->sha1CmdTolken = Tcl_CreateObjCommand(
> >> interp, "sha1", (Tcl_ObjCmdProc *)Sha1_Cmd,
> >> sha1ClientDataPtr, Sha1_CmdDeleteProc);
> > ---------------^
> > Shouldn't this be "cmdClientDataPtr"?
>
> Well, I use a client data for the command "sha1ClientDataPtr" with the
> command state, which is deleted by the command delete proc
> "Sha1_CmdDeleteProc".
>
> In addition, there is assoc data of the dll "cmdClientDataPtr" to keep
> the command tokens for removal within the unload procedure.
>
> Is this design sensible ?

Can't say without seeing the real code, but ...

* If you delete the command [sha1], either using [rename] or by deleting
the current interpreter or namespace, you might want to unload the
library as well, and free all allocated resources;
* If you [unload] the library, you might want to also delete the [sha1]
command, and free all allocated resources.
* If you are using Tcl_{Get|Set}AssocData, you have to check the right
time to use ckfree if both cleanup functions depends on clientdata
to be valid. In this case, Tcl_Preserve/Tcl_Release and
Tcl_EventuallyFree might be useful. Or maybe adding a flag in the
clientdata structure to mark "This cleanup function was already been called".

>
> THanks for all,
> Harald

Regards
--
Emiliano

Subject: Re: sample extension: how to beam created proc tolkens to unload procedure
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 10 Dec 2024 17:09 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: sample extension: how to beam created proc tolkens to unload
procedure
Date: Tue, 10 Dec 2024 18:09:43 +0100
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <vj9skn$t4fh$4@dont-email.me>
References: <vj921g$t4fh$1@dont-email.me>
<20241210121305.783c35bc867324876cf3ec2b@example.invalid>
<vj9p6s$t4fh$3@dont-email.me>
<20241210133717.db2e1230270895295813d469@example.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 10 Dec 2024 18:10:12 +0100 (CET)
Injection-Info: dont-email.me; posting-host="1d2bfd6a637209064bb6be6f570006d2";
logging-data="954865"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XM9AJ5u1CvK7S77O2aYZN"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:E5YmeEpeo1cZ0xoAjv8MUnj4SZE=
In-Reply-To: <20241210133717.db2e1230270895295813d469@example.invalid>
Content-Language: en-GB
View all headers

Am 10.12.2024 um 17:37 schrieb Emiliano:
> On Tue, 10 Dec 2024 17:11:08 +0100
> Harald Oehlmann <wortkarg3@yahoo.com> wrote:
>
>> Am 10.12.2024 um 16:13 schrieb Emiliano:
>>> On Tue, 10 Dec 2024 10:35:46 +0100
>>>> Sample_Init:
>>>> struct CmdClientData *cmdClientDataPtr;
>>>> cmdClientDataPtr = ckalloc(sizeof(struct Sha1ClientData));
>>> -------------------------------------------^
>>> Shouldn't this be "struct CmdClientDataPtr"?
>>
>> Yes, good catch
>>
>>>> cmdClientDataPtr->sha1CmdTolken = Tcl_CreateObjCommand(
>>>> interp, "sha1", (Tcl_ObjCmdProc *)Sha1_Cmd,
>>>> sha1ClientDataPtr, Sha1_CmdDeleteProc);
>>> ---------------^
>>> Shouldn't this be "cmdClientDataPtr"?
>>
>> Well, I use a client data for the command "sha1ClientDataPtr" with the
>> command state, which is deleted by the command delete proc
>> "Sha1_CmdDeleteProc".
>>
>> In addition, there is assoc data of the dll "cmdClientDataPtr" to keep
>> the command tokens for removal within the unload procedure.
>>
>> Is this design sensible ?
>
> Can't say without seeing the real code, but ...
>
> * If you delete the command [sha1], either using [rename] or by deleting
> the current interpreter or namespace, you might want to unload the
> library as well, and free all allocated resources;
> * If you [unload] the library, you might want to also delete the [sha1]
> command, and free all allocated resources.
> * If you are using Tcl_{Get|Set}AssocData, you have to check the right
> time to use ckfree if both cleanup functions depends on clientdata
> to be valid. In this case, Tcl_Preserve/Tcl_Release and
> Tcl_EventuallyFree might be useful. Or maybe adding a flag in the
> clientdata structure to mark "This cleanup function was already been called".
>
>>
>> THanks for all,
>> Harald
>
> Regards

Hi Emiliano,
thanks, great !

Here is the current proposal:

https://core.tcl-lang.org/sampleextension/file?name=generic/tclsample.c&ci=tip

I thought, that the command client data is really tied to the command.
And the clean-up is called on command deletion. That is easier, as there
is the clientData pointer at each command interaction (Call, Deletion).

I think, assoc data has only be used for commands, if the data should be
available outside of those interactions, like event processing.
Here, this is not the case.
But it may be added as a comment.

About the DLL, the unload or interpreter destruction should care.

To unload the DLL by "rename sha1 {}" would be an incredible feature I
don't want to think of. Users may use "unload <PathToDll>" to do so.

Thanks for all,
Harald

Subject: Re: sample extension: how to beam created proc tolkens to unload procedure
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Tue, 10 Dec 2024 18:25 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: sample extension: how to beam created proc tolkens to unload procedure
Date: Tue, 10 Dec 2024 19:25:36 +0100
Lines: 22
Message-ID: <yga4j3b8kf3.fsf@akutech.de>
References: <vj921g$t4fh$1@dont-email.me>
<20241210121305.783c35bc867324876cf3ec2b@example.invalid>
<vj9p6s$t4fh$3@dont-email.me>
<20241210133717.db2e1230270895295813d469@example.invalid>
<vj9skn$t4fh$4@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net 4O/uQo9tshgxhcD0SNtZFAqaMD6Oj0U42+xMoSdd6tTGUHCqA=
Cancel-Lock: sha1:uGaghUu7ysz3W+GT793nY9pt9rw= sha1:xv9fSZpI2FivkOLsSmDD546aYmo= sha256:QTZs62j6kDgmn3VEghS9W+b+iVyGw5yr4ODnHU6CJ6U=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
View all headers

* Harald Oehlmann <wortkarg3@yahoo.com>
| About the DLL, the unload or interpreter destruction should care.
>
| To unload the DLL by "rename sha1 {}" would be an incredible feature I
| don't want to think of. Users may use "unload <PathToDll>" to do so.

Unloading the DLL when the command is deleted would have very surprising
side-effects:

# load the package
package require some_pkg
# use it to create an instance
some_pkg::create_obj obj
# done with that instance, get rid of it
rename obj ""

# use it to create another instance
some_pkg::create_obj obj
error: unknown command 'some_pkg::create_obj'
# WTF?

R'

Subject: Re: sample extension: how to beam created proc tolkens to unload procedure
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 10 Dec 2024 17:10 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: sample extension: how to beam created proc tolkens to unload
procedure
Date: Tue, 10 Dec 2024 18:10:04 +0100
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <vja8qn$14epa$1@dont-email.me>
References: <vj921g$t4fh$1@dont-email.me>
<20241210121305.783c35bc867324876cf3ec2b@example.invalid>
<vj9p6s$t4fh$3@dont-email.me>
<20241210133717.db2e1230270895295813d469@example.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 10 Dec 2024 21:38:10 +0100 (CET)
Injection-Info: dont-email.me; posting-host="1cd2cfe0b4adb203b740d0f3fafea229";
logging-data="1194794"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gx8JwLOl1EL4PaC8/GJYQ"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:rtmoLopK31qbgD4cU8XV9XLggGM=
In-Reply-To: <20241210133717.db2e1230270895295813d469@example.invalid>
Content-Language: en-GB
View all headers

Am 10.12.2024 um 17:37 schrieb Emiliano:
> On Tue, 10 Dec 2024 17:11:08 +0100
> Harald Oehlmann <wortkarg3@yahoo.com> wrote:
>
>> Am 10.12.2024 um 16:13 schrieb Emiliano:
>>> On Tue, 10 Dec 2024 10:35:46 +0100
>>>> Sample_Init:
>>>> struct CmdClientData *cmdClientDataPtr;
>>>> cmdClientDataPtr = ckalloc(sizeof(struct Sha1ClientData));
>>> -------------------------------------------^
>>> Shouldn't this be "struct CmdClientDataPtr"?
>>
>> Yes, good catch
>>
>>>> cmdClientDataPtr->sha1CmdTolken = Tcl_CreateObjCommand(
>>>> interp, "sha1", (Tcl_ObjCmdProc *)Sha1_Cmd,
>>>> sha1ClientDataPtr, Sha1_CmdDeleteProc);
>>> ---------------^
>>> Shouldn't this be "cmdClientDataPtr"?
>>
>> Well, I use a client data for the command "sha1ClientDataPtr" with the
>> command state, which is deleted by the command delete proc
>> "Sha1_CmdDeleteProc".
>>
>> In addition, there is assoc data of the dll "cmdClientDataPtr" to keep
>> the command tokens for removal within the unload procedure.
>>
>> Is this design sensible ?
>
> Can't say without seeing the real code, but ...
>
> * If you delete the command [sha1], either using [rename] or by deleting
> the current interpreter or namespace, you might want to unload the
> library as well, and free all allocated resources;
> * If you [unload] the library, you might want to also delete the [sha1]
> command, and free all allocated resources.
> * If you are using Tcl_{Get|Set}AssocData, you have to check the right
> time to use ckfree if both cleanup functions depends on clientdata
> to be valid. In this case, Tcl_Preserve/Tcl_Release and
> Tcl_EventuallyFree might be useful. Or maybe adding a flag in the
> clientdata structure to mark "This cleanup function was already been called".
>
>>
>> THanks for all,
>> Harald
>
> Regards

Hi Emiliano,
thanks, great !

Here is the current proposal:

https://core.tcl-lang.org/sampleextension/file?name=generic/tclsample.c&ci=tip

I thought, that the command client data is really tied to the command.
And the clean-up is called on command deletion. That is easier, as there
is the clientData pointer at each command interaction (Call, Deletion).

I think, assoc data has only be used for commands, if the data should be
available outside of those interactions, like event processing.
Here, this is not the case.
But it may be added as a comment.

About the DLL, the unload or interpreter destruction should care.

To unload the DLL by "rename sha1 {}" would be an incredible feature I
don't want to think of. Users may use "unload <PathToDll>" to do so.

Thanks for all,
Harald

Subject: Re: sample extension: how to beam created proc tolkens to unload procedure
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Wed, 11 Dec 2024 10:27 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: sample extension: how to beam created proc tolkens to unload
procedure
Date: Wed, 11 Dec 2024 11:27:14 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <vjbpe3$1eljb$1@dont-email.me>
References: <vj921g$t4fh$1@dont-email.me>
<20241210121305.783c35bc867324876cf3ec2b@example.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 Dec 2024 11:27:15 +0100 (CET)
Injection-Info: dont-email.me; posting-host="666cb4466d32c5b2e88684559a3a6100";
logging-data="1529451"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/rasJLPLZ0QPPy7CHoWkSL"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:iRd2g35zgnC4QmjtMLM+GjqLp+w=
Content-Language: en-GB
In-Reply-To: <20241210121305.783c35bc867324876cf3ec2b@example.invalid>
View all headers

Am 10.12.2024 um 16:13 schrieb Emiliano:
> On Tue, 10 Dec 2024 10:35:46 +0100
> Harald Oehlmann <wortkarg3@yahoo.com> wrote:
> You get (at least!) three "levels" for storing cliendata to Tcl:
>
> * Per command, using the clientdata argument of Tcl_CreateObjCommand().
> * Per interp, using Tcl_{Set|Get}AssocData().
> * Per thread, using Tcl_GetThreadData().

I found another one. The command
Tcl_CreateNamespace(interp, name, clientData, deleteProc)
also has a clientData and deleteProc argument.

When the command of the sample application is put into a namespace (IMHO
a good practice), we can use the namespace clientData to store the
command tolkens.

This may avoid the associated data.

Thanks for all,
Harald

1

rocksolid light 0.9.8
clearnet tor