Re: Differing namespace behavior in Tcl 9.0b2

Liste des GroupesRevenir à cl tcl 
Sujet : Re: Differing namespace behavior in Tcl 9.0b2
De : amangogna (at) *nospam* modelrealization.com (Andrew Mangogna)
Groupes : comp.lang.tcl
Date : 17. Jul 2024, 19:09:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v791bu$1uodl$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 7/17/24 01:04, Andreas Leitgeb wrote:
Andrew Mangogna <amangogna@modelrealization.com> wrote:
I have been out of the Tcl loop for a while, but have been porting an old
"C" based extension of mine to Tcl 9.0b2. The port went well, required
very few changes, but I have some differing behavior that I'm trying to
track down. The package consists of an ensemble command, "ral" which
has three subcommands implemented in the "::ral" namespace. Each of
the subcommands is also exported from the namespace. The following shows
the problems:
 The behaviour looks buggy to me, but without knowing what
your package ral really does, it's hard to judge.
 The only commonly known change w.r.t. namespaces in Tcl9 is
that change about variable lookup (already mentioned in other
replies).
 Could you try to reproduce it with a simple package, that
exhibits the same difference 8.6 vs 9.0 ?
 
% namespace export
tuple relation relvar       <- unexpected -- ral exports these commands
                             <- but they shouldn't appear in the global
                             <- namespace
 Maybe your code does an export on these commands, but only in Tcl9 it
effectively does the "export" from global namespace...
 That *might* be a Tcl9 bug, but it would be very interesting how
that is triggered.
 Btw., a command does not need to exist in a particular namespace to
be "export"-able from there.
 
I didn't want to drop a big pile of code, but here is the package init function where the commands and ensemble are created. This is old code, most of it dating from 2014.
-----------
DLLEXPORT
int
ral_Init(
     Tcl_Interp *interp)
{
     static char const tupleCmdName[] = "::ral::tuple" ;
     static char const tupleStr[] = "tuple" ;
     static char const relationCmdName[] = "::ral::relation" ;
     static char const relationStr[] = "relation" ;
     static char const relvarCmdName[] = "::ral::relvar" ;
     static char const relvarStr[] = "relvar" ;
     static char const pkgNamespace[] = "::ral" ;
     Ral_RelvarInfo rInfo ;
     Tcl_Obj *mapObj ;
     Tcl_Command ensembleCmdToken ;
     Tcl_Namespace *ralNs ;
     if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
         return TCL_ERROR ;
     }
     if (Tcl_TomMath_InitStubs(interp, TCL_VERSION) == NULL) {
         return TCL_ERROR ;
     }
     /*
      * Create the namespace in which the package command reside.
      */
     ralNs = Tcl_CreateNamespace(interp, pkgNamespace, NULL, NULL) ;
     /*
      * Create the package commands.
      * First the "tuple" command.
      */
     mapObj = Tcl_NewDictObj() ;
     Tcl_CreateObjCommand(interp, tupleCmdName, tupleCmd, NULL, NULL) ;
     if (Tcl_Export(interp, ralNs, tupleStr, 0) != TCL_OK) {
         goto errorout ;
     }
     if (Tcl_DictObjPut(interp, mapObj,
                 Tcl_NewStringObj(tupleStr, -1),
                 Tcl_NewStringObj(tupleCmdName, -1)) != TCL_OK) {
         goto errorout ;
     }
     /*
      * Next the "relation" command.
      */
     Tcl_CreateObjCommand(interp, relationCmdName, relationCmd, NULL, NULL) ;
     if (Tcl_Export(interp, ralNs, relationStr, 0) != TCL_OK) {
         goto errorout ;
     }
     if (Tcl_DictObjPut(interp, mapObj,
                 Tcl_NewStringObj(relationStr, -1),
                 Tcl_NewStringObj(relationCmdName, -1)) != TCL_OK) {
         goto errorout ;
     }
     /*
      * Finally, the "relvar" command.
      */
     rInfo = Ral_RelvarNewInfo(ral_pkgname, interp) ;
     Tcl_CreateObjCommand(interp, relvarCmdName, relvarCmd, rInfo, NULL) ;
     if (Tcl_Export(interp, ralNs, relvarStr, 0) != TCL_OK) {
         goto errorout ;
     }
     if (Tcl_DictObjPut(interp, mapObj,
                 Tcl_NewStringObj(relvarStr, -1),
                 Tcl_NewStringObj(relvarCmdName, -1)) != TCL_OK) {
}
     /*
      * Create an ensemble command on the namespace.
      */
     ensembleCmdToken = Tcl_CreateEnsemble(interp, "::ral", ralNs, 0) ;
     /*
      * Following the pattern in Tcl sources, we set the mapping dictionary
      * of the ensemble. This will allow the ensemble to be extended
      * at the script level.
      */
     if (Tcl_SetEnsembleMappingDict(interp, ensembleCmdToken, mapObj) !=
             TCL_OK) {
         goto errorout ;
     }
     /*
      * Support for package configuration.
      */
     Tcl_RegisterConfig(interp, ral_pkgname, ral_config, "iso8859-1") ;
     Tcl_PkgProvide(interp, ral_pkgname, ral_version) ;
     return TCL_OK ;
errorout:
     Tcl_DecrRefCount(mapObj) ;
     return TCL_ERROR ;
}
-----------
Andrew Mangogna

Date Sujet#  Auteur
16 Jul 24 * Differing namespace behavior in Tcl 9.0b26Andrew Mangogna
17 Jul 24 +- Re: Differing namespace behavior in Tcl 9.0b21et99
17 Jul 24 +- Re: Differing namespace behavior in Tcl 9.0b21Ashok
17 Jul 24 +- Re: Differing namespace behavior in Tcl 9.0b21Ashok
17 Jul 24 `* Re: Differing namespace behavior in Tcl 9.0b22Andreas Leitgeb
17 Jul 24  `- Re: Differing namespace behavior in Tcl 9.0b21Andrew Mangogna

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal