#!/bin/bash LIBX11_VERSION=1.6.12 SCRIPT_VERSION=4 create_patch_file() { cat << EOF > $1 diff --git a/src/locking.c b/src/locking.c index 9f4fe06777abc007164049ef475d56e23ff28f9e..3981c0f55afd3bab76964add3cd128bee2f003ee 100644 --- a/src/locking.c +++ b/src/locking.c @@ -66,6 +66,8 @@ in this Software without prior written authorization from The Open Group. /* in lcWrap.c */ extern LockInfoPtr _Xi18n_lock; +/* in lcConv.c */ +extern LockInfoPtr _conv_lock; #ifdef WIN32 static DWORD _X_TlsIndex = (DWORD)-1; @@ -98,6 +100,7 @@ static xthread_t _Xthread_self(void) static LockInfoRec global_lock; static LockInfoRec i18n_lock; +static LockInfoRec conv_lock; static void _XLockMutex( LockInfoPtr lip @@ -594,12 +597,22 @@ Status XInitThreads(void) global_lock.lock = NULL; return 0; } + if (!(conv_lock.lock = xmutex_malloc())) { + xmutex_free(global_lock.lock); + global_lock.lock = NULL; + xmutex_free(i18n_lock.lock); + i18n_lock.lock = NULL; + return 0; + } _Xglobal_lock = &global_lock; xmutex_init(_Xglobal_lock->lock); xmutex_set_name(_Xglobal_lock->lock, "Xlib global"); _Xi18n_lock = &i18n_lock; xmutex_init(_Xi18n_lock->lock); xmutex_set_name(_Xi18n_lock->lock, "Xlib i18n"); + _conv_lock = &conv_lock; + xmutex_init(_conv_lock->lock); + xmutex_set_name(_conv_lock->lock, "Xlib conv"); _XLockMutex_fn = _XLockMutex; _XUnlockMutex_fn = _XUnlockMutex; _XCreateMutex_fn = _XCreateMutex; diff --git a/src/xlibi18n/lcConv.c b/src/xlibi18n/lcConv.c index 7d9a4738ccf5abccdaaace5f97404c27858b681f..32699746d1acf0be82a0fa8f70501b9ca2272fea 100644 --- a/src/xlibi18n/lcConv.c +++ b/src/xlibi18n/lcConv.c @@ -29,6 +29,11 @@ #include "Xlibint.h" #include "XlcPubI.h" #include +#include "locking.h" + +#ifdef XTHREADS +LockInfoPtr _conv_lock; +#endif typedef struct _XlcConverterListRec { XLCd from_lcd; @@ -58,6 +63,9 @@ get_converter( XrmQuark to_type) { XlcConverterList list, prev = NULL; + XlcConv conv = NULL; + + _XLockMutex(_conv_lock); for (list = conv_list; list; list = list->next) { if (list->from_lcd == from_lcd && list->to_lcd == to_lcd @@ -69,13 +77,16 @@ get_converter( conv_list = list; } - return (*list->converter)(from_lcd, list->from, to_lcd, list->to); + conv = (*list->converter)(from_lcd, list->from, to_lcd, list->to); + break; } prev = list; } - return (XlcConv) NULL; + _XUnlockMutex(_conv_lock); + + return conv; } Bool @@ -92,18 +103,20 @@ _XlcSetConverter( from_type = XrmStringToQuark(from); to_type = XrmStringToQuark(to); + _XLockMutex(_conv_lock); + for (list = conv_list; list; list = list->next) { if (list->from_lcd == from_lcd && list->to_lcd == to_lcd && list->from_type == from_type && list->to_type == to_type) { list->converter = converter; - return True; + goto ret; } } list = Xmalloc(sizeof(XlcConverterListRec)); if (list == NULL) - return False; + goto ret; list->from_lcd = from_lcd; list->from = from; @@ -115,7 +128,9 @@ _XlcSetConverter( list->next = conv_list; conv_list = list; - return True; +ret: + _XUnlockMutex(_conv_lock); + return list != NULL; } typedef struct _ConvRec { diff --git a/src/xlibi18n/lcStd.c b/src/xlibi18n/lcStd.c index d7490f16bee2382d902cfa5e0adca0fa90aca27c..a8518b05634984fb5068bbba4838e3c671161f40 100644 --- a/src/xlibi18n/lcStd.c +++ b/src/xlibi18n/lcStd.c @@ -36,11 +36,11 @@ _Xlcmbtowc( char *str, int len) { - static XLCd last_lcd = NULL; - static XlcConv conv = NULL; + XlcConv conv; XPointer from, to; int from_left, to_left; wchar_t tmp_wc; + int ret; if (lcd == NULL) { lcd = _XlcCurrentLC(); @@ -50,18 +50,9 @@ _Xlcmbtowc( if (str == NULL) return XLC_PUBLIC(lcd, is_state_depend); - if (conv && lcd != last_lcd) { - _XlcCloseConverter(conv); - conv = NULL; - } - - last_lcd = lcd; - - if (conv == NULL) { - conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar); - if (conv == NULL) + conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar); + if (conv == NULL) return -1; - } from = (XPointer) str; from_left = len; @@ -69,9 +60,12 @@ _Xlcmbtowc( to_left = 1; if (_XlcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0) - return -1; + ret = -1; + else + ret = len - from_left; - return (len - from_left); + _XlcCloseConverter(conv); + return ret; } int @@ -80,10 +74,10 @@ _Xlcwctomb( char *str, wchar_t wc) { - static XLCd last_lcd = NULL; - static XlcConv conv = NULL; + XlcConv conv; XPointer from, to; int from_left, to_left, length; + int ret; if (lcd == NULL) { lcd = _XlcCurrentLC(); @@ -93,18 +87,9 @@ _Xlcwctomb( if (str == NULL) return XLC_PUBLIC(lcd, is_state_depend); - if (conv && lcd != last_lcd) { - _XlcCloseConverter(conv); - conv = NULL; - } - - last_lcd = lcd; - - if (conv == NULL) { - conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte); - if (conv == NULL) - return -1; - } + conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte); + if (conv == NULL) + return -1; from = (XPointer) &wc; from_left = 1; @@ -112,9 +97,12 @@ _Xlcwctomb( length = to_left = XLC_PUBLIC(lcd, mb_cur_max); if (_XlcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0) - return -1; + ret = -1; + else + ret = length - to_left; - return (length - to_left); + _XlcCloseConverter(conv); + return ret; } int diff --git a/src/xlibi18n/lcWrap.c b/src/xlibi18n/lcWrap.c index df660bfa395b2968c5021b1463718dbb9a71a63f..c78ae44f7cb4739e04b71d5a3d5cf2b28d881640 100644 --- a/src/xlibi18n/lcWrap.c +++ b/src/xlibi18n/lcWrap.c @@ -169,7 +169,6 @@ _XlcDefaultMapModifiers( typedef struct _XLCdListRec { struct _XLCdListRec *next; XLCd lcd; - int ref_count; } XLCdListRec, *XLCdList; static XLCdList lcd_list = NULL; @@ -279,7 +278,6 @@ _XOpenLC( for (cur = lcd_list; cur; cur = cur->next) { if (!strcmp (cur->lcd->core->name, name)) { lcd = cur->lcd; - cur->ref_count++; goto found; } } @@ -296,7 +294,6 @@ _XOpenLC( cur = Xmalloc (sizeof(XLCdListRec)); if (cur) { cur->lcd = lcd; - cur->ref_count = 1; cur->next = lcd_list; lcd_list = cur; } else { @@ -323,23 +320,7 @@ void _XCloseLC( XLCd lcd) { - XLCdList cur, *prev; - - for (prev = &lcd_list; (cur = *prev); prev = &cur->next) { - if (cur->lcd == lcd) { - if (--cur->ref_count < 1) { - _XlcDestroyLC(lcd); - *prev = cur->next; - Xfree(cur); - } - break; - } - } - - if(loader_list) { - _XlcDeInitLoader(); - loader_list = NULL; - } + (void) lcd; } /* @@ -349,17 +330,7 @@ _XCloseLC( XLCd _XlcCurrentLC(void) { - XLCd lcd; - static XLCd last_lcd = NULL; - - lcd = _XOpenLC((char *) NULL); - - if (last_lcd) - _XCloseLC(last_lcd); - - last_lcd = lcd; - - return lcd; + return _XOpenLC(NULL); } XrmMethods EOF } echo "create_libx11 version ${SCRIPT_VERSION}" LIB=libX11-${LIBX11_VERSION} FILE=${LIB}.tar.gz read -p "Press [Enter] to get and patch ${LIB} " [[ ! -f $FILE ]] && wget https://www.x.org/releases/individual/lib/${FILE} tar xvfz ${FILE} cd ${LIB} create_patch_file libx11.patch patch -p1 < libx11.patch read -p "Press [Enter] to make ${LIB} " ./configure --prefix=/usr/local/libx11/${LIBX11_VERSION} make -j4 2> make_errors.txt read -p "Press [Enter] to see make error output" less make_errors.txt read -p "Press [Enter] to install..." sudo make install read -p "Press [Enter] to backup and overwrite old librarires..." sudo cp --backup=t /usr/local/libx11/${LIBX11_VERSION}/lib/libX11.so.6.3.0 /usr/lib/x86_64-linux-gnu/ sudo cp --backup=t /usr/local/libx11/${LIBX11_VERSION}/lib/libX11-xcb.so.1.0.0 /usr/lib/x86_64-linux-gnu/