Check-in [a697a2954e]
Overview
SHA1:a697a2954e480f8001f8707fee99116ce87bd187
Date: 2010-10-18 17:56:31
User: rkeene
Comment:Merged proper fix for mkClose() segfaulting in from P. Thoyts
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2010-10-21
13:00
[9ff996f870] KitCreator 0.5.3

Removed version control tag from release version (user: rkeene, tags: trunk, 0.5.3)

2010-10-18
17:56
[a697a2954e] Merged proper fix for mkClose() segfaulting in from P. Thoyts (user: rkeene, tags: trunk)
2010-10-17
17:27
[626ffe0122] Added link to home page from build page (user: rkeene, tags: trunk)
Changes

Modified mk4tcl/patches/all/metakit-2.4.9.7-fixeventchannels-1pt.diff from [8e303e1d43] to [95a5c09a03].

1
2
3
4
5
6
7
8
9

10
11
12






13
14
15
16
17
18
19
20
..
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
..
69
70
71
72
73
74
75
76

77
78


79


80
81
82
83
84
85
86

87

88

89
90
91
92

93
94
95
96
97
98
99
100
101
102










103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120
121
122

123
124
125
126
127
128








129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
diff -uNr metakit-2.4.9.7.orig/tcl/mk4tcl.cpp metakit-2.4.9.7-1ptrsk/tcl/mk4tcl.cpp
--- metakit-2.4.9.7.orig/tcl/mk4tcl.cpp	2007-06-18 16:05:24.000000000 -0500
+++ metakit-2.4.9.7-1ptrsk/tcl/mk4tcl.cpp	2010-10-16 16:21:41.000000000 -0500
@@ -182,6 +182,8 @@
     Tcl_Channel _chan;
     int _validMask;
     int _watchMask;
+    int _flags;
+    SiasStrategy *_next;

     Tcl_Interp *_interp;
 
     SiasStrategy(c4_Storage &storage_, const c4_View &view_, const c4_BytesProp






@@ -259,23 +261,58 @@
 ///////////////////////////////////////////////////////////////////////////////
 // New in 1.2: channel interface to memo fields
 
-typedef SiasStrategy MkChannel;
-
 typedef struct {
   Tcl_Event header;
................................................................................
 
+static void SetupProc(ClientData clientData, int flags) {
+  MkWorkspace *ws = (MkWorkspace *)clientData;
+  int msec = 10000;
+  Tcl_Time blockTime = {0, 0};
+  if (!(flags & TCL_FILE_EVENTS))
+    return;
+  for (MkChannel *chan = ws->_chanList; chan != NULL; chan = chan->_next) {
+    msec = 10;
+  }
+  blockTime.sec = msec / 1000;
+  blockTime.usec = (msec % 1000) * 1000;
+  Tcl_SetMaxBlockTime(&blockTime);
+}
+
+static void CheckProc(ClientData clientData, int flags) {
+  MkWorkspace *ws = (MkWorkspace *)clientData;
................................................................................
+    }
+  }
+}
+
 static int mkEventFilter(Tcl_Event *evPtr, ClientData instanceData) {
   MkEvent *me = (MkEvent*)evPtr;
   MkChannel *chan = (MkChannel*)instanceData;
@@ -285,6 +322,16 @@

 static int mkClose(ClientData instanceData, Tcl_Interp *interp) {
   MkChannel *chan = (MkChannel*)instanceData;


 


+  /* remove this channel from the package list */
+  if (interp) {
+    MkWorkspace *ws = (MkWorkspace*)Tcl_GetAssocData(interp, "mk4tcl", 0);
+    MkChannel **tmpPtrPtr = &ws->_chanList;
+    while (*tmpPtrPtr && *tmpPtrPtr != chan) {
+      tmpPtrPtr = &(*tmpPtrPtr)->_next;
+    }

+    *tmpPtrPtr = chan->_next;

+  }

+  
   Tcl_DeleteEvents(mkEventFilter, (ClientData)chan);
   chan->_chan = 0;
   delete chan;

@@ -726,7 +773,7 @@
   ++generation; // make sure all cached paths refresh on next access
 }
 
-MkWorkspace::MkWorkspace(Tcl_Interp *ip_): _interp(ip_) {
+MkWorkspace::MkWorkspace(Tcl_Interp *ip_): _interp(ip_), _chanList(NULL) {
   new Item("", "", 0, _items, 0);
 
   // never uses entry zero (so atoi failure in ForgetPath is harmless)
@@ -741,6 +788,7 @@










     delete Nth(i);
 
   // need this to prevent recursion in Tcl_DeleteAssocData in 8.2 (not 8.0!)
+  Tcl_DeleteEventSource(SetupProc, CheckProc, this);
   Tcl_SetAssocData(_interp, "mk4tcl", 0, 0);
   Tcl_DeleteAssocData(_interp, "mk4tcl");
 }
@@ -2371,6 +2419,7 @@
 
   mkChan->_watchMask = 0;
   mkChan->_validMask = mode;
+  mkChan->_flags = 0;
   mkChan->_interp = interp;
   mkChan->_chan = Tcl_CreateChannel(&mkChannelType, buffer, (ClientData)mkChan,
     mode);
@@ -2380,6 +2429,10 @@
 

   Tcl_RegisterChannel(interp, mkChan->_chan);
 
+  /* insert this channel at the front of the workspace channels list */

+  mkChan->_next = work._chanList;
+  work._chanList = mkChan;
+
   if (_error)
     return _error;
 








@@ -2603,6 +2656,7 @@
     // since that does not seem to trigger exitproc handling (!)
     Tcl_SetAssocData(interp, "mk4tcl", DelProc, ws);
     Tcl_CreateExitHandler(ExitProc, ws);
+    Tcl_CreateEventSource(SetupProc, CheckProc, ws);
   }
 
   // this list must match the "CmdDef defTab []" above.
@@ -2648,3 +2702,11 @@
 }
 
 ///////////////////////////////////////////////////////////////////////////////
