tDOM

Check-in [120c8294a0]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Now start to actually use the local key constraint info.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | localkey
Files: files | file ages | folders
SHA3-256: 120c8294a03dda1c21e96db6c03bc452f17f5e7418a5798a1c32aa034659d952
User & Date: rolf 2019-05-17 00:02:41
Context
2019-05-18
00:41
Save work. check-in: 4592100a23 user: rolf tags: localkey
2019-05-17
00:02
Now start to actually use the local key constraint info. check-in: 120c8294a0 user: rolf tags: localkey
2019-05-16
22:25
Still working on digest local key constraint specification: Now support union "Path ( '|' Path )*" for selector and fields. Distinct between element and attribute selecting steps because of the distict spaces of the names. check-in: 69c262ef77 user: rolf tags: localkey
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to generic/schema.c.

   512    512   {
   513    513       SchemaData *sdata = (SchemaData *) clientData;
   514    514       unsigned int i;
   515    515       SchemaValidationStack *down;
   516    516       Tcl_HashEntry *h;
   517    517       Tcl_HashSearch search;
   518    518       SchemaDocKey *dk;
          519  +    KeyState *ks, *nextks;
   519    520   
   520    521       /* Protect the clientData to be freed inside (even nested)
   521    522        * Tcl_Eval*() calls to avoid invalid mem access and postpone the
   522    523        * cleanup until the Tcl_Eval*() calls are finished (done in
   523    524        * schemaInstanceCmd(). */
   524    525       if (sdata->currentEvals) {
   525    526           sdata->cleanupAfterEval = 1;
................................................................................
   577    578            h != NULL;
   578    579            h = Tcl_NextHashEntry (&search)) {
   579    580           dk = Tcl_GetHashValue (h);
   580    581           Tcl_DeleteHashTable (&dk->ids);
   581    582           FREE (dk);
   582    583       }
   583    584       Tcl_DeleteHashTable (&sdata->idTables);
          585  +    ks = sdata->keyStatePool;
          586  +    while (ks) {
          587  +        nextks = ks->next;
          588  +        FREE (ks->values);
          589  +        FREE (ks);
          590  +        ks = nextks;
          591  +    }
   584    592       FREE (sdata);
   585    593   }
   586    594   
   587    595   static void
   588    596   cleanupLastPattern (
   589    597       SchemaData *sdata,
   590    598       unsigned int from
................................................................................
   733    741   static void
   734    742   pushToStack (
   735    743       SchemaData *sdata,
   736    744       SchemaCP *pattern
   737    745       )
   738    746   {
   739    747       SchemaValidationStack *stackElm, *se;
   740         -
          748  +    KeyConstraint *kc;
          749  +    KeyState *ks;
          750  +    
   741    751       DBG(fprintf(stderr, "push to Stack:\n");serializeCP(pattern));
   742    752       if (sdata->stackPool) {
   743    753           stackElm = sdata->stackPool;
   744    754           sdata->stackPool = stackElm->down;
   745    755       } else {
   746    756           stackElm = TMALLOC (SchemaValidationStack);
   747    757       }
................................................................................
   748    758       memset (stackElm, 0, sizeof (SchemaValidationStack));
   749    759       se = sdata->stack;
   750    760       stackElm->down = se;
   751    761       stackElm->pattern = pattern;
   752    762       if (pattern->type == SCHEMA_CTYPE_INTERLEAVE) {
   753    763           stackElm->interleaveState = MALLOC (sizeof (int) * pattern->nc);
   754    764           memset (stackElm->interleaveState, 0, sizeof (int) * pattern->nc);
          765  +    }
          766  +    if (pattern->type == SCHEMA_CTYPE_NAME) {
          767  +        /* Handle local key contraint matches */
          768  +
          769  +        /* And open new local key contraints, if necessary. */
          770  +        kc = pattern->localkeys;
          771  +        while (kc) {
          772  +            if (sdata->keyStatePool) {
          773  +                ks = sdata->keyStatePool;
          774  +                sdata->keyStatePool = ks->next;
          775  +            } else {
          776  +                ks = TMALLOC (KeyState);
          777  +                ks->values = TMALLOC (Tcl_HashTable);
          778  +            }
          779  +            Tcl_InitHashTable (ks->values, TCL_STRING_KEYS);
          780  +            ks->selector = kc->selector;
          781  +            ks->fields = kc->fields;
          782  +            ks->next = stackElm->keyState;
          783  +            stackElm->keyState = ks;
          784  +            kc = kc->next;
          785  +        }
   755    786       }
   756    787       sdata->stack = stackElm;
   757    788   }
   758    789   
   759    790   static void
   760    791   popStack (
   761    792       SchemaData *sdata
   762    793       )
   763    794   {
   764    795       SchemaValidationStack *se;
          796  +    KeyState *ks, *nextks;
   765    797       DBG(fprintf(stderr, "pop from Stack:\n");serializeCP(sdata->stack->pattern));
   766    798       if (sdata->stack->interleaveState) {
   767    799           FREE (sdata->stack->interleaveState);
   768    800           sdata->stack->interleaveState = NULL;
          801  +    }
          802  +    if (sdata->stack->pattern->type == SCHEMA_CTYPE_NAME) {
          803  +        /* Check and cleanup local key contraints */
          804  +        ks = sdata->stack->keyState;
          805  +        while (ks) {
          806  +            nextks = ks->next;
          807  +            Tcl_DeleteHashTable (ks->values);
          808  +            if (sdata->keyStatePool) {
          809  +                ks->next = sdata->keyStatePool;
          810  +            } else {
          811  +                ks->next = NULL;
          812  +            }
          813  +            sdata->keyStatePool = ks;
          814  +            ks = nextks;
          815  +        }
   769    816       }
   770    817       se = sdata->stack->down;
   771    818       sdata->stack->down = sdata->stackPool;
   772    819       sdata->stackPool = sdata->stack;
   773    820       sdata->stack = se;
   774    821   }
   775    822   

Changes to generic/schema.h.

    99     99       char     *name;
   100    100       KeyType   type;
   101    101       KeyStep  *selector;
   102    102       KeyStep **fields;
   103    103       int       nrFields;
   104    104       struct KeyConstraint *next;
   105    105   } KeyConstraint;
          106  +
          107  +typedef struct KeyState 
          108  +{
          109  +    struct KeyState *next;
          110  +    KeyStep         *selector;
          111  +    KeyStep        **fields;
          112  +    Tcl_HashTable   *values;
          113  +} KeyState;
   106    114   
   107    115   typedef struct SchemaCP
   108    116   {
   109    117       Schema_CP_Type    type;
   110    118       char             *namespace;
   111    119       char             *name;
   112    120       struct SchemaCP  *next;
................................................................................
   125    133   {
   126    134       SchemaCP *pattern;
   127    135       struct SchemaValidationStack *next;
   128    136       struct SchemaValidationStack *down;
   129    137       int               activeChild;
   130    138       int               hasMatched;
   131    139       int              *interleaveState;
          140  +    KeyState         *keyState;
   132    141   } SchemaValidationStack;
   133    142   
   134    143   typedef enum {
   135    144       VALIDATION_READY,
   136    145       VALIDATION_STARTED,
   137    146       VALIDATION_ERROR,
   138    147       VALIDATION_FINISHED
................................................................................
   178    187       unsigned int contentSize;
   179    188       SchemaAttr **currentAttrs;
   180    189       unsigned int numAttr;
   181    190       unsigned int numReqAttr;
   182    191       unsigned int attrSize;
   183    192       SchemaValidationStack *stack;
   184    193       SchemaValidationStack *stackPool;
          194  +    KeyState *keyStatePool;
   185    195       ValidationState validationState;
   186    196       unsigned int skipDeep;
   187    197       Tcl_DString *cdata;
   188    198       Tcl_HashTable ids;
   189    199       int unknownIDrefs;
   190    200       Tcl_HashTable idTables;
   191    201   } SchemaData;