View Source

[modwtcl]
apreq.h
dist/
libapreq1/
mod_wtcl.c
mod_wtcl.h
setupExclude.txt
util/
win.def
win.mak
wt1.1/
WtAppTable.c
WtAppTable.h
WtBasicCmds.c
WtBasicCmds.h
WtClientRequest.c
WtClientRequest.h
WtCollection.c
WtCollection.h
WtCollectionCmds.c
WtCollectionCmds.h
WtContext.c
WtContext.h
WtContextEvents.c
WtContextEvents.h
WtCookie.c
WtCookie.h
WtDbSession.c
WtDbSession.h
WtExecute.c
WtExecute.h
WtHtmlEntities.c
WtHtmlEntities.h
WtInitCmds.c
WtInitCmds.h
WtMtTable.c
WtMtTable.h
WtMultiTable.c
WtMultiTable.h
WtOS.h
WtProcSession.c
WtProcSession.h
WtResponse.c
WtResponse.h
WtServerCmds.c
WtServerCmds.h
WtSession.c
WtSession.h
WtSettings.c
WtSettings.h
WtTable.c
WtTable.h
WtTableCmds.c
WtTableCmds.h
WtTableUtil.c
WtTableUtil.h
WtUpload.c
WtUpload.h
WtUtil.c
WtUtil.h
WtWebErrors.c
WtWebErrors.h
WtWindows.h
File: / archive / modwtcl / WtMtTable.c

Lines Size Modified Created Owner MIME Types
268 5,731 2010/05/08 18:46:41 2011/06/13 15:35:15 BUILTIN\Administrators text/x-csrc

0001
/*
0002
 * Copyright 2001 Alexander Boverman and the original authors.
0003
 * 
0004
 * Licensed under the Apache License, Version 2.0 (the "License");
0005
 * you may not use this file except in compliance with the License.
0006
 * You may obtain a copy of the License at
0007
 * 
0008
 *      http://www.apache.org/licenses/LICENSE-2.0
0009
 * 
0010
 * Unless required by applicable law or agreed to in writing, software
0011
 * distributed under the License is distributed on an "AS IS" BASIS,
0012
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013
 * See the License for the specific language governing permissions and
0014
 * limitations under the License.
0015
 */
0016
0017
#include "WtMtTable.h"
0018
#include "WtTable.h"
0019
#include "WtUtil.h"
0020
0021
/* Size of the table */
0022
0023
int WtMtTableSize(Tcl_Obj *mtTbl)
0024
{
0025
  int size;
0026
  WtMtTableLock(mtTbl);
0027
  size = WtTableSize(WtMtTableStorage(mtTbl));
0028
  WtMtTableUnlock(mtTbl);
0029
  return size;
0030
}
0031
0032
/* Check if the key exists */
0033
0034
int WtMtTableHas(Tcl_Obj *mtTbl, Tcl_Obj *key)
0035
{
0036
  int ret;
0037
  WtMtTableLock(mtTbl);
0038
  ret = WtTableHas(WtMtTableStorage(mtTbl), key);
0039
  WtMtTableUnlock(mtTbl);
0040
  return ret;
0041
}
0042
0043
/* Get an entry */
0044
0045
Tcl_Obj *WtMtTableGet(Tcl_Obj *mtTbl, Tcl_Obj *key)
0046
{
0047
  Tcl_Obj *val;
0048
  WtMtTableLock(mtTbl);
0049
  val = WtTableGet(WtMtTableStorage(mtTbl), key);
0050
  Tcl_IncrRefCount(val);
0051
  WtMtTableUnlock(mtTbl);
0052
  return val;
0053
}
0054
0055
/* Set a table entry */
0056
0057
void WtMtTableSet(Tcl_Obj *mtTbl, Tcl_Obj *key, Tcl_Obj *val)
0058
{
0059
  key = Tcl_DuplicateObj(key);
0060
  Tcl_IncrRefCount(key);
0061
0062
  val = Tcl_DuplicateObj(val);
0063
  Tcl_IncrRefCount(val);
0064
0065
  WtMtTableLock(mtTbl);
0066
  WtTableSet(WtMtTableStorage(mtTbl), key, val);
0067
  WtMtTableUnlock(mtTbl);
0068
0069
  Tcl_DecrRefCount(key);
0070
  Tcl_DecrRefCount(val);
0071
}
0072
0073
/* Remove an entry */
0074
0075
void WtMtTableRemove(Tcl_Obj *mtTbl, Tcl_Obj *key)
0076
{
0077
  WtMtTableLock(mtTbl);
0078
  WtTableRemove(WtMtTableStorage(mtTbl), key);
0079
  WtMtTableUnlock(mtTbl);
0080
}
0081
0082
/* Remove a list */
0083
0084
int WtMtTableRemoveList(Tcl_Obj *mtTbl, Tcl_Obj *list,
0085
    Tcl_Interp *interp)
