gcc-6: use $(GNU_ARCH) in manifest
[unleashed-userland.git] / components / x11 / libXt / patches / 6671721.patch
blob0a68e615553024373eb5f7edfc01b686e67814e9
1 diff --git a/configure.ac b/configure.ac
2 index d15b326..28185fe 100644
3 --- a/configure.ac
4 +++ b/configure.ac
5 @@ -72,6 +72,7 @@ AC_SUBST(LDFLAGS_FOR_BUILD)
7 # Map function checks to old Imake #defines
8 case $host_os in
9 + solaris*) ;; # our changes to NextEvent.c break if poll() is used
10 # darwin through Snow Leopard has poll() but can't be used to poll character devices.
11 darwin@<:@789@:>@*|darwin10*) ;;
12 darwin*)
13 diff --git a/include/X11/Intrinsic.h b/include/X11/Intrinsic.h
14 index d09acad..d30e01f 100644
15 --- a/include/X11/Intrinsic.h
16 +++ b/include/X11/Intrinsic.h
17 @@ -125,6 +125,7 @@ typedef int XtCacheType;
18 #define XtCacheAll 0x002
19 #define XtCacheByDisplay 0x003
20 #define XtCacheRefCount 0x100
21 +#define XtCacheXmRefCount 0x200
23 /****************************************************************
25 @@ -253,6 +254,8 @@ typedef void (*XtDestructor)(
26 Cardinal* /* num_args */
29 +typedef XtPointer (*XtReplicator)(XtPointer);
31 typedef Opaque XtCacheRef;
33 typedef Opaque XtActionHookId;
34 @@ -656,6 +659,17 @@ extern void XtSetTypeConverter(
35 XtDestructor /* destructor */
38 +extern void _XtSetTypeConverter(
39 + _Xconst _XtString /* from_type */,
40 + _Xconst _XtString /* to_type */,
41 + XtTypeConverter /* converter */,
42 + XtConvertArgList /* convert_args */,
43 + Cardinal /* num_args */,
44 + XtCacheType /* cache_type */,
45 + XtDestructor /* destructor */,
46 + XtReplicator /* replicator */
47 +);
49 extern void XtAppSetTypeConverter(
50 XtAppContext /* app_context */,
51 _Xconst _XtString /* from_type */,
52 diff --git a/src/Convert.c b/src/Convert.c
53 index cea8fd3..265b162 100644
54 --- a/src/Convert.c
55 +++ b/src/Convert.c
56 @@ -87,6 +87,7 @@ typedef struct _ConverterRec {
57 XrmRepresentation from, to;
58 XtTypeConverter converter;
59 XtDestructor destructor;
60 + XtReplicator replicator;
61 unsigned short num_args;
62 unsigned int do_ref_count:1;
63 unsigned int new_style:1;
64 @@ -94,6 +95,20 @@ typedef struct _ConverterRec {
65 /* used for old-style type converter cache only */
66 static Heap globalHeap = {NULL, NULL, 0};
68 +static
69 +void TableAddConverter(
70 + ConverterTable table,
71 + XrmRepresentation from_type,
72 + XrmRepresentation to_type,
73 + XtTypeConverter converter,
74 + XtConvertArgList convert_args,
75 + Cardinal num_args,
76 + _XtBoolean new_style,
77 + XtCacheType cache_type,
78 + XtDestructor destructor,
79 + XtReplicator replicator,
80 + _XtBoolean global);
82 void _XtSetDefaultConverterTable(
83 ConverterTable *table)
85 @@ -117,13 +132,11 @@ void _XtSetDefaultConverterTable(
86 XtCacheType cache_type;
87 for (i = CONVERTHASHSIZE; --i >= 0; ) {
88 for (rec = *globalConverterTable++; rec; rec = rec->next) {
89 - cache_type = rec->cache_type;
90 - if (rec->do_ref_count)
91 - cache_type |= XtCacheRefCount;
92 - _XtTableAddConverter(*table, rec->from, rec->to, rec->converter,
93 + cache_type = rec->cache_type | (rec->do_ref_count & 0xff00);
94 + TableAddConverter(*table, rec->from, rec->to, rec->converter,
95 ConvertArgs(rec), rec->num_args,
96 rec->new_style, cache_type,
97 - rec->destructor, True);
98 + rec->destructor, rec->replicator, True);
102 @@ -155,10 +168,14 @@ typedef struct _CacheRec {
103 XtPointer tag;
104 int hash;
105 XtTypeConverter converter;
106 + XtDestructor destructor;
107 + XtReplicator replicator;
108 + XtPointer closure;
109 unsigned short num_args;
110 unsigned int conversion_succeeded:1;
111 unsigned int has_ext:1;
112 unsigned int is_refcounted:1;
113 + unsigned int ref_count;
114 unsigned int must_be_freed:1;
115 unsigned int from_is_value:1;
116 unsigned int to_is_value:1;
117 @@ -166,15 +183,7 @@ typedef struct _CacheRec {
118 XrmValue to;
119 } CacheRec;
121 -typedef struct _CacheRecExt {
122 - CachePtr *prev;
123 - XtDestructor destructor;
124 - XtPointer closure;
125 - long ref_count;
126 -} CacheRecExt;
128 -#define CEXT(p) ((CacheRecExt *)((p)+1))
129 -#define CARGS(p) ((p)->has_ext ? (XrmValue *)(CEXT(p)+1) : (XrmValue *)((p)+1))
130 +#define CARGS(p) (XrmValue *)((p)+(ptrdiff_t)1)
132 #define CACHEHASHSIZE 256
133 #define CACHEHASHMASK 255
134 @@ -183,6 +192,28 @@ typedef CachePtr CacheHashTable[CACHEHASHSIZE];
135 static CacheHashTable cacheHashTable;
137 void _XtTableAddConverter(
138 + ConverterTable table,
139 + XrmRepresentation from_type,
140 + XrmRepresentation to_type,
141 + XtTypeConverter converter,
142 + XtConvertArgList convert_args,
143 + Cardinal num_args,
144 + _XtBoolean new_style,
145 + XtCacheType cache_type,
146 + XtDestructor destructor,
147 + _XtBoolean global)
150 + unsigned short cache_flags;
152 + cache_flags = cache_type & (XtCacheNone | XtCacheAll |
153 + XtCacheByDisplay | XtCacheRefCount);
155 + TableAddConverter(table, from_type, to_type, converter, convert_args, num_args,
156 + new_style, cache_type, destructor, 0, global);
159 +void TableAddConverter(
160 ConverterTable table,
161 XrmRepresentation from_type,
162 XrmRepresentation to_type,
163 @@ -192,6 +223,7 @@ void _XtTableAddConverter(
164 _XtBoolean new_style,
165 XtCacheType cache_type,
166 XtDestructor destructor,
167 + XtReplicator replicator,
168 _XtBoolean global)
170 register ConverterPtr *pp;
171 @@ -215,6 +247,7 @@ void _XtTableAddConverter(
172 p->to = to_type;
173 p->converter = converter;
174 p->destructor = destructor;
175 + p->replicator = replicator;
176 p->num_args = num_args;
177 p->global = global;
178 args = ConvertArgs(p);
179 @@ -224,21 +257,21 @@ void _XtTableAddConverter(
180 p->do_ref_count = False;
181 if (destructor || (cache_type & 0xff)) {
182 p->cache_type = cache_type & 0xff;
183 - if (cache_type & XtCacheRefCount)
184 - p->do_ref_count = True;
185 + p->do_ref_count = cache_type & 0xff00;
186 } else {
187 p->cache_type = XtCacheNone;
191 -void XtSetTypeConverter(
192 +void _XtSetTypeConverter(
193 register _Xconst char* from_type,
194 register _Xconst char* to_type,
195 - XtTypeConverter converter,
196 + XtTypeConverter converter,
197 XtConvertArgList convert_args,
198 - Cardinal num_args,
199 - XtCacheType cache_type,
200 - XtDestructor destructor
201 + Cardinal num_args,
202 + XtCacheType cache_type,
203 + XtDestructor destructor,
204 + XtReplicator replicator
207 ProcessContext process;
208 @@ -253,21 +286,41 @@ void XtSetTypeConverter(
209 to = XrmStringToRepresentation(to_type);
211 if (!process->globalConverterTable) {
212 - process->globalConverterTable = (ConverterTable)
213 - __XtCalloc(CONVERTHASHSIZE, (unsigned)sizeof(ConverterPtr));
214 + process->globalConverterTable = (ConverterTable)
215 + __XtCalloc(CONVERTHASHSIZE, (unsigned)sizeof(ConverterPtr));
217 - _XtTableAddConverter(process->globalConverterTable, from, to,
218 - converter, convert_args,
219 - num_args, True, cache_type, destructor, True);
221 + TableAddConverter(process->globalConverterTable, from, to, converter,
222 + convert_args, num_args, True, cache_type, destructor,
223 + replicator, True);
224 while (app) {
225 - _XtTableAddConverter(app->converterTable, from, to,
226 - converter, convert_args,
227 - num_args, True, cache_type, destructor, True);
228 + TableAddConverter(app->converterTable, from, to, converter,
229 + convert_args, num_args, True, cache_type,
230 + destructor, replicator, True);
231 app = app->next;
233 UNLOCK_PROCESS;
236 +void XtSetTypeConverter(
237 + register _Xconst char* from_type,
238 + register _Xconst char* to_type,
239 + XtTypeConverter converter,
240 + XtConvertArgList convert_args,
241 + Cardinal num_args,
242 + XtCacheType cache_type,
243 + XtDestructor destructor
246 + unsigned short cache_flags;
248 + cache_flags = cache_type & (XtCacheNone | XtCacheAll |
249 + XtCacheByDisplay | XtCacheRefCount);
251 + _XtSetTypeConverter(from_type, to_type, converter, convert_args, num_args,
252 + cache_flags, destructor, 0);
255 void XtAppSetTypeConverter(
256 XtAppContext app,
257 register _Xconst char* from_type,
258 @@ -357,6 +410,7 @@ CacheEnter(
259 Boolean do_ref,
260 Boolean do_free,
261 XtDestructor destructor,
262 + XtReplicator replicator,
263 XtPointer closure)
265 register CachePtr *pHashEntry;
266 @@ -366,34 +420,22 @@ CacheEnter(
267 LOCK_PROCESS;
268 pHashEntry = &cacheHashTable[hash & CACHEHASHMASK];
270 - if ((succeeded && destructor) || do_ref) {
271 - p = (CachePtr) _XtHeapAlloc(heap, (sizeof(CacheRec) +
272 - sizeof(CacheRecExt) +
273 - num_args * sizeof(XrmValue)));
274 - CEXT(p)->prev = pHashEntry;
275 - CEXT(p)->destructor = succeeded ? destructor : NULL;
276 - CEXT(p)->closure = closure;
277 - CEXT(p)->ref_count = 1;
278 - p->has_ext = True;
280 - else {
281 - p = (CachePtr)_XtHeapAlloc(heap, (sizeof(CacheRec) +
282 - num_args * sizeof(XrmValue)));
283 - p->has_ext = False;
285 + p = (CachePtr)_XtHeapAlloc(heap,
286 + (sizeof(CacheRec) + num_args * sizeof(XrmValue)));
288 if (!to->addr)
289 succeeded = False;
290 p->conversion_succeeded = succeeded;
291 p->is_refcounted = do_ref;
292 p->must_be_freed = do_free;
293 p->next = *pHashEntry;
294 - if (p->next && p->next->has_ext)
295 - CEXT(p->next)->prev = &p->next;
297 *pHashEntry = p;
298 p->tag = (XtPointer)heap;
299 p->hash = hash;
300 p->converter = converter;
301 + p->destructor = destructor;
302 + p->replicator = replicator;
303 + p->closure = closure;
304 p->from.size = from->size;
305 if (from->size <= sizeof(p->from.addr)) {
306 p->from_is_value = True;
307 @@ -416,14 +458,31 @@ CacheEnter(
308 if (!succeeded) {
309 p->to_is_value = False;
310 p->to.addr = NULL;
311 - } else if (to->size <= sizeof(p->to.addr)) {
312 - p->to_is_value = True;
313 - XtMemmove(&p->to.addr, to->addr, to->size);
314 } else {
315 - p->to_is_value = False;
316 - p->to.addr = (XPointer)_XtHeapAlloc(heap, to->size);
317 - (void) memmove((char *)p->to.addr, (char *)to->addr, to->size);
318 + XPointer src_ptr, dest_ptr, gptr;
320 + if ((size_t)to->size <= sizeof(p->to.addr)) {
321 + p->to_is_value = True;
322 + dest_ptr = (XPointer)&p->to.addr;
323 + } else {
324 + p->to_is_value = False;
325 + dest_ptr = p->to.addr = (XPointer)_XtHeapAlloc(heap, to->size);
328 + if (do_ref & XtCacheXmRefCount) {
329 + gptr = (*(p->replicator))(*(XtPointer *)(to->addr));
330 + src_ptr = (XtPointer)&gptr;
331 + } else {
332 + src_ptr = to->addr;
335 + memmove(dest_ptr, src_ptr, to->size);
338 + if ((succeeded && destructor) || do_ref) {
339 + p->ref_count = 1;
342 UNLOCK_PROCESS;
343 return p;
345 @@ -431,32 +490,39 @@ CacheEnter(
346 static void FreeCacheRec(
347 XtAppContext app,
348 CachePtr p,
349 - CachePtr *prev)
350 + Boolean clean_table)
352 LOCK_PROCESS;
353 - if (p->has_ext) {
354 - if (CEXT(p)->destructor) {
355 - Cardinal num_args = p->num_args;
356 - XrmValue *args = NULL;
357 - XrmValue toc;
358 - if (num_args)
359 - args = CARGS(p);
360 - toc.size = p->to.size;
361 - if (p->to_is_value)
362 - toc.addr = (XPointer)&p->to.addr;
363 - else
364 - toc.addr = p->to.addr;
365 - (*CEXT(p)->destructor) (app, &toc, CEXT(p)->closure, args,
366 - &num_args);
368 - *(CEXT(p)->prev) = p->next;
369 - if (p->next && p->next->has_ext)
370 - CEXT(p->next)->prev = CEXT(p)->prev;
371 - } else {
372 - *prev = p->next;
373 - if (p->next && p->next->has_ext)
374 - CEXT(p->next)->prev = prev;
375 + if (clean_table) {
376 + CachePtr cachep, *cachepp;
378 + cachepp = &cacheHashTable[p->hash & CACHEHASHMASK];
379 + while (cachep = *cachepp) {
380 + if (p == cachep) {
381 + *cachepp = cachep->next;
382 + break;
384 + cachepp = &cachep->next;
385 + }
388 + if (p->destructor) {
389 + Cardinal num_args=p->num_args;
390 + XrmValue *args=NULL;
391 + XrmValue toc;
393 + if (num_args) {
394 + args = CARGS(p);
396 + toc.size = p->to.size;
397 + if (p->to_is_value) {
398 + toc.addr = (XPointer)&p->to.addr;
399 + } else {
400 + toc.addr = p->to.addr;
402 + (*p->destructor)(app, &toc, p->closure, args, &num_args);
405 if (p->must_be_freed) {
406 register int i;
407 if (!p->from_is_value)
408 @@ -480,18 +546,18 @@ void _XtCacheFlushTag(
409 XtPointer tag)
411 int i;
412 - register CachePtr *prev;
413 register CachePtr rec;
414 + register CachePtr *next_link;
416 LOCK_PROCESS;
417 for (i = CACHEHASHSIZE; --i >= 0;) {
418 - prev = &cacheHashTable[i];
419 - while ((rec = *prev)) {
420 + next_link = &cacheHashTable[i];
421 + while ((rec = *next_link)) {
422 + next_link = &rec->next;
423 if (rec->tag == tag)
424 - FreeCacheRec(app, rec, prev);
425 - else
426 - prev = &rec->next;
427 + FreeCacheRec(app, rec, False);
429 + cacheHashTable[i] = 0;
431 UNLOCK_PROCESS;
433 @@ -641,7 +707,12 @@ void XtDirectConvert(
434 LOCK_PROCESS;
435 /* Try to find cache entry for conversion */
436 hash = ((long) converter >> 2) + from->size + *((char *) from->addr);
437 - if (from->size > 1) hash += ((char *) from->addr)[1];
438 + if (from->size > 1) {
439 + if (sizeof(long) == 4)
440 + hash += ((char *) from->addr)[1];
441 + else
442 + hash += ((char *) from->addr)[6];
445 for (p = cacheHashTable[hash & CACHEHASHMASK]; p; p = p->next) {
446 if ((p->hash == hash)
447 @@ -685,7 +756,7 @@ void XtDirectConvert(
449 CacheEnter(&globalHeap, (XtTypeConverter)converter, args, num_args,
450 from, to, (to->addr != NULL), hash, False, False,
451 - (XtDestructor)NULL, NULL);
452 + (XtDestructor)NULL, NULL, 0);
454 UNLOCK_PROCESS;
456 @@ -726,6 +797,7 @@ CallConverter(
457 int hash;
458 Cardinal i;
459 Boolean retval;
460 + XPointer from_addr, gptr;
462 if (!cP || ((cP->cache_type == XtCacheNone) && !cP->destructor)) {
463 XtPointer closure;
464 @@ -738,7 +810,12 @@ CallConverter(
465 LOCK_PROCESS;
466 /* Try to find cache entry for conversion */
467 hash = ((long)(converter) >> 2) + from->size + *((char *) from->addr);
468 - if (from->size > 1) hash += ((char *) from->addr)[1];
469 + if (from->size > 1) {
470 + if (sizeof(long) == 4)
471 + hash += ((char *) from->addr)[1];
472 + else
473 + hash += ((char *) from->addr)[6];
476 if (cP->cache_type != XtCacheNone) {
477 for (p = cacheHashTable[hash & CACHEHASHMASK]; p; p = p->next){
478 @@ -770,14 +847,18 @@ CallConverter(
479 UNLOCK_PROCESS;
480 return False;
482 - to->size = p->to.size;
483 - if (p->to_is_value) {
484 - XtMemmove(to->addr, &p->to.addr,
485 - to->size);
486 + if (cP->do_ref_count & XtCacheXmRefCount) {
487 + gptr = (*(p->replicator))(p->to.addr);
488 + from_addr = (XPointer)&gptr;
489 + } else if (p->to_is_value) {
490 + from_addr = (XPointer)&p->to.addr;
491 } else {
492 - (void) memmove((char *)to->addr,
493 - (char *)p->to.addr, to->size);
494 + from_addr = p->to.addr;
497 + to->size = p->to.size;
498 + memmove((char *)to->addr, from_addr,
499 + to->size);
500 } else { /* old-style call */
501 to->size = p->to.size;
502 if (p->to_is_value)
503 @@ -787,7 +868,7 @@ CallConverter(
506 if (p->is_refcounted) {
507 - CEXT(p)->ref_count++;
508 + p->ref_count++;
509 if (cache_ref_return)
510 *cache_ref_return = (XtCacheRef)p;
511 else
512 @@ -810,7 +891,7 @@ CallConverter(
513 Heap *heap;
514 XtPointer closure = NULL;
515 unsigned int supplied_size = to->size;
516 - Boolean do_ref = cP->do_ref_count && cache_ref_return;
517 + unsigned short do_ref;
518 Boolean do_free = False;
519 Boolean retval =
520 (*(XtTypeConverter)converter)(dpy, args, &num_args, from, to, &closure);
521 @@ -823,6 +904,8 @@ CallConverter(
522 return False;
525 + do_ref = cache_ref_return ? cP->do_ref_count : 0;
527 if ((cP->cache_type == XtCacheNone) || do_ref) {
528 heap = NULL;
529 do_free = True;
530 @@ -834,8 +917,12 @@ CallConverter(
531 else
532 heap = &XtDisplayToApplicationContext(dpy)->heap;
534 - p = CacheEnter(heap, converter, args, num_args, from, to, retval,
535 - hash, do_ref, do_free, cP->destructor, closure);
536 + if (do_ref || !(cP->do_ref_count & XtCacheXmRefCount)) {
537 + p = CacheEnter(heap, converter, args, num_args, from, to, retval,
538 + hash, do_ref, do_free, cP->destructor,
539 + cP->replicator, closure);
542 if (do_ref)
543 *cache_ref_return = (XtCacheRef)p;
544 else if (cache_ref_return)
545 @@ -1061,8 +1148,8 @@ void XtAppReleaseCacheRefs(
546 LOCK_APP(app);
547 LOCK_PROCESS;
548 for (r = (CachePtr*)refs; (p = *r); r++) {
549 - if (p->is_refcounted && --(CEXT(p)->ref_count) == 0) {
550 - FreeCacheRec(app, p, NULL);
551 + if (p->is_refcounted && (--p->ref_count) == 0) {
552 + FreeCacheRec(app, p, True);
555 UNLOCK_PROCESS;
556 @@ -1078,7 +1165,6 @@ void XtCallbackReleaseCacheRefList(
558 XtAppReleaseCacheRefs( XtWidgetToApplicationContext(widget),
559 (XtCacheRef*)closure );
560 - XtFree(closure);
564 diff --git a/src/Create.c b/src/Create.c
565 index da00192..b756223 100644
566 --- a/src/Create.c
567 +++ b/src/Create.c
568 @@ -405,8 +405,7 @@ xtCreate(
569 CompileCallbacks(widget);
571 if (cache_refs != NULL) {
572 - XtAddCallback(widget, XtNdestroyCallback,
573 - XtCallbackReleaseCacheRefList, (XtPointer)cache_refs );
574 + XtFree(cache_refs);
577 wsize = widget_class->core_class.widget_size;
578 diff --git a/src/Display.c b/src/Display.c
579 index 4ccf079..72ed668 100644
580 --- a/src/Display.c
581 +++ b/src/Display.c
582 @@ -323,12 +323,15 @@ _XtAppInit(
583 * Save away argv and argc so we can set the properties later
586 - saved_argv = (String *)
587 - __XtMalloc( (Cardinal)((*argc_in_out + 1) * sizeof(String)) );
589 - for (i = 0 ; i < *argc_in_out ; i++) saved_argv[i] = (*argv_in_out)[i];
590 - saved_argv[i] = NULL; /* NULL terminate that sucker. */
592 + if(*argv_in_out != NULL) {
593 + saved_argv = (String *)
594 + __XtMalloc( (Cardinal)((*argc_in_out + 1) * sizeof(String)) );
596 + for (i = 0 ; i < *argc_in_out ; i++) saved_argv[i] = (*argv_in_out)[i];
597 + saved_argv[i] = NULL; /* NULL terminate that sucker. */
598 + } else {
599 + saved_argv = NULL;
602 *app_context_return = XtCreateApplicationContext();
604 diff --git a/src/Event.c b/src/Event.c
605 index 11823d6..7c15e83 100644
606 --- a/src/Event.c
607 +++ b/src/Event.c
608 @@ -563,6 +563,14 @@ void XtRegisterDrawable(
609 UNLOCK_APP(app);
612 +/* need this for backward compatability */
613 +void _XtRegisterWindow(
614 + Window window,
615 + Widget widget)
617 + XtRegisterDrawable(XtDisplay(widget), (Drawable)window, widget);
620 void XtUnregisterDrawable(
621 Display* display,
622 Drawable drawable)
623 @@ -613,6 +621,14 @@ void XtUnregisterDrawable(
624 UNLOCK_APP(app);
627 +/* need this for backward compatability */
628 +void _XtUnregisterWindow(
629 + register Window window,
630 + register Widget widget)
632 + XtUnregisterDrawable(XtDisplay(widget), (Drawable)window);
635 static void ExpandWWTable(
636 register WWTable tab)
638 diff --git a/src/Geometry.c b/src/Geometry.c
639 index d64c8e2..c8ddbd6 100644
640 --- a/src/Geometry.c
641 +++ b/src/Geometry.c
642 @@ -330,6 +330,12 @@ _XtMakeGeometryRequest (
643 } else {
644 returnCode = (*manager)(widget, request, reply);
647 + /* leob fix for bug 4153816 */
648 + if (returnCode == XtGeometryDone && XtIsRealized(widget) &&
649 + (widget->core.width != request->width ||
650 + widget->core.height != request->height) )
651 + return XtGeometryYes;
655 diff --git a/src/Initialize.c b/src/Initialize.c
656 index 9783deb..2a5a8a8 100644
657 --- a/src/Initialize.c
658 +++ b/src/Initialize.c
659 @@ -473,7 +473,7 @@ static String _XtDefaultLanguageProc(
660 if (! XSetLocaleModifiers(""))
661 XtWarning("X locale modifiers not supported, using default");
663 - return setlocale(LC_ALL, NULL); /* re-query in case overwritten */
664 + return setlocale(LC_CTYPE, NULL); /* re-query in case overwritten */
667 XtLanguageProc XtSetLanguageProc(
668 @@ -994,8 +994,13 @@ Widget XtOpenApplication(XtAppContext *app_context_return,
670 LOCK_APP(app_con);
671 XtSetArg(args[num], XtNscreen, DefaultScreenOfDisplay(dpy)); num++;
672 - XtSetArg(args[num], XtNargc, saved_argc); num++;
673 - XtSetArg(args[num], XtNargv, argv_in_out); num++;
674 + /* only set argc and argv if argv_in_out[0] is not NULL */
675 + if (argv_in_out && argv_in_out[0]) {
676 + XtSetArg(args[num], XtNargc, saved_argc);
677 + num++;
678 + XtSetArg(args[num], XtNargv, argv_in_out);
679 + num++;
682 merged_args = XtMergeArgLists(args_in, num_args_in, args, num);
683 num += num_args_in;
684 diff --git a/src/Makefile.am b/src/Makefile.am
685 index cf54a5c..a786d94 100644
686 --- a/src/Makefile.am
687 +++ b/src/Makefile.am
688 @@ -74,7 +74,8 @@ DISTCLEANFILES = StringDefs.c
690 libXt_la_LIBADD = @XT_LIBS@
692 -libXt_la_LDFLAGS = -version-number 6:0:0 -no-undefined
693 +libXt_la_LDFLAGS = -version-number 4:0:0 -no-undefined \
694 + -Wl,-M$(top_srcdir)/../mapfile-vers -lc
697 # The util directory contains a program that builds some of the sources.
698 diff --git a/src/NextEvent.c b/src/NextEvent.c
699 index b1f7bc7..c9b53db 100644
700 --- a/src/NextEvent.c
701 +++ b/src/NextEvent.c
702 @@ -347,6 +347,51 @@ static void AdjustTimes (
703 #endif
706 +static void CheckAndTrimTimes(XtAppContext app, wait_times_ptr_t wt)
708 + struct timeval tv;
709 + String pptrs[8];
710 + Cardinal nbr_parms;
712 + pptrs[0] = (String)zero_time.tv_sec;
713 + pptrs[1] = (String)zero_time.tv_usec;
714 + pptrs[2] = (String)wt->wait_time.tv_sec;
715 + pptrs[3] = (String)wt->wait_time.tv_usec;
716 + pptrs[4] = (String)wt->max_wait_time.tv_sec;
717 + pptrs[5] = (String)wt->max_wait_time.tv_usec;
718 + pptrs[6] = (String)wt->cur_time.tv_sec;
719 + pptrs[7] = (String)wt->cur_time.tv_usec;
720 + nbr_parms = 8;
721 + XtAppErrorMsg(app, "communicationError", "select",
722 + XtCXtToolkitError, "Resetting timer values: zero_time=%lu:%lu, "
723 + "wait_time=%lu:%lu, max_wait_time=%lu:%lu, cur_time=%lu:%lu",
724 + pptrs, &nbr_parms);
726 + memset(&zero_time, 0, sizeof(zero_time)); /* Ensure the integrity of */
727 + /* zero_time. */
728 + if (wt->max_wait_time.tv_sec > 99999999) /* Bring max_wait_time back into */
729 + { /* acceptable range if nec. */
730 + wt->max_wait_time.tv_sec &= 0xFFFFF;
731 + wt->max_wait_time.tv_usec = 0; /* (Fractions of a sec are in- */
732 + /* significant at this level.) */
734 + if (app->timerQueue != NULL) /* Do the same for the head of */
735 + { /* the timer queue if necessary. */
736 + TIMEDELTA(tv, app->timerQueue->te_timer_value, wt->cur_time);
737 + if (tv.tv_sec > 99999999)
739 + pptrs[0] = (String)app->timerQueue->te_timer_value.tv_sec;
740 + pptrs[1] = (String)app->timerQueue->te_timer_value.tv_usec;
741 + nbr_parms = 2;
742 + XtAppErrorMsg(app, "selectError", "timerQueue",
743 + XtCXtToolkitError, "timerQueue value %lu:%lu is invalid",
744 + pptrs, &nbr_parms);
745 + tv.tv_sec &= 0xFFFFF;
746 + tv.tv_usec = 0;
747 + ADD_TIME(app->timerQueue->te_timer_value, wt->cur_time, tv);
752 static int IoWait (
753 wait_times_ptr_t wt,
754 @@ -629,20 +674,56 @@ WaitLoop:
756 * interrupt occured recalculate time value and wait again.
758 - if (errno == EINTR || errno == EAGAIN) {
759 - if (errno == EAGAIN) {
760 - errno = 0; /* errno is not self reseting */
761 - continue;
763 - errno = 0; /* errno is not self reseting */
765 - /* was it interrupted by a signal that we care about? */
766 - if (!ignoreSignals && app->signalQueue != NULL) {
767 - SignalEventRec *se_ptr = app->signalQueue;
768 - while (se_ptr != NULL) {
769 - if (se_ptr->se_notice) {
770 - if (block && howlong != NULL)
771 - AdjustHowLong (howlong, &wt.start_time);
772 + if (errno == EAGAIN) {
773 + errno = 0; /* errno is not self reseting */
774 + continue;
775 + } else if (errno == EBADF) {
776 + /* Bug 4482749 - If we have a bad FD stop monitoring it */
777 + int i;
778 + struct timeval tv={0};
779 + for (i = 0; i < wf.nfds; i++) {
780 + if (FD_ISSET(i, &wf.rmask) || FD_ISSET(i, &wf.wmask) ||
781 + FD_ISSET(i, &wf.emask)) {
782 + if (select(i + 1, &wf.rmask, &wf.wmask, &wf.emask, &tv)
783 + == -1) {
784 + char bad_fd[55];
785 + String param = bad_fd;
786 + Cardinal param_count = 1;
788 + /*
789 + * Get rid of any input procedures on the bad FD
790 + * and regenerate the list of FDs we listen to.
791 + */
792 + while (app->input_list[i] != NULL) {
793 + XtRemoveInput((XtInputId)app->input_list[i]);
795 + InitFds (app, ignoreEvents, ignoreInputs, &wf);
797 + sprintf(bad_fd, "%d", errno);
798 + XtAppWarningMsg(app, "communicationError", "select",
799 + XtCXtToolkitError,
800 + "Select failed; error code %s",
801 + &param, &param_count);
803 + sprintf(bad_fd, "EBADF error in select() call for file descriptor %d", i);
804 + XtAppWarning(app, param);
810 + return -1;
812 + } else if (errno == EINTR) {
813 + errno = 0;
815 + /* was it interrupted by a signal that we care about? */
816 + if (!ignoreSignals && app->signalQueue != NULL) {
817 + SignalEventRec *se_ptr = app->signalQueue;
818 + while (se_ptr != NULL) {
819 + if (se_ptr->se_notice) {
820 + if (block && howlong != NULL)
821 + AdjustHowLong (howlong, &wt.start_time);
822 #ifdef USE_POLL
823 XtStackFree ((XtPointer) wf.fdlist, fdlist);
824 #endif
825 @@ -687,17 +768,33 @@ WaitLoop:
826 #endif
827 nfds = 0;
829 - } else {
830 - char Errno[12];
831 - String param = Errno;
832 - Cardinal param_count = 1;
834 - sprintf( Errno, "%d", errno);
835 - XtAppWarningMsg(app, "communicationError","select",
836 - XtCXtToolkitError,"Select failed; error code %s",
837 - &param, &param_count);
838 - continue;
840 + } else if (errno == EINVAL) { /* (Can be recovered from if */
841 + struct timeval tv={0};
843 + nfds = Select(wf.nfds, &wf.rmask, &wf.wmask, &wf.emask, &tv);
844 + /* Do a non-blocking select to */
845 + /* eliminate any timeout errors.*/
846 + if (nfds == -1) { /* Now try to sort out the good */
847 + if (errno == EINVAL) { /* and the bad from the ugly. */
848 + char Errno[12]; /* (This is ugly). */
849 + String param = Errno;
850 + Cardinal param_count = 1;
852 + sprintf(Errno, "%d", errno);
853 + XtAppErrorMsg(app, "communicationError", "select",
854 + XtCXtToolkitError, "Select failed; error code %s",
855 + &param, &param_count);
856 + XtAppError(app, "EINVAL error in select() call");
857 + } else { /* If the new error is not about */
858 + /* an invalid select() parameter,*/
859 + continue; /* then simply try again. */
861 + } else { /* (Else the error appears to be */
862 + /* in the timeout parameter.) */
863 + CheckAndTrimTimes(app, &wt);
864 + continue;
867 } /* timed out or input available */
868 break;
870 @@ -750,6 +847,33 @@ WaitLoop:
871 #define SeCallProc(ptr) \
872 (*ptr->se_proc) (ptr->se_closure, (XtSignalId*)&ptr);
874 +#ifdef sun /*SUNSOFT */
875 +int _XtwaitForSomething(
876 + _XtBoolean ignoreTimers,
877 + _XtBoolean ignoreInputs,
878 + _XtBoolean ignoreEvents,
879 + _XtBoolean block,
880 + unsigned long *howlong,
881 + XtAppContext app)
883 +#ifdef XTHREADS
884 +/* fix for bug 4185875 leob */
885 +return _XtWaitForSomething(app,
886 + ignoreEvents, ignoreTimers, ignoreInputs, TRUE,
887 + block,
888 + TRUE,
889 + howlong);
890 +#else
891 +/* fix for bug 4185875 leob */
892 +return _XtWaitForSomething(app,
893 + ignoreEvents, ignoreTimers, ignoreInputs, TRUE,
894 + block,
895 + howlong);
896 +#endif
899 +#endif /* SUNSOFT */
902 * Public Routines