File: | Display.c |
Location: | line 460, column 14 |
Description: | Access to field 'exit_flag' results in a dereference of a null pointer (loaded from variable 'app') |
1 | /*********************************************************** |
2 | Copyright (c) 1993, Oracle and/or its affiliates. All rights reserved. |
3 | |
4 | Permission is hereby granted, free of charge, to any person obtaining a |
5 | copy of this software and associated documentation files (the "Software"), |
6 | to deal in the Software without restriction, including without limitation |
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
8 | and/or sell copies of the Software, and to permit persons to whom the |
9 | Software is furnished to do so, subject to the following conditions: |
10 | |
11 | The above copyright notice and this permission notice (including the next |
12 | paragraph) shall be included in all copies or substantial portions of the |
13 | Software. |
14 | |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
21 | DEALINGS IN THE SOFTWARE. |
22 | |
23 | Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. |
24 | |
25 | All Rights Reserved |
26 | |
27 | Permission to use, copy, modify, and distribute this software and its |
28 | documentation for any purpose and without fee is hereby granted, |
29 | provided that the above copyright notice appear in all copies and that |
30 | both that copyright notice and this permission notice appear in |
31 | supporting documentation, and that the name of Digital not be |
32 | used in advertising or publicity pertaining to distribution of the |
33 | software without specific, written prior permission. |
34 | |
35 | DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING |
36 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL |
37 | DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR |
38 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
39 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
40 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
41 | SOFTWARE. |
42 | |
43 | ******************************************************************/ |
44 | |
45 | /* |
46 | |
47 | Copyright 1987, 1988, 1998 The Open Group |
48 | |
49 | Permission to use, copy, modify, distribute, and sell this software and its |
50 | documentation for any purpose is hereby granted without fee, provided that |
51 | the above copyright notice appear in all copies and that both that |
52 | copyright notice and this permission notice appear in supporting |
53 | documentation. |
54 | |
55 | The above copyright notice and this permission notice shall be included in |
56 | all copies or substantial portions of the Software. |
57 | |
58 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
59 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
60 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
61 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
62 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
63 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
64 | |
65 | Except as contained in this notice, the name of The Open Group shall not be |
66 | used in advertising or otherwise to promote the sale, use or other dealings |
67 | in this Software without prior written authorization from The Open Group. |
68 | |
69 | */ |
70 | |
71 | #ifdef HAVE_CONFIG_H1 |
72 | #include <config.h> |
73 | #endif |
74 | #include "IntrinsicI.h" |
75 | #ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT |
76 | #include "ResConfigP.h" |
77 | #endif |
78 | |
79 | #include <stdlib.h> |
80 | |
81 | #ifdef XTHREADS1 |
82 | void (*_XtProcessLock)(void) = NULL((void*)0); |
83 | void (*_XtProcessUnlock)(void) = NULL((void*)0); |
84 | void (*_XtInitAppLock)(XtAppContext) = NULL((void*)0); |
85 | #endif |
86 | |
87 | static String XtNnoPerDisplay = "noPerDisplay"; |
88 | |
89 | ProcessContext _XtGetProcessContext(void) |
90 | { |
91 | static ProcessContextRec processContextRec = { |
92 | (XtAppContext)NULL((void*)0), |
93 | (XtAppContext)NULL((void*)0), |
94 | (ConverterTable)NULL((void*)0), |
95 | {(XtLanguageProc)NULL((void*)0), (XtPointer)NULL((void*)0)} |
96 | }; |
97 | |
98 | return &processContextRec; |
99 | } |
100 | |
101 | |
102 | XtAppContext _XtDefaultAppContext(void) |
103 | { |
104 | ProcessContext process = _XtGetProcessContext(); |
105 | XtAppContext app; |
106 | |
107 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
108 | if (process->defaultAppContext == NULL((void*)0)) { |
109 | process->defaultAppContext = XtCreateApplicationContext(); |
110 | } |
111 | app = process->defaultAppContext; |
112 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
113 | return app; |
114 | } |
115 | |
116 | static void AddToAppContext( |
117 | Display *d, |
118 | XtAppContext app) |
119 | { |
120 | #define DISPLAYS_TO_ADD 4 |
121 | |
122 | if (app->count >= app->max) { |
123 | app->max += DISPLAYS_TO_ADD; |
124 | app->list = (Display **) XtRealloc((char *)app->list, |
125 | (unsigned) app->max * sizeof(Display *)); |
126 | } |
127 | |
128 | app->list[app->count++] = d; |
129 | app->rebuild_fdlist = TRUE1; |
130 | #ifndef USE_POLL1 |
131 | if (ConnectionNumber(d)(((_XPrivDisplay)d)->fd) + 1 > app->fds.nfds) { |
132 | app->fds.nfds = ConnectionNumber(d)(((_XPrivDisplay)d)->fd) + 1; |
133 | } |
134 | #else |
135 | app->fds.nfds++; |
136 | #endif |
137 | #undef DISPLAYS_TO_ADD |
138 | } |
139 | |
140 | static void XtDeleteFromAppContext( |
141 | Display *d, |
142 | register XtAppContext app) |
143 | { |
144 | register int i; |
145 | |
146 | for (i = 0; i < app->count; i++) if (app->list[i] == d) break; |
147 | |
148 | if (i < app->count) { |
149 | if (i <= app->last && app->last > 0) app->last--; |
150 | for (i++; i < app->count; i++) app->list[i-1] = app->list[i]; |
151 | app->count--; |
152 | } |
153 | app->rebuild_fdlist = TRUE1; |
154 | #ifndef USE_POLL1 |
155 | if ((ConnectionNumber(d)(((_XPrivDisplay)d)->fd) + 1) == app->fds.nfds) |
156 | app->fds.nfds--; |
157 | else /* Unnecessary, just to be fool-proof */ |
158 | FD_CLR(ConnectionNumber(d), &app->fds.rmask)((void) (((&app->fds.rmask)->__fds_bits)[(((((_XPrivDisplay )d)->fd)) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask ) 1 << (((((_XPrivDisplay)d)->fd)) % (8 * (int) sizeof (__fd_mask)))))); |
159 | #else |
160 | app->fds.nfds--; |
161 | #endif |
162 | } |
163 | |
164 | static XtPerDisplay NewPerDisplay( |
165 | Display *dpy) |
166 | { |
167 | PerDisplayTablePtr pd; |
168 | |
169 | pd = XtNew(PerDisplayTable)((PerDisplayTable *) XtMalloc((unsigned) sizeof(PerDisplayTable ))); |
170 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
171 | pd->dpy = dpy; |
172 | pd->next = _XtperDisplayList; |
173 | _XtperDisplayList = pd; |
174 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
175 | return &(pd->perDpy); |
176 | } |
177 | |
178 | static XtPerDisplay InitPerDisplay( |
179 | Display *dpy, |
180 | XtAppContext app, |
181 | _Xconstconst char * name, |
182 | _Xconstconst char * classname) |
183 | { |
184 | XtPerDisplay pd; |
185 | |
186 | AddToAppContext(dpy, app); |
187 | |
188 | pd = NewPerDisplay(dpy); |
189 | _XtHeapInit(&pd->heap); |
190 | pd->destroy_callbacks = NULL((void*)0); |
191 | pd->region = XCreateRegion(); |
192 | pd->case_cvt = NULL((void*)0); |
193 | pd->defaultKeycodeTranslator = XtTranslateKey; |
194 | pd->keysyms_serial = 0; |
195 | pd->keysyms = NULL((void*)0); |
196 | XDisplayKeycodes(dpy, &pd->min_keycode, &pd->max_keycode); |
197 | pd->modKeysyms = NULL((void*)0); |
198 | pd->modsToKeysyms = NULL((void*)0); |
199 | pd->appContext = app; |
200 | pd->name = XrmStringToName(name)XrmStringToQuark(name); |
201 | pd->class = XrmStringToClass(classname)XrmStringToQuark(classname); |
202 | pd->being_destroyed = False0; |
203 | pd->GClist = NULL((void*)0); |
204 | pd->pixmap_tab = NULL((void*)0); |
205 | pd->language = NULL((void*)0); |
206 | pd->rv = False0; |
207 | pd->last_event.xany.serial = 0; |
208 | pd->last_timestamp = 0; |
209 | _XtAllocTMContext(pd); |
210 | pd->mapping_callbacks = NULL((void*)0); |
211 | |
212 | pd->pdi.grabList = NULL((void*)0); |
213 | pd->pdi.trace = NULL((void*)0); |
214 | pd->pdi.traceDepth = 0; |
215 | pd->pdi.traceMax = 0; |
216 | pd->pdi.focusWidget = NULL((void*)0); |
217 | pd->pdi.activatingKey = 0; |
218 | pd->pdi.keyboard.grabType = XtNoServerGrab; |
219 | pd->pdi.pointer.grabType = XtNoServerGrab; |
220 | _XtAllocWWTable(pd); |
221 | pd->per_screen_db = (XrmDatabase *)__XtCalloc(ScreenCount(dpy)(((_XPrivDisplay)dpy)->nscreens), |
222 | sizeof(XrmDatabase)); |
223 | pd->cmd_db = (XrmDatabase)NULL((void*)0); |
224 | pd->server_db = (XrmDatabase)NULL((void*)0); |
225 | pd->dispatcher_list = NULL((void*)0); |
226 | pd->ext_select_list = NULL((void*)0); |
227 | pd->ext_select_count = 0; |
228 | pd->hook_object = NULL((void*)0); |
229 | #if 0 |
230 | pd->hook_object = _XtCreate("hooks", "Hooks", hookObjectClass, |
231 | (Widget)NULL((void*)0), (Screen*)DefaultScreenOfDisplay(dpy)(&((_XPrivDisplay)dpy)->screens[(((_XPrivDisplay)dpy)-> default_screen)]), |
232 | (ArgList)NULL((void*)0), 0, (XtTypedArgList)NULL((void*)0), 0, |
233 | (ConstraintWidgetClass)NULL((void*)0)); |
234 | #endif |
235 | |
236 | #ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT |
237 | pd->rcm_init = XInternAtom (dpy, RCM_INIT"Custom Init", 0); |
238 | pd->rcm_data = XInternAtom (dpy, RCM_DATA"Custom Data", 0); |
239 | #endif |
240 | |
241 | return pd; |
242 | } |
243 | |
244 | Display *XtOpenDisplay( |
245 | XtAppContext app, |
246 | _Xconstconst char* displayName, |
247 | _Xconstconst char* applName, |
248 | _Xconstconst char* className, |
249 | XrmOptionDescRec *urlist, |
250 | Cardinal num_urs, |
251 | int *argc, |
252 | String *argv) |
253 | { |
254 | Display *d; |
255 | XrmDatabase db = NULL((void*)0); |
256 | XtPerDisplay pd; |
257 | String language = NULL((void*)0); |
258 | |
259 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
260 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
261 | /* parse the command line for name, display, and/or language */ |
262 | db = _XtPreparseCommandLine(urlist, num_urs, *argc, argv, |
263 | (String *)&applName, |
264 | (String *)(displayName ? NULL((void*)0) : &displayName), |
265 | (app->process->globalLangProcRec.proc ? |
266 | &language : NULL((void*)0))); |
267 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
268 | d = XOpenDisplay(displayName); |
269 | |
270 | if (! applName && !(applName = getenv("RESOURCE_NAME"))) { |
271 | if (*argc > 0 && argv[0] && *argv[0]) { |
272 | #ifdef WIN32 |
273 | char *ptr = strrchr(argv[0], '\\'); |
274 | #else |
275 | char *ptr = strrchr(argv[0], '/'); |
276 | #endif |
277 | #ifdef __UNIXOS2__ |
278 | char *dot_ptr,*ptr2; |
279 | ptr2 = strrchr(argv[0],'\\'); |
280 | if (ptr2 > ptr) ptr = ptr2; |
281 | dot_ptr = strrchr(argv[0],'.'); |
282 | if (dot_ptr && (dot_ptr > ptr)) *dot_ptr='\0'; |
283 | #endif /* This will remove the .exe suffix under OS/2 */ |
284 | |
285 | if (ptr) applName = ++ptr; |
286 | else applName = argv[0]; |
287 | } else |
288 | applName = "main"; |
289 | } |
290 | |
291 | if (d) { |
292 | pd = InitPerDisplay(d, app, applName, className); |
293 | pd->language = language; |
294 | _XtDisplayInitialize(d, pd, applName, urlist, num_urs, argc, argv); |
295 | } else { |
296 | int len; |
297 | displayName = XDisplayName(displayName); |
298 | len = strlen (displayName); |
299 | app->display_name_tried = (String) __XtMalloc (len + 1); |
300 | strncpy ((char*) app->display_name_tried, displayName, len + 1); |
301 | app->display_name_tried[len] = '\0'; |
302 | } |
303 | if (db) XrmDestroyDatabase(db); |
304 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
305 | return d; |
306 | } |
307 | |
308 | Display * |
309 | _XtAppInit( |
310 | XtAppContext * app_context_return, |
311 | String application_class, |
312 | XrmOptionDescRec *options, |
313 | Cardinal num_options, |
314 | int *argc_in_out, |
315 | String **argv_in_out, |
316 | String * fallback_resources) |
317 | { |
318 | String *saved_argv; |
319 | int i; |
320 | Display *dpy; |
321 | |
322 | /* |
323 | * Save away argv and argc so we can set the properties later |
324 | */ |
325 | |
326 | saved_argv = (String *) |
327 | __XtMalloc( (Cardinal)((*argc_in_out + 1) * sizeof(String)) ); |
328 | |
329 | for (i = 0 ; i < *argc_in_out ; i++) saved_argv[i] = (*argv_in_out)[i]; |
330 | saved_argv[i] = NULL((void*)0); /* NULL terminate that sucker. */ |
331 | |
332 | |
333 | *app_context_return = XtCreateApplicationContext(); |
334 | |
335 | LOCK_APP((*app_context_return))if((*app_context_return) && (*app_context_return)-> lock)(*(*app_context_return)->lock)((*app_context_return)); |
336 | if (fallback_resources) /* save a procedure call */ |
337 | XtAppSetFallbackResources(*app_context_return, fallback_resources); |
338 | |
339 | dpy = XtOpenDisplay(*app_context_return, (String) NULL((void*)0), NULL((void*)0), |
340 | application_class, |
341 | options, num_options, argc_in_out, *argv_in_out); |
342 | |
343 | if (!dpy) { |
344 | String param = (*app_context_return)->display_name_tried; |
345 | Cardinal param_count = 1; |
346 | XtErrorMsg("invalidDisplay","xtInitialize",XtCXtToolkitError, |
347 | "Can't open display: %s", ¶m, ¶m_count); |
348 | XtFree((char *) (*app_context_return)->display_name_tried); |
349 | } |
350 | *argv_in_out = saved_argv; |
351 | UNLOCK_APP((*app_context_return))if((*app_context_return) && (*app_context_return)-> unlock)(*(*app_context_return)->unlock)((*app_context_return )); |
352 | return dpy; |
353 | } |
354 | |
355 | void |
356 | XtDisplayInitialize( |
357 | XtAppContext app, |
358 | Display *dpy, |
359 | _Xconstconst char* name, |
360 | _Xconstconst char* classname, |
361 | XrmOptionDescRec *urlist, |
362 | Cardinal num_urs, |
363 | int *argc, |
364 | String *argv |
365 | ) |
366 | { |
367 | XtPerDisplay pd; |
368 | XrmDatabase db = NULL((void*)0); |
369 | |
370 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
371 | pd = InitPerDisplay(dpy, app, name, classname); |
372 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
373 | if (app->process->globalLangProcRec.proc) |
374 | /* pre-parse the command line for the language resource */ |
375 | db = _XtPreparseCommandLine(urlist, num_urs, *argc, argv, NULL((void*)0), NULL((void*)0), |
376 | &pd->language); |
377 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
378 | _XtDisplayInitialize(dpy, pd, name, urlist, num_urs, argc, argv); |
379 | if (db) XrmDestroyDatabase(db); |
380 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
381 | } |
382 | |
383 | XtAppContext XtCreateApplicationContext(void) |
384 | { |
385 | XtAppContext app = XtNew(XtAppStruct)((XtAppStruct *) XtMalloc((unsigned) sizeof(XtAppStruct))); |
386 | #ifdef XTHREADS1 |
387 | app->lock_info = NULL((void*)0); |
388 | app->lock = NULL((void*)0); |
389 | app->unlock = NULL((void*)0); |
390 | app->yield_lock = NULL((void*)0); |
391 | app->restore_lock = NULL((void*)0); |
392 | app->free_lock = NULL((void*)0); |
393 | #endif |
394 | INIT_APP_LOCK(app)if(_XtInitAppLock) (*_XtInitAppLock)(app); |
395 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
396 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
397 | app->process = _XtGetProcessContext(); |
398 | app->next = app->process->appContextList; |
399 | app->process->appContextList = app; |
400 | app->langProcRec.proc = app->process->globalLangProcRec.proc; |
401 | app->langProcRec.closure = app->process->globalLangProcRec.closure; |
402 | app->destroy_callbacks = NULL((void*)0); |
403 | app->list = NULL((void*)0); |
404 | app->count = app->max = app->last = 0; |
405 | app->timerQueue = NULL((void*)0); |
406 | app->workQueue = NULL((void*)0); |
407 | app->signalQueue = NULL((void*)0); |
408 | app->input_list = NULL((void*)0); |
409 | app->outstandingQueue = NULL((void*)0); |
410 | app->errorDB = NULL((void*)0); |
411 | _XtSetDefaultErrorHandlers(&app->errorMsgHandler, |
412 | &app->warningMsgHandler, &app->errorHandler, |
413 | &app->warningHandler); |
414 | app->action_table = NULL((void*)0); |
415 | _XtSetDefaultSelectionTimeout(&app->selectionTimeout); |
416 | _XtSetDefaultConverterTable(&app->converterTable); |
417 | app->sync = app->being_destroyed = app->error_inited = FALSE0; |
418 | app->in_phase2_destroy = NULL((void*)0); |
419 | #ifndef USE_POLL1 |
420 | FD_ZERO(&app->fds.rmask)do { unsigned int __i; fd_set *__arr = (&app->fds.rmask ); for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask ); ++__i) ((__arr)->__fds_bits)[__i] = 0; } while (0); |
421 | FD_ZERO(&app->fds.wmask)do { unsigned int __i; fd_set *__arr = (&app->fds.wmask ); for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask ); ++__i) ((__arr)->__fds_bits)[__i] = 0; } while (0); |
422 | FD_ZERO(&app->fds.emask)do { unsigned int __i; fd_set *__arr = (&app->fds.emask ); for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask ); ++__i) ((__arr)->__fds_bits)[__i] = 0; } while (0); |
423 | #endif |
424 | app->fds.nfds = 0; |
425 | app->input_count = app->input_max = 0; |
426 | _XtHeapInit(&app->heap); |
427 | app->fallback_resources = NULL((void*)0); |
428 | _XtPopupInitialize(app); |
429 | app->action_hook_list = NULL((void*)0); |
430 | app->block_hook_list = NULL((void*)0); |
431 | app->destroy_list_size = app->destroy_count = app->dispatch_level = 0; |
432 | app->destroy_list = NULL((void*)0); |
433 | #ifndef NO_IDENTIFY_WINDOWS |
434 | app->identify_windows = False0; |
435 | #endif |
436 | app->free_bindings = NULL((void*)0); |
437 | app->display_name_tried = NULL((void*)0); |
438 | app->dpy_destroy_count = 0; |
439 | app->dpy_destroy_list = NULL((void*)0); |
440 | app->exit_flag = FALSE0; |
441 | app->rebuild_fdlist = TRUE1; |
442 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
443 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
444 | return app; |
445 | } |
446 | |
447 | void XtAppSetExitFlag ( |
448 | XtAppContext app) |
449 | { |
450 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
451 | app->exit_flag = TRUE1; |
452 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
453 | } |
454 | |
455 | Boolean XtAppGetExitFlag ( |
456 | XtAppContext app) |
457 | { |
458 | Boolean retval; |
459 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
460 | retval = app->exit_flag; |
Access to field 'exit_flag' results in a dereference of a null pointer (loaded from variable 'app') | |
461 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
462 | return retval; |
463 | } |
464 | |
465 | static void DestroyAppContext(XtAppContext app) |
466 | { |
467 | XtAppContext* prev_app; |
468 | |
469 | prev_app = &app->process->appContextList; |
470 | while (app->count-- > 0) XtCloseDisplay(app->list[app->count]); |
471 | if (app->list != NULL((void*)0)) XtFree((char *)app->list); |
472 | _XtFreeConverterTable(app->converterTable); |
473 | _XtCacheFlushTag(app, (XtPointer)&app->heap); |
474 | _XtFreeActions(app->action_table); |
475 | if (app->destroy_callbacks != NULL((void*)0)) { |
476 | XtCallCallbackList((Widget) NULL((void*)0), |
477 | (XtCallbackList)app->destroy_callbacks, |
478 | (XtPointer)app); |
479 | _XtRemoveAllCallbacks(&app->destroy_callbacks); |
480 | } |
481 | while (app->timerQueue) XtRemoveTimeOut((XtIntervalId)app->timerQueue); |
482 | while (app->workQueue) XtRemoveWorkProc((XtWorkProcId)app->workQueue); |
483 | while (app->signalQueue) XtRemoveSignal((XtSignalId)app->signalQueue); |
484 | if (app->input_list) _XtRemoveAllInputs(app); |
485 | XtFree((char*)app->destroy_list); |
486 | _XtHeapFree(&app->heap); |
487 | while (*prev_app != app) prev_app = &(*prev_app)->next; |
488 | *prev_app = app->next; |
489 | if (app->process->defaultAppContext == app) |
490 | app->process->defaultAppContext = NULL((void*)0); |
491 | if (app->free_bindings) _XtDoFreeBindings (app); |
492 | FREE_APP_LOCK(app)if(app && app->free_lock)(*app->free_lock)(app); |
493 | XtFree((char *)app); |
494 | } |
495 | |
496 | static XtAppContext* appDestroyList = NULL((void*)0); |
497 | int _XtAppDestroyCount = 0; |
498 | |
499 | void XtDestroyApplicationContext(XtAppContext app) |
500 | { |
501 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
502 | if (app->being_destroyed) { |
503 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
504 | return; |
505 | } |
506 | |
507 | if (_XtSafeToDestroy(app)((app)->dispatch_level == 0)) { |
508 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
509 | DestroyAppContext(app); |
510 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
511 | } else { |
512 | app->being_destroyed = TRUE1; |
513 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
514 | _XtAppDestroyCount++; |
515 | appDestroyList = |
516 | (XtAppContext *) XtRealloc((char *) appDestroyList, |
517 | (unsigned) (_XtAppDestroyCount * sizeof(XtAppContext))); |
518 | appDestroyList[_XtAppDestroyCount-1] = app; |
519 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
520 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
521 | } |
522 | } |
523 | |
524 | void _XtDestroyAppContexts(void) |
525 | { |
526 | int i,ii; |
527 | XtAppContext apps[8]; |
528 | XtAppContext* pApps; |
529 | |
530 | pApps = XtStackAlloc (sizeof (XtAppContext) * _XtAppDestroyCount, apps)((sizeof (XtAppContext) * _XtAppDestroyCount) <= sizeof(apps ) ? (XtPointer)(apps) : XtMalloc((unsigned)(sizeof (XtAppContext ) * _XtAppDestroyCount))); |
531 | |
532 | for (i = ii = 0; i < _XtAppDestroyCount; i++) { |
533 | if (_XtSafeToDestroy(appDestroyList[i])((appDestroyList[i])->dispatch_level == 0)) |
534 | DestroyAppContext(appDestroyList[i]); |
535 | else |
536 | pApps[ii++] = appDestroyList[i]; |
537 | } |
538 | _XtAppDestroyCount = ii; |
539 | if (_XtAppDestroyCount == 0) { |
540 | XtFree((char *) appDestroyList); |
541 | appDestroyList = NULL((void*)0); |
542 | } else { |
543 | for (i = 0; i < ii; i++) |
544 | appDestroyList[i] = pApps[i]; |
545 | } |
546 | XtStackFree ((XtPointer) pApps, apps){ if (((XtPointer) pApps) != ((XtPointer)(apps))) XtFree((XtPointer ) pApps); }; |
547 | } |
548 | |
549 | XrmDatabase XtDatabase(Display *dpy) |
550 | { |
551 | XrmDatabase retval; |
552 | DPY_TO_APPCON(dpy)XtAppContext app = (_XtProcessLock ? XtDisplayToApplicationContext (dpy): ((void*)0)); |
553 | |
554 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
555 | retval = XrmGetDatabase(dpy); |
556 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
557 | return retval; |
558 | } |
559 | |
560 | PerDisplayTablePtr _XtperDisplayList = NULL((void*)0); |
561 | |
562 | XtPerDisplay _XtSortPerDisplayList(Display *dpy) |
563 | { |
564 | register PerDisplayTablePtr pd, opd = NULL((void*)0); |
565 | |
566 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
567 | for (pd = _XtperDisplayList; |
568 | pd != NULL((void*)0) && pd->dpy != dpy; |
569 | pd = pd->next) { |
570 | opd = pd; |
571 | } |
572 | |
573 | if (pd == NULL((void*)0)) { |
574 | XtErrorMsg(XtNnoPerDisplay, "getPerDisplay", XtCXtToolkitError, |
575 | "Couldn't find per display information", |
576 | (String *) NULL((void*)0), (Cardinal *)NULL((void*)0)); |
577 | } |
578 | |
579 | if (pd != _XtperDisplayList) { /* move it to the front */ |
580 | /* opd points to the previous one... */ |
581 | |
582 | opd->next = pd->next; |
583 | pd->next = _XtperDisplayList; |
584 | _XtperDisplayList = pd; |
585 | } |
586 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
587 | return &(pd->perDpy); |
588 | } |
589 | |
590 | XtAppContext XtDisplayToApplicationContext(Display *dpy) |
591 | { |
592 | XtAppContext retval; |
593 | |
594 | retval = _XtGetPerDisplay(dpy)->appContext; |
595 | return retval; |
596 | } |
597 | |
598 | static void CloseDisplay(Display *dpy) |
599 | { |
600 | register XtPerDisplay xtpd; |
601 | register PerDisplayTablePtr pd, opd = NULL((void*)0); |
602 | XrmDatabase db; |
603 | int i; |
604 | |
605 | XtDestroyWidget(XtHooksOfDisplay(dpy)); |
606 | |
607 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
608 | for (pd = _XtperDisplayList; |
609 | pd != NULL((void*)0) && pd->dpy != dpy; |
610 | pd = pd->next){ |
611 | opd = pd; |
612 | } |
613 | |
614 | if (pd == NULL((void*)0)) { |
615 | XtErrorMsg(XtNnoPerDisplay, "closeDisplay", XtCXtToolkitError, |
616 | "Couldn't find per display information", |
617 | (String *) NULL((void*)0), (Cardinal *)NULL((void*)0)); |
618 | } |
619 | |
620 | if (pd == _XtperDisplayList) _XtperDisplayList = pd->next; |
621 | else opd->next = pd->next; |
622 | |
623 | xtpd = &(pd->perDpy); |
624 | |
625 | if (xtpd != NULL((void*)0)) { |
626 | if (xtpd->destroy_callbacks != NULL((void*)0)) { |
627 | XtCallCallbackList((Widget) NULL((void*)0), |
628 | (XtCallbackList)xtpd->destroy_callbacks, |
629 | (XtPointer)xtpd); |
630 | _XtRemoveAllCallbacks(&xtpd->destroy_callbacks); |
631 | } |
632 | if (xtpd->mapping_callbacks != NULL((void*)0)) |
633 | _XtRemoveAllCallbacks(&xtpd->mapping_callbacks); |
634 | XtDeleteFromAppContext(dpy, xtpd->appContext); |
635 | if (xtpd->keysyms) |
636 | XFree((char *) xtpd->keysyms); |
637 | XtFree((char *) xtpd->modKeysyms); |
638 | XtFree((char *) xtpd->modsToKeysyms); |
639 | xtpd->keysyms_per_keycode = 0; |
640 | xtpd->being_destroyed = FALSE0; |
641 | xtpd->keysyms = NULL((void*)0); |
642 | xtpd->modKeysyms = NULL((void*)0); |
643 | xtpd->modsToKeysyms = NULL((void*)0); |
644 | XDestroyRegion(xtpd->region); |
645 | _XtCacheFlushTag(xtpd->appContext, (XtPointer)&xtpd->heap); |
646 | _XtGClistFree(dpy, xtpd); |
647 | XtFree((char*)xtpd->pdi.trace); |
648 | _XtHeapFree(&xtpd->heap); |
649 | _XtFreeWWTable(xtpd); |
650 | xtpd->per_screen_db[DefaultScreen(dpy)(((_XPrivDisplay)dpy)->default_screen)] = (XrmDatabase)NULL((void*)0); |
651 | for (i = ScreenCount(dpy)(((_XPrivDisplay)dpy)->nscreens); --i >= 0; ) { |
652 | db = xtpd->per_screen_db[i]; |
653 | if (db) |
654 | XrmDestroyDatabase(db); |
655 | } |
656 | XtFree((char *)xtpd->per_screen_db); |
657 | if ((db = XrmGetDatabase(dpy))) |
658 | XrmDestroyDatabase(db); |
659 | if (xtpd->cmd_db) |
660 | XrmDestroyDatabase(xtpd->cmd_db); |
661 | if (xtpd->server_db) |
662 | XrmDestroyDatabase(xtpd->server_db); |
663 | XtFree(xtpd->language); |
664 | if (xtpd->dispatcher_list != NULL((void*)0)) |
665 | XtFree((char *) xtpd->dispatcher_list); |
666 | if (xtpd->ext_select_list != NULL((void*)0)) |
667 | XtFree((char *) xtpd->ext_select_list); |
668 | } |
669 | XtFree((char*)pd); |
670 | XrmSetDatabase(dpy, (XrmDatabase)NULL((void*)0)); |
671 | XCloseDisplay(dpy); |
672 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
673 | } |
674 | |
675 | void XtCloseDisplay(Display *dpy) |
676 | { |
677 | XtPerDisplay pd; |
678 | XtAppContext app = XtDisplayToApplicationContext(dpy); |
679 | |
680 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
681 | pd = _XtGetPerDisplay(dpy); |
682 | if (pd->being_destroyed) { |
683 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
684 | return; |
685 | } |
686 | |
687 | if (_XtSafeToDestroy(app)((app)->dispatch_level == 0)) CloseDisplay(dpy); |
688 | else { |
689 | pd->being_destroyed = TRUE1; |
690 | app->dpy_destroy_count++; |
691 | app->dpy_destroy_list = (Display **) |
692 | XtRealloc((char *) app->dpy_destroy_list, |
693 | (unsigned) (app->dpy_destroy_count * sizeof(Display *))); |
694 | app->dpy_destroy_list[app->dpy_destroy_count-1] = dpy; |
695 | } |
696 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
697 | } |
698 | |
699 | void _XtCloseDisplays(XtAppContext app) |
700 | { |
701 | int i; |
702 | |
703 | LOCK_APP(app)if(app && app->lock)(*app->lock)(app); |
704 | for (i = 0; i < app->dpy_destroy_count; i++) { |
705 | CloseDisplay(app->dpy_destroy_list[i]); |
706 | } |
707 | app->dpy_destroy_count = 0; |
708 | XtFree((char *) app->dpy_destroy_list); |
709 | app->dpy_destroy_list = NULL((void*)0); |
710 | UNLOCK_APP(app)if(app && app->unlock)(*app->unlock)(app); |
711 | } |
712 | |
713 | XtAppContext XtWidgetToApplicationContext(Widget w) |
714 | { |
715 | XtAppContext retval; |
716 | |
717 | retval = _XtGetPerDisplay(XtDisplayOfObject(w)((((Object)(w))->object.widget_class->core_class.class_inited & 0x04) ? (w)->core.screen->display : _XtIsHookObject (w) ? ((HookObject)(w))->hooks.screen->display : _XtWindowedAncestor (w)->core.screen->display))->appContext; |
718 | return retval; |
719 | } |
720 | |
721 | |
722 | void XtGetApplicationNameAndClass( |
723 | Display *dpy, |
724 | String *name_return, |
725 | String *class_return) |
726 | { |
727 | XtPerDisplay pd; |
728 | |
729 | pd = _XtGetPerDisplay(dpy); |
730 | *name_return = XrmQuarkToString(pd->name); |
731 | *class_return = XrmQuarkToString(pd->class); |
732 | } |
733 | |
734 | XtPerDisplay _XtGetPerDisplay (Display* display) |
735 | { |
736 | XtPerDisplay retval; |
737 | |
738 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
739 | retval = ((_XtperDisplayList != NULL((void*)0) && |
740 | _XtperDisplayList->dpy == display) |
741 | ? &_XtperDisplayList->perDpy |
742 | : _XtSortPerDisplayList(display)); |
743 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
744 | return retval; |
745 | } |
746 | |
747 | XtPerDisplayInputRec* _XtGetPerDisplayInput(Display* display) |
748 | { |
749 | XtPerDisplayInputRec* retval; |
750 | LOCK_PROCESSif(_XtProcessLock)(*_XtProcessLock)(); |
751 | retval = ((_XtperDisplayList != NULL((void*)0) && |
752 | _XtperDisplayList->dpy == display) |
753 | ? &_XtperDisplayList->perDpy.pdi |
754 | : &_XtSortPerDisplayList(display)->pdi); |
755 | UNLOCK_PROCESSif(_XtProcessUnlock)(*_XtProcessUnlock)(); |
756 | return retval; |
757 | } |
758 | |
759 | void XtGetDisplays( |
760 | XtAppContext app_context, |
761 | Display*** dpy_return, |
762 | Cardinal* num_dpy_return) |
763 | { |
764 | int ii; |
765 | LOCK_APP(app_context)if(app_context && app_context->lock)(*app_context-> lock)(app_context); |
766 | *num_dpy_return = app_context->count; |
767 | *dpy_return = (Display**)__XtMalloc(app_context->count * sizeof(Display*)); |
768 | for (ii = 0; ii < app_context->count; ii++) |
769 | (*dpy_return)[ii] = app_context->list[ii]; |
770 | UNLOCK_APP(app_context)if(app_context && app_context->unlock)(*app_context ->unlock)(app_context); |
771 | } |