3 source/macro.c | 19 ++++++++++++++++---
6 source/window.c | 6 ++++++
7 4 files changed, 24 insertions(+), 4 deletions(-)
9 diff --quilt old/source/macro.c new/source/macro.c
10 --- old/source/macro.c
11 +++ new/source/macro.c
12 @@ -1279,12 +1279,14 @@ static void finishMacroCmdExecution(Wind
17 for (win=WindowList; win!=NULL; win=win->next)
18 - if (win->macroCmdData != NULL || InSmartIndentMacros(win))
20 + if (win->macroCmdData != NULL
21 + || InSmartIndentMacros(win)
22 + || win->inMacroHook)
24 GarbageCollectStrings();
28 ** Executes macro string "macro" using the lastFocus pane in "window".
29 @@ -6045,11 +6047,11 @@ static int readStringArg(DataValue dv, c
30 *errMsg = "%s called with unknown object";
35 -void MacroApplyHook(const WindowInfo* document, const char* hook, int argc,
36 +void MacroApplyHook(WindowInfo* document, const char* hook, int argc,
37 DataValue* argv, DataValue* resultDV)
41 hookSymbol = LookupSymbol(hook);
42 @@ -6059,10 +6061,12 @@ void MacroApplyHook(const WindowInfo* do
43 DataValue dummyResultDV; /* Passed to ExecuteMacro() if no result requested */
46 // char statusT[1024];
48 + document->inMacroHook++;
51 status = ExecuteMacro((WindowInfo*) document, hookProg, argc, argv,
52 (NULL == resultDV) ? &dummyResultDV : resultDV, &restartData,
55 @@ -6077,10 +6081,19 @@ void MacroApplyHook(const WindowInfo* do
56 while (MACRO_TIME_LIMIT == status) {
57 status = ContinueMacro(restartData,
58 (NULL == resultDV) ? &dummyResultDV : resultDV, &errMsg);
61 + document->inMacroHook--;
62 + /* call the GC only if the caller of this function is not interested
63 + ** in any result, else it may happen, that strings and arrays are swept
66 + if (NULL == resultDV) {
70 if (MACRO_PREEMPT == status || MACRO_ERROR == status) {
71 fprintf(stderr, "nedit: \"%s\" error: %s\n", hook, (MACRO_ERROR == status) ? errMsg : "No dialogs");
73 /* Macro is done here */
75 diff --quilt old/source/nedit.h new/source/nedit.h
76 --- old/source/nedit.h
77 +++ new/source/nedit.h
78 @@ -567,10 +567,11 @@ typedef struct _WindowInfo {
79 UserMenuCache *userMenuCache; /* cache user menus: */
80 UserBGMenuCache userBGMenuCache; /* shell & macro menu are shared over all
81 "tabbed" documents, while each document
82 has its own background menu. */
84 + int inMacroHook; /* to protect GC in MacroApplyHook() */
87 extern WindowInfo *WindowList;
88 extern Display *TheDisplay;
89 extern Widget TheAppShell;
90 diff --quilt old/source/window.c new/source/window.c
91 --- old/source/window.c
92 +++ new/source/window.c
93 @@ -265,10 +265,11 @@ WindowInfo *CreateWindow(const char *nam
94 window->autoSaveOpCount = 0;
95 window->undoOpCount = 0;
96 window->undoMemUsed = 0;
97 CLEAR_ALL_LOCKS(window->lockReasons);
98 window->transient = False;
99 + window->inMacroHook = 0;
100 window->indentStyle = GetPrefAutoIndent(PLAIN_LANGUAGE_MODE);
101 window->autoSave = GetPrefAutoSave();
102 window->saveOldVersion = GetPrefSaveOldVersion();
103 window->wrapMode = GetPrefWrap(PLAIN_LANGUAGE_MODE);
104 window->showWrapMargin = GetPrefShowWrapMargin();
105 @@ -1011,10 +1012,14 @@ void CloseWindow(WindowInfo *window)
106 RefreshTabState(window);
107 updateLineNumDisp(window);
111 + if (window->inMacroHook) {
112 + fprintf(stderr, "NEdit: warning closing window while in MacroHook\n");
115 /* Free syntax highlighting patterns, if any. w/o redisplaying */
116 FreeHighlightingData(window);
118 /* remove the buffer modification callbacks so the buffer will be
119 deallocated when the last text widget is destroyed */
120 @@ -3371,10 +3376,11 @@ WindowInfo* CreateDocument(WindowInfo* s
121 window->autoSaveOpCount = 0;
122 window->undoOpCount = 0;
123 window->undoMemUsed = 0;
124 CLEAR_ALL_LOCKS(window->lockReasons);
125 window->transient = False;
126 + window->inMacroHook = 0;
127 window->indentStyle = GetPrefAutoIndent(PLAIN_LANGUAGE_MODE);
128 window->autoSave = GetPrefAutoSave();
129 window->saveOldVersion = GetPrefSaveOldVersion();
130 window->wrapMode = GetPrefWrap(PLAIN_LANGUAGE_MODE);
131 window->showWrapMargin = GetPrefShowWrapMargin();
132 diff --quilt old/source/macro.h new/source/macro.h
133 --- old/source/macro.h
134 +++ new/source/macro.h
135 @@ -72,9 +72,9 @@ int CheckMacroString(Widget dialogParent
137 char *GetReplayMacro(void);
138 void ReadMacroInitFile(WindowInfo *window);
139 void ReturnShellCommandOutput(WindowInfo *window, const char *outText, int status);
141 -void MacroApplyHook(const WindowInfo* document, const char *hook, int argc,
142 +void MacroApplyHook(WindowInfo* document, const char *hook, int argc,
143 struct DataValueTag* argv, struct DataValueTag* resultDV);
145 #endif /* NEDIT_MACRO_H_INCLUDED */