0086
{
0087
  int ret;
0088
  WtMtTableLock(mtTbl);
0089
  ret = WtTableRemoveList(WtMtTableStorage(mtTbl), list, interp);
0090
  WtMtTableUnlock(mtTbl);
0091
  return ret;
0092
}
0093
0094
/* Get keys */
0095
0096
int WtMtTableKeys(Tcl_Obj *mtTbl, Tcl_Obj **keys, Tcl_Interp *interp)
0097
{
0098
  int ret;
0099
  WtMtTableLock(mtTbl);
0100
  ret = WtTableKeys(WtMtTableStorage(mtTbl), keys, interp);
0101
  WtMtTableUnlock(mtTbl);
0102
  return ret;
0103
}
0104
0105
/* Get values */
0106
0107
int WtMtTableValues(Tcl_Obj *mtTbl, Tcl_Obj **vals, Tcl_Interp *interp)
0108
{
0109
  int ret;
0110
  WtMtTableLock(mtTbl);
0111
  ret = WtTableKeys(WtMtTableStorage(mtTbl), vals, interp);
0112
  WtMtTableUnlock(mtTbl);
0113
  return ret;
0114
}
0115
0116
/* Update table */
0117
0118
int WtMtUpdateTable(Tcl_Obj *dest, Tcl_Obj *src)
0119
{
0120
  int ret;
0121
0122
  WtMtTableLock(dest);
0123
  if (dest != src) {
0124
    WtMtTableLock(src);
0125
  }
0126
0127
  ret = WtUpdateTable(WtMtTableStorage(dest),
0128
    WtMtTableStorage(src));
0129
0130
  WtMtTableUnlock(dest);
0131
  if (dest != src) {
0132
    WtMtTableUnlock(src);
0133
  }
0134
0135
  return ret;
0136
}
0137
0138
void WtMtTableClear(Tcl_Obj *mtTbl)
0139
{
0140
  WtMtTableLock(mtTbl);
0141
  WtClearTable(WtMtTableStorage(mtTbl));
0142
  WtMtTableUnlock(mtTbl);
0143
}
0144
0145
void WtMtTableLock(Tcl_Obj *mtTbl)
0146
{
0147
  Tcl_MutexLock(&WtMtTableRep(mtTbl)->lock);
0148
}
0149
0150
void WtMtTableUnlock(Tcl_Obj *mtTbl)
0151
{
0152
  Tcl_MutexUnlock(&WtMtTableRep(mtTbl)->lock);
0153
}
0154
0155
WtMtTable *WtMtTableRep(Tcl_Obj *mtTbl)
0156
{
0157
  return (WtMtTable *)(mtTbl->internalRep.twoPtrValue.ptr1);
0158
}
0159
0160
Tcl_Obj *WtMtTableStorage(Tcl_Obj *mtTbl)
0161
{
0162
  return WtMtTableRep(mtTbl)->tbl;
0163
}
0164
0165
/* Table object */
0166
0167
Tcl_Obj *WtNewMtTableObj()
0168
{
0169
  Tcl_Obj *obj = Tcl_NewObj();
0170
  WtMtTable *mt = (WtMtTable *)ckalloc(sizeof(WtMtTable));
0171
  mt->tbl = WtNewTableObj();
0172
  Tcl_IncrRefCount(mt->tbl);
0173
  mt->lock = NULL;
0174
  obj->internalRep.twoPtrValue.ptr1 = mt;
0175
  obj->internalRep.twoPtrValue.ptr2 = NULL;
0176
  Tcl_InvalidateStringRep(obj);
0177
  return obj;
0178
}
0179
0180
struct Tcl_ObjType WtMtTableType =
0181
{
0182
  "mtTable",
0183
  WtFreeMtTable,
0184
  WtDupMtTable,
0185
  WtUpdateMtTableString,
0186
  WtSetMtTableFromAny
0187
};
0188
0189
void WtFreeMtTable(Tcl_Obj *mtTbl)
0190
{
0191
  WtMtTable *mt = WtMtTableRep(mtTbl);
0192
  Tcl_MutexLock(&mt->lock);
0193
  if (mt->tbl) {
0194
    Tcl_DecrRefCount(mt->tbl);
0195
  }
0196
  Tcl_MutexUnlock(&mt->lock);
0197
  Tcl_MutexFinalize(&mt->lock);
0198
  ckfree((char *)mt);
0199
}
0200
0201
void WtDupMtTable(Tcl_Obj *src, Tcl_Obj *dest)
0202
{
0203
  WtMtTable *srcMt, *destMt;
0204
0205
  destMt = (WtMtTable *)ckalloc(sizeof(WtMtTable));
0206
0207
  WtMtTableLock(src);
0208
  srcMt = WtMtTableRep(src);
0209
  destMt->tbl = Tcl_DuplicateObj(srcMt->tbl);
0210
  WtMtTableUnlock(src);
0211
  Tcl_IncrRefCount(destMt->tbl);
0212
0213
  destMt->lock = NULL;
0214
  dest->internalRep.twoPtrValue.ptr1 = destMt;
0215
  dest->internalRep.twoPtrValue.ptr2 = NULL;
0216
  dest->typePtr = src->typePtr;
0217
  Tcl_InvalidateStringRep(dest);
0218
}
0219
0220
void WtUpdateMtTableString(Tcl_Obj *mtTbl)
0221
{
0222
  WtMtTable *mt;
0223
  const char *bytes;
0224
  int len;
0225
0226
  WtMtTableLock(mtTbl);
0227
  mt = WtMtTableRep(mtTbl);
0228
  bytes = Tcl_GetStringFromObj(mt->tbl, &len);
0229
0230
  if (bytes) {
0231
    mtTbl->bytes = Tcl_Alloc(len + 1);
0232
    memcpy(mtTbl->bytes, bytes, len + 1);
0233
    mtTbl->length = len;
0234
  } else {
0235
    mtTbl->bytes = NULL;
0236
    mtTbl->length = 0;
0237
  }
0238
0239
  WtMtTableUnlock(mtTbl);
0240
}
0241
0242
int WtSetMtTableFromAny(Tcl_Interp *interp, Tcl_Obj *obj)
0243
{
0244
  int ret = TCL_OK;
0245
  Tcl_Obj *tbl;
0246
  WtMtTable *destMt;
0247
0248
  if (obj->typePtr != &WtMtTableType) {
0249
    tbl = Tcl_DuplicateObj(obj);
0250
    if (Tcl_ConvertToType(interp, tbl, &WtTableType) != TCL_OK) {
0251
      ret = TCL_ERROR;
0252
    } else {
0253
      if (obj->typePtr && obj->typePtr->freeIntRepProc) {
0254
        obj->typePtr->freeIntRepProc(obj);
0255
      }
0256
      destMt = (WtMtTable *)ckalloc(sizeof(WtMtTable));
0257
      destMt->tbl = tbl;
0258
      Tcl_IncrRefCount(destMt->tbl);
0259
      destMt->lock = NULL;
0260
      obj->internalRep.twoPtrValue.ptr1 = destMt;
0261
      obj->internalRep.twoPtrValue.ptr2 = NULL;
0262
      obj->typePtr = &WtMtTableType;
0263
      Tcl_InvalidateStringRep(obj);
0264
    }
0265
  }
0266
0267
  return ret;
0268
}