+
+/*
+ * Local variables:
+ * mode: c
+ * c-basic-offset: 2
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -uNr metakit-2.4.9.7.orig/tcl/mk4tcl.h metakit-2.4.9.7-1ptrsk/tcl/mk4tcl.h
--- metakit-2.4.9.7.orig/tcl/mk4tcl.h	2007-06-15 18:26:40.000000000 -0500
+++ metakit-2.4.9.7-1ptrsk/tcl/mk4tcl.h	2010-10-16 16:19:00.000000000 -0500
@@ -205,6 +205,9 @@
 ///////////////////////////////////////////////////////////////////////////////
 // A workspace manages a number of storage objects and their associated paths.
 
+class SiasStrategy;
+typedef SiasStrategy MkChannel;
+


|
|





>



>
>
>
>
>
>
|







 







|

<







 







|
>


>
>

>
>

<
<
<
|
|
|
>
|
>
|
>
|
<


>
|




|



|
>
>
>
>
>
>
>
>
>
>







|







|
<
>
|


>



|
|
|
>
>
>
>
>
>
>
>
|







|













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91



92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
diff -uNr metakit-2.4.9.7.orig/tcl/mk4tcl.cpp metakit-2.4.9.7-1ptrsk/tcl/mk4tcl.cpp
--- metakit-2.4.9.7.orig/tcl/mk4tcl.cpp	2007-06-18 16:05:24.000000000 -0500
+++ metakit-2.4.9.7-1ptrsk/tcl/mk4tcl.cpp	2010-10-18 09:09:28.000000000 -0500
@@ -182,11 +182,14 @@
     Tcl_Channel _chan;
     int _validMask;
     int _watchMask;
+    int _flags;
+    SiasStrategy *_next;
+    MkWorkspace *_workspace;
     Tcl_Interp *_interp;
 
     SiasStrategy(c4_Storage &storage_, const c4_View &view_, const c4_BytesProp
       &memo_, int row_): _storage(storage_), _view(view_), _memo(memo_), _row
-      (row_), _position(0), _interp(0) {
+      (row_), _position(0), _interp(0), _next(0), _workspace(0) {
         // set up mapping if the memo itself is mapped in its entirety
         c4_Strategy &strat = storage_.Strategy();
         if (strat._mapStart != 0) {
@@ -259,23 +262,57 @@
 ///////////////////////////////////////////////////////////////////////////////
 // New in 1.2: channel interface to memo fields
 
-typedef SiasStrategy MkChannel;
-
 typedef struct {
   Tcl_Event header;
................................................................................
 
+static void SetupProc(ClientData clientData, int flags) {
+  MkWorkspace *ws = (MkWorkspace *)clientData;
+  int msec = 10000;
+  Tcl_Time blockTime = {0, 0};
+  if (!(flags & TCL_FILE_EVENTS))
+    return;
+  if (ws->_chanList != 0)
+    msec = 10;

+  blockTime.sec = msec / 1000;
+  blockTime.usec = (msec % 1000) * 1000;
+  Tcl_SetMaxBlockTime(&blockTime);
+}
+
+static void CheckProc(ClientData clientData, int flags) {
+  MkWorkspace *ws = (MkWorkspace *)clientData;
................................................................................
+    }
+  }
+}
+
 static int mkEventFilter(Tcl_Event *evPtr, ClientData instanceData) {
   MkEvent *me = (MkEvent*)evPtr;
   MkChannel *chan = (MkChannel*)instanceData;
@@ -284,8 +321,21 @@
 
 static int mkClose(ClientData instanceData, Tcl_Interp *interp) {
   MkChannel *chan = (MkChannel*)instanceData;
+  MkWorkspace *ws = chan->_workspace;
+  MkChannel **tmpPtrPtr = &ws->_chanList;
 
   Tcl_DeleteEvents(mkEventFilter, (ClientData)chan);
+
+  /* remove this channel from the package list */



+  while (*tmpPtrPtr && (*tmpPtrPtr != chan)) {
+    tmpPtrPtr = &(*tmpPtrPtr)->_next;
+  }
+  if (*tmpPtrPtr == chan) {
+      *tmpPtrPtr = chan->_next;
+      chan->_next = 0;
+  } else {
+      d4_assert(false);
+  }

   chan->_chan = 0;
   delete chan;
 
@@ -726,21 +776,24 @@
   ++generation; // make sure all cached paths refresh on next access
 }
 
-MkWorkspace::MkWorkspace(Tcl_Interp *ip_): _interp(ip_) {
+MkWorkspace::MkWorkspace(Tcl_Interp *ip_): _interp(ip_), _chanList(0) {
   new Item("", "", 0, _items, 0);
 
   // never uses entry zero (so atoi failure in ForgetPath is harmless)
   _usedRows = _usedBuffer.SetBufferClear(16); 
-    // no realloc for first 16 temp rows
+  // no realloc for first 16 temp rows
 }
 
 MkWorkspace::~MkWorkspace() {
   CleanupCommands();
 
+  d4_assert(_chanList == 0);
+
   for (int i = _items.GetSize(); --i >= 0;)
     delete Nth(i);
 
   // need this to prevent recursion in Tcl_DeleteAssocData in 8.2 (not 8.0!)
+  Tcl_DeleteEventSource(SetupProc, CheckProc, this);
   Tcl_SetAssocData(_interp, "mk4tcl", 0, 0);
   Tcl_DeleteAssocData(_interp, "mk4tcl");
 }
@@ -2371,6 +2424,7 @@
 
   mkChan->_watchMask = 0;
   mkChan->_validMask = mode;
+  mkChan->_flags = 0;
   mkChan->_interp = interp;
   mkChan->_chan = Tcl_CreateChannel(&mkChannelType, buffer, (ClientData)mkChan,
     mode);
@@ -2383,6 +2437,11 @@

   if (_error)
     return _error;
 
+  /* insert this channel at the front of the workspace channels list */
+  mkChan->_workspace = &work;
+  mkChan->_next = work._chanList;
+  work._chanList = mkChan;
+
   KeepRef o = tcl_NewStringObj(buffer);
   return tcl_SetObjResult(o);
 }
@@ -2579,6 +2638,7 @@
 }
 
 static void ExitProc(ClientData cd_) {
+  Tcl_DeleteEventSource(SetupProc, CheckProc, cd_);
   delete (MkWorkspace*)cd_;
 }
 
@@ -2603,6 +2663,7 @@
     // since that does not seem to trigger exitproc handling (!)
     Tcl_SetAssocData(interp, "mk4tcl", DelProc, ws);
     Tcl_CreateExitHandler(ExitProc, ws);
+    Tcl_CreateEventSource(SetupProc, CheckProc, ws);
   }
 
   // this list must match the "CmdDef defTab []" above.
@@ -2648,3 +2709,11 @@
 }
 
 ///////////////////////////////////////////////////////////////////////////////
+
+/*
+ * Local variables:
+ * mode: c
+ * c-basic-offset: 2
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -uNr metakit-2.4.9.7.orig/tcl/mk4tcl.h metakit-2.4.9.7-1ptrsk/tcl/mk4tcl.h
--- metakit-2.4.9.7.orig/tcl/mk4tcl.h	2007-06-15 18:26:40.000000000 -0500
+++ metakit-2.4.9.7-1ptrsk/tcl/mk4tcl.h	2010-10-18 09:09:00.000000000 -0500
@@ -205,6 +205,9 @@
 ///////////////////////////////////////////////////////////////////////////////
 // A workspace manages a number of storage objects and their associated paths.
 
+class SiasStrategy;
+typedef SiasStrategy MkChannel;
+