Index: lib/X11/XimintL.h =================================================================== RCS file: /cvs/xorg/xc/lib/X11/XimintL.h,v retrieving revision 1.2 diff -u -p -r1.2 XimintL.h --- lib/X11/XimintL.h 23 Apr 2004 18:43:24 -0000 1.2 +++ lib/X11/XimintL.h 28 Feb 2005 15:26:42 -0000 @@ -40,21 +40,36 @@ THIS SOFTWARE. #define COMPOSE_FILE "Compose" /* - * Data Structure for Local Processing + * Data Structures for Local Processing */ +typedef INT32 DTIndex; +typedef INT32 DTCharIndex; +typedef BITS32 DTModifier; + typedef struct _DefTree { - struct _DefTree *next; /* another Key definition */ - struct _DefTree *succession; /* successive Key Sequence */ + DTIndex next; + DTIndex succession; /* -"- successive Key Sequence */ /* Key definitions */ - unsigned modifier_mask; - unsigned modifier; + DTModifier modifier_mask; + DTModifier modifier; KeySym keysym; /* leaf only */ - char *mb; - wchar_t *wc; /* make from mb */ - char *utf8; /* make from mb */ + DTCharIndex mb; + DTCharIndex wc; /* make from mb */ + DTCharIndex utf8; /* make from mb */ KeySym ks; } DefTree; +typedef struct _DefTreeBase { + DefTree *tree; + char *mb; + wchar_t *wc; + char *utf8; + DTIndex treeused, treesize; + DTCharIndex mbused, mbsize; + DTCharIndex wcused, wcsize; + DTCharIndex utf8used, utf8size; +} DefTreeBase; + typedef struct _XimLocalPrivateRec { /* The first fields are identical with XimCommonPrivateRec. */ XlcConv ctom_conv; @@ -67,7 +82,8 @@ typedef struct _XimLocalPrivateRec { XlcConv ucstoutf8_conv; XIC current_ic; - DefTree *top; + DefTreeBase base; + DTIndex top; } XimLocalPrivateRec; typedef struct _XicThaiPart { @@ -78,8 +94,9 @@ typedef struct _XicThaiPart { typedef struct _XicLocalPrivateRec { long value_mask; - DefTree *context; - DefTree *composed; + DefTreeBase base; + DTIndex context; + DTIndex composed; XicThaiPart thai; XIMResourceList ic_resources; Index: lib/X11/XlibInt.c =================================================================== RCS file: /cvs/xorg/xc/lib/X11/XlibInt.c,v retrieving revision 1.5 diff -u -p -r1.5 XlibInt.c --- lib/X11/XlibInt.c 1 Dec 2004 12:42:17 -0000 1.5 +++ lib/X11/XlibInt.c 28 Feb 2005 15:26:44 -0000 @@ -3366,6 +3366,26 @@ int _XOpenFile(path, flags) return ret; } +int _XOpenFileMode(path, flags, mode) + _Xconst char* path; + int flags; + mode_t mode; +{ + char buf[MAX_PATH]; + char* bufp = NULL; + int ret = -1; + UINT olderror = SetErrorMode (SEM_FAILCRITICALERRORS); + + if (AccessFile (path, buf, MAX_PATH, &bufp)) + ret = open (bufp, flags, mode); + + (void) SetErrorMode (olderror); + + if (bufp != buf) Xfree (bufp); + + return ret; +} + void* _XFopenFile(path, mode) _Xconst char* path; _Xconst char* mode; Index: lib/X11/Xlibint.h =================================================================== RCS file: /cvs/xorg/xc/lib/X11/Xlibint.h,v retrieving revision 1.3 diff -u -p -r1.3 Xlibint.h --- lib/X11/Xlibint.h 31 Aug 2004 11:37:03 -0000 1.3 +++ lib/X11/Xlibint.h 28 Feb 2005 15:26:44 -0000 @@ -1254,6 +1254,12 @@ extern int _XOpenFile( int /* flags */ ); +extern int _XOpenFileMode( + _Xconst char* /* path */, + int /* flags */, + mode_t /* mode */ +); + extern void* _XFopenFile( _Xconst char* /* path */, _Xconst char* /* mode */ @@ -1264,6 +1270,7 @@ extern int _XAccessFile( ); #else #define _XOpenFile(path,flags) open(path,flags) +#define _XOpenFileMode(path,flags,mode) open(path,flags,mode) #define _XFopenFile(path,mode) fopen(path,mode) #endif Index: lib/X11/imLcFlt.c =================================================================== RCS file: /cvs/xorg/xc/lib/X11/imLcFlt.c,v retrieving revision 1.2 diff -u -p -r1.2 imLcFlt.c --- lib/X11/imLcFlt.c 31 Aug 2004 11:37:03 -0000 1.2 +++ lib/X11/imLcFlt.c 28 Feb 2005 15:26:46 -0000 @@ -46,31 +46,31 @@ _XimLocalFilter(d, w, ev, client_data) Xic ic = (Xic)client_data; KeySym keysym; static char buf[256]; - DefTree *p; + DefTree *b = ic->private.local.base.tree; + DTIndex t; if( (ev->type != KeyPress) || (ev->xkey.keycode == 0) - || (((Xim)ic->core.im)->private.local.top == (DefTree *)NULL) ) + || (((Xim)ic->core.im)->private.local.top == 0 )) return(False); XLookupString((XKeyEvent *)ev, buf, sizeof(buf), &keysym, NULL); if(IsModifierKey(keysym)) return (False); - - for(p = ic->private.local.context; p; p = p->next) { - if(((ev->xkey.state & p->modifier_mask) == p->modifier) && - (keysym == p->keysym)) { + + for(t = ic->private.local.context; t; t = b[t].next) { + if(((ev->xkey.state & b[t].modifier_mask) == b[t].modifier) && + (keysym == b[t].keysym)) break; - } } - if(p) { /* Matched */ - if(p->succession) { /* Intermediate */ - ic->private.local.context = p->succession; + if(t) { /* Matched */ + if(b[t].succession) { /* Intermediate */ + ic->private.local.context = b[t].succession; return(True); } else { /* Terminate (reached to leaf) */ - ic->private.local.composed = p; + ic->private.local.composed = t; /* return back to client KeyPressEvent keycode == 0 */ ev->xkey.keycode = 0; _XPutBackEvent(d, ev); Index: lib/X11/imLcIc.c =================================================================== RCS file: /cvs/xorg/xc/lib/X11/imLcIc.c,v retrieving revision 1.2 diff -u -p -r1.2 imLcIc.c --- lib/X11/imLcIc.c 23 Apr 2004 18:43:24 -0000 1.2 +++ lib/X11/imLcIc.c 28 Feb 2005 15:26:46 -0000 @@ -94,7 +94,7 @@ _XimLocalReset( XIC xic) { Xic ic = (Xic)xic; - ic->private.local.composed = (DefTree *)NULL; + ic->private.local.composed = 0; ic->private.local.context = ((Xim)ic->core.im)->private.local.top; } @@ -146,8 +146,9 @@ _XimLocalCreateIC( ic->methods = &Local_ic_methods; ic->core.im = im; - ic->private.local.context = ((Xim)im)->private.local.top; - ic->private.local.composed = (DefTree *)NULL; + ic->private.local.base = ((Xim)im)->private.local.base; + ic->private.local.context = ((Xim)ic->core.im)->private.local.top; + ic->private.local.composed = 0; num = im->core.ic_num_resources; len = sizeof(XIMResource) * num; Index: lib/X11/imLcIm.c =================================================================== RCS file: /cvs/xorg/xc/lib/X11/imLcIm.c,v retrieving revision 1.2 diff -u -p -r1.2 imLcIm.c --- lib/X11/imLcIm.c 23 Apr 2004 18:43:24 -0000 1.2 +++ lib/X11/imLcIm.c 28 Feb 2005 15:26:46 -0000 @@ -75,23 +75,29 @@ _XimCheckIfLocalProcessing(im) Private void XimFreeDefaultTree( - DefTree *top) + DefTreeBase *b) { - if (!top) return; - if (top->succession) XimFreeDefaultTree(top->succession); - if (top->next) XimFreeDefaultTree(top->next); - if (top->mb) Xfree(top->mb); - if (top->wc) Xfree(top->wc); - if (top->utf8) Xfree(top->utf8); - Xfree(top); + if (!b) return; + if (b->tree) Xfree (b->tree); + if (b->mb) Xfree (b->mb); + if (b->wc) Xfree (b->wc); + if (b->utf8) Xfree (b->utf8); + b->tree = NULL; + b->mb = NULL; + b->wc = NULL; + b->utf8 = NULL; + b->treeused = b->treesize = 0; + b->mbused = b->mbsize = 0; + b->wcused = b->wcsize = 0; + b->utf8used = b->utf8size = 0; } Public void _XimLocalIMFree( Xim im) { - XimFreeDefaultTree(im->private.local.top); - im->private.local.top = NULL; + XimFreeDefaultTree(&im->private.local.base); + im->private.local.top = 0; if(im->core.im_resources) { Xfree(im->core.im_resources); @@ -324,6 +330,11 @@ _XimLocalOpenIM( goto Open_Error; private->ucstoutf8_conv = conv; + private->base.treeused = 1; + private->base.mbused = 1; + private->base.wcused = 1; + private->base.utf8used = 1; + _XimCreateDefaultTree(im); im->methods = &Xim_im_local_methods; Index: lib/X11/imLcLkup.c =================================================================== RCS file: /cvs/xorg/xc/lib/X11/imLcLkup.c,v retrieving revision 1.2 diff -u -p -r1.2 imLcLkup.c --- lib/X11/imLcLkup.c 23 Apr 2004 18:43:24 -0000 1.2 +++ lib/X11/imLcLkup.c 28 Feb 2005 15:26:46 -0000 @@ -52,19 +52,21 @@ _XimLocalMbLookupString(xic, ev, buffer, { Xic ic = (Xic)xic; int ret; + DefTree *b = ic->private.local.base.tree; + char *mb = ic->private.local.base.mb; if(ev->type != KeyPress) { if(status) *status = XLookupNone; return(0); } - if(ev->keycode == 0 && ic->private.local.composed != NULL) { /* Composed Event */ - ret = strlen(ic->private.local.composed->mb); + if(ev->keycode == 0 && ic->private.local.composed != 0) { /* Composed Event */ + ret = strlen(&mb[b[ic->private.local.composed].mb]); if(ret > bytes) { if(status) *status = XBufferOverflow; return(ret); } - memcpy(buffer, ic->private.local.composed->mb, ret); - if(keysym) *keysym = ic->private.local.composed->ks; + memcpy(buffer, &mb[b[ic->private.local.composed].mb], ret); + if(keysym) *keysym = b[ic->private.local.composed].ks; if (ret > 0) { if (keysym && *keysym != NoSymbol) { if(status) *status = XLookupBoth; @@ -111,20 +113,22 @@ _XimLocalWcLookupString(xic, ev, buffer, { Xic ic = (Xic)xic; int ret; + DefTree *b = ic->private.local.base.tree; + wchar_t *wc = ic->private.local.base.wc; if(ev->type != KeyPress) { if(status) *status = XLookupNone; return(0); } if(ev->keycode == 0) { /* Composed Event */ - ret = _Xwcslen(ic->private.local.composed->wc); + ret = _Xwcslen(&wc[b[ic->private.local.composed].wc]); if(ret > wlen) { if(status) *status = XBufferOverflow; return (ret); } - memcpy((char *)buffer, (char *)ic->private.local.composed->wc, + memcpy((char *)buffer, (char *)&wc[b[ic->private.local.composed].wc], ret * sizeof(wchar_t)); - if(keysym) *keysym = ic->private.local.composed->ks; + if(keysym) *keysym = b[ic->private.local.composed].ks; if (ret > 0) { if (keysym && *keysym != NoSymbol) { if(status) *status = XLookupBoth; @@ -171,19 +175,21 @@ _XimLocalUtf8LookupString(xic, ev, buffe { Xic ic = (Xic)xic; int ret; + DefTree *b = ic->private.local.base.tree; + char *utf8 = ic->private.local.base.utf8; if(ev->type != KeyPress) { if(status) *status = XLookupNone; return(0); } if(ev->keycode == 0) { /* Composed Event */ - ret = strlen(ic->private.local.composed->utf8); + ret = strlen(&utf8[b[ic->private.local.composed].utf8]); if(ret > bytes) { if(status) *status = XBufferOverflow; return (ret); } - memcpy(buffer, ic->private.local.composed->utf8, ret); - if(keysym) *keysym = ic->private.local.composed->ks; + memcpy(buffer, &utf8[b[ic->private.local.composed].utf8], ret); + if(keysym) *keysym = b[ic->private.local.composed].ks; if (ret > 0) { if (keysym && *keysym != NoSymbol) { if(status) *status = XLookupBoth; Index: lib/X11/imLcPrs.c =================================================================== RCS file: /cvs/xorg/xc/lib/X11/imLcPrs.c,v retrieving revision 1.2 diff -u -p -r1.2 imLcPrs.c --- lib/X11/imLcPrs.c 23 Apr 2004 18:43:24 -0000 1.2 +++ lib/X11/imLcPrs.c 28 Feb 2005 15:26:46 -0000 @@ -419,11 +419,13 @@ parseline( char* tokenbuf) { int token; - unsigned modifier_mask; - unsigned modifier; - unsigned tmp; + DTModifier modifier_mask; + DTModifier modifier; + DTModifier tmp; KeySym keysym = NoSymbol; - DefTree **top = &im->private.local.top; + DTIndex *top = &im->private.local.top; + DefTreeBase *b = &im->private.local.base; + DTIndex t; DefTree *p = NULL; Bool exclam, tilde; KeySym rhs_keysym = 0; @@ -435,8 +437,8 @@ parseline( char local_utf8_buf[LOCAL_UTF8_BUFSIZE], *rhs_string_utf8; struct DefBuffer { - unsigned modifier_mask; - unsigned modifier; + DTModifier modifier_mask; + DTModifier modifier; KeySym keysym; }; @@ -533,20 +535,24 @@ parseline( token = nexttoken(fp, tokenbuf, &lastch); if (token == STRING) { - if( (rhs_string_mb = Xmalloc(strlen(tokenbuf) + 1)) == NULL ) - goto error; + l = strlen(tokenbuf) + 1; + while (b->mbused + l > b->mbsize) { + b->mbsize = b->mbsize ? b->mbsize * 1.5 : 1024; + if (! (b->mb = Xrealloc (b->mb, b->mbsize)) ) + goto error; + } + rhs_string_mb = &b->mb[b->mbused]; + b->mbused += l; strcpy(rhs_string_mb, tokenbuf); token = nexttoken(fp, tokenbuf, &lastch); if (token == KEY) { rhs_keysym = XStringToKeysym(tokenbuf); if (rhs_keysym == NoSymbol) { - Xfree(rhs_string_mb); goto error; } token = nexttoken(fp, tokenbuf, &lastch); } if (token != ENDOFLINE && token != ENDOFFILE) { - Xfree(rhs_string_mb); goto error; } } else if (token == KEY) { @@ -560,14 +566,13 @@ parseline( } l = get_mb_string(im, local_mb_buf, rhs_keysym); - if (l == 0) { - rhs_string_mb = Xmalloc(1); - } else { - rhs_string_mb = Xmalloc(l + 1); - } - if( rhs_string_mb == NULL ) { - goto error; + while (b->mbused + l + 1 > b->mbsize) { + b->mbsize = b->mbsize ? b->mbsize * 1.5 : 1024; + if (! (b->mb = Xrealloc (b->mb, b->mbsize)) ) + goto error; } + rhs_string_mb = &b->mb[b->mbused]; + b->mbused += l + 1; memcpy(rhs_string_mb, local_mb_buf, l); rhs_string_mb[l] = '\0'; } else { @@ -578,62 +583,70 @@ parseline( if (l == LOCAL_WC_BUFSIZE - 1) { local_wc_buf[l] = (wchar_t)'\0'; } - if( (rhs_string_wc = (wchar_t *)Xmalloc((l + 1) * sizeof(wchar_t))) == NULL ) { - Xfree( rhs_string_mb ); - return( 0 ); + while (b->wcused + l + 1 > b->wcsize) { + b->wcsize = b->wcsize ? b->wcsize * 1.5 : 512; + if (! (b->wc = Xrealloc (b->wc, sizeof(wchar_t) * b->wcsize)) ) + goto error; } + rhs_string_wc = &b->wc[b->wcused]; + b->wcused += l + 1; memcpy((char *)rhs_string_wc, (char *)local_wc_buf, (l + 1) * sizeof(wchar_t) ); l = _Xmbstoutf8(local_utf8_buf, rhs_string_mb, LOCAL_UTF8_BUFSIZE - 1); if (l == LOCAL_UTF8_BUFSIZE - 1) { local_wc_buf[l] = '\0'; } - if( (rhs_string_utf8 = (char *)Xmalloc(l + 1)) == NULL ) { - Xfree( rhs_string_wc ); - Xfree( rhs_string_mb ); - return( 0 ); + while (b->utf8used + l + 1 > b->utf8size) { + b->utf8size = b->utf8size ? b->utf8size * 1.5 : 1024; + if (! (b->utf8 = Xrealloc (b->utf8, b->utf8size)) ) + goto error; } + rhs_string_utf8 = &b->utf8[b->utf8used]; + b->utf8used += l + 1; memcpy(rhs_string_utf8, local_utf8_buf, l + 1); for (i = 0; i < n; i++) { - for (p = *top; p; p = p->next) { - if (buf[i].keysym == p->keysym && - buf[i].modifier == p->modifier && - buf[i].modifier_mask == p->modifier_mask) { + for (t = *top; t; t = b->tree[t].next) { + if (buf[i].keysym == b->tree[t].keysym && + buf[i].modifier == b->tree[t].modifier && + buf[i].modifier_mask == b->tree[t].modifier_mask) { break; } } - if (p) { + if (t) { + p = &b->tree[t]; top = &p->succession; } else { - if( (p = (DefTree*)Xmalloc(sizeof(DefTree))) == NULL ) { - Xfree( rhs_string_mb ); - goto error; + while (b->treeused >= b->treesize) { + DefTree *old = b->tree; + int oldsize = b->treesize; + b->treesize = b->treesize ? b->treesize * 1.5 : 256; + if (! (b->tree = Xrealloc (b->tree, sizeof(DefTree) * b->treesize)) ) + goto error; + if (top >= (DTIndex *) old && top < (DTIndex *) &old[oldsize]) + top = (DTIndex *) (((char *) top) + (((char *)b->tree)-(char *)old)); } + p = &b->tree[b->treeused]; p->keysym = buf[i].keysym; p->modifier = buf[i].modifier; p->modifier_mask = buf[i].modifier_mask; - p->succession = NULL; + p->succession = 0; p->next = *top; - p->mb = NULL; - p->wc = NULL; - p->utf8 = NULL; + p->mb = 0; + p->wc = 0; + p->utf8 = 0; p->ks = NoSymbol; - *top = p; + *top = b->treeused; top = &p->succession; + b->treeused++; } } - if( p->mb != NULL ) - Xfree( p->mb ); - p->mb = rhs_string_mb; - if( p->wc != NULL ) - Xfree( p->wc ); - p->wc = rhs_string_wc; - if( p->utf8 != NULL ) - Xfree( p->utf8 ); - p->utf8 = rhs_string_utf8; - p->ks = rhs_keysym; + /* old entries no longer freed... */ + p->mb = rhs_string_mb - b->mb; + p->wc = rhs_string_wc - b->wc; + p->utf8 = rhs_string_utf8 - b->utf8; + p->ks = rhs_keysym; return(n); error: while (token != ENDOFLINE && token != ENDOFFILE) { @@ -650,6 +663,7 @@ _XimParseStringFile( char tb[8192]; char* tbp; struct stat st; +/* DefTreeBase *b = &im->private.local.base; */ if (fstat (fileno (fp), &st) != -1) { unsigned long size = (unsigned long) st.st_size; @@ -661,4 +675,6 @@ _XimParseStringFile( if (tbp != tb) free (tbp); } } +/* fprintf (stderr, "-> tree %d mb %d wc %d utf8 %d\n", b->treeused, b->mbused, b->wcused, b->utf8used); */ +/* fprintf (stderr, " allocated tree %d mb %d wc %d utf8 %d\n", b->treesize, b->mbsize, b->wcsize, b->utf8size); */ } Index: lib/X11/imThaiFlt.c =================================================================== RCS file: /cvs/xorg/xc/lib/X11/imThaiFlt.c,v retrieving revision 1.2 diff -u -p -r1.2 imThaiFlt.c --- lib/X11/imThaiFlt.c 23 Apr 2004 18:43:24 -0000 1.2 +++ lib/X11/imThaiFlt.c 28 Feb 2005 15:26:46 -0000 @@ -519,9 +519,9 @@ Private Bool ThaiComposeConvert( * Macros to save and recall last input character in XIC */ #define IC_SavePreviousChar(ic,ch) \ - (*((ic)->private.local.context->mb) = (char) (ch)) + ((ic)->private.local.base.mb[(ic)->private.local.base.tree[(ic)->private.local.context].mb] = (char) (ch)) #define IC_ClearPreviousChar(ic) \ - (*((ic)->private.local.context->mb) = 0) + ((ic)->private.local.base.mb[(ic)->private.local.base.tree[(ic)->private.local.context].mb] = 0) #define IC_GetPreviousChar(ic) \ (IC_RealGetPreviousChar(ic,1)) #define IC_GetContextChar(ic) \ @@ -533,6 +533,7 @@ Private unsigned char IC_RealGetPreviousChar(Xic ic, unsigned short pos) { XICCallback* cb = &ic->core.string_conversion_callback; + DefTreeBase *b = &ic->private.local.base; if (cb && cb->callback) { XIMStringConversionCallbackStruct screc; @@ -549,7 +550,7 @@ IC_RealGetPreviousChar(Xic ic, unsigned (cb->callback)((XIC)ic, cb->client_data, (XPointer)&screc); if (!screc.text) - return (unsigned char) *((ic)->private.local.context->mb); + return (unsigned char) b->mb[b->tree[(ic)->private.local.context].mb]; if ((screc.text->feedback && *screc.text->feedback == XIMStringConversionLeftEdge) || screc.text->length < 1) @@ -567,7 +568,7 @@ IC_RealGetPreviousChar(Xic ic, unsigned XFree(screc.text); return c; } else { - return (unsigned char) *((ic)->private.local.context->mb); + return (unsigned char) b->mb[b->tree[(ic)->private.local.context].mb]; } } @@ -1190,13 +1191,14 @@ Private void InitIscMode(Xic ic) Private Bool ThaiFltAcceptInput(Xic ic, unsigned char new_char, KeySym symbol) { - ic->private.local.composed->wc[0] = tis2ucs(new_char); - ic->private.local.composed->wc[1] = '\0'; + DefTreeBase *b = &ic->private.local.base; + b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char); + b->wc[b->tree[ic->private.local.composed].wc+1] = '\0'; if ((new_char <= 0x1f) || (new_char == 0x7f)) - ic->private.local.composed->keysym = symbol; + b->tree[ic->private.local.composed].keysym = symbol; else - ic->private.local.composed->keysym = NoSymbol; + b->tree[ic->private.local.composed].keysym = NoSymbol; return True; } @@ -1204,12 +1206,13 @@ ThaiFltAcceptInput(Xic ic, unsigned char Private Bool ThaiFltReorderInput(Xic ic, unsigned char previous_char, unsigned char new_char) { + DefTreeBase *b = &ic->private.local.base; if (!IC_DeletePreviousChar(ic)) return False; - ic->private.local.composed->wc[0] = tis2ucs(new_char); - ic->private.local.composed->wc[1] = tis2ucs(previous_char); - ic->private.local.composed->wc[2] = '\0'; + b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char); + b->wc[b->tree[ic->private.local.composed].wc+1] = tis2ucs(previous_char); + b->wc[b->tree[ic->private.local.composed].wc+2] = '\0'; - ic->private.local.composed->keysym = NoSymbol; + b->tree[ic->private.local.composed].keysym = NoSymbol; return True; } @@ -1217,14 +1220,15 @@ ThaiFltReorderInput(Xic ic, unsigned cha Private Bool ThaiFltReplaceInput(Xic ic, unsigned char new_char, KeySym symbol) { + DefTreeBase *b = &ic->private.local.base; if (!IC_DeletePreviousChar(ic)) return False; - ic->private.local.composed->wc[0] = tis2ucs(new_char); - ic->private.local.composed->wc[1] = '\0'; + b->wc[b->tree[ic->private.local.composed].wc+0] = tis2ucs(new_char); + b->wc[b->tree[ic->private.local.composed].wc+1] = '\0'; if ((new_char <= 0x1f) || (new_char == 0x7f)) - ic->private.local.composed->keysym = symbol; + b->tree[ic->private.local.composed].keysym = symbol; else - ic->private.local.composed->keysym = NoSymbol; + b->tree[ic->private.local.composed].keysym = NoSymbol; return True; } @@ -1253,6 +1257,7 @@ XPointer client_data; #endif wchar_t wbuf[10]; Bool isReject; + DefTreeBase *b = &ic->private.local.base; if ((ev->type != KeyPress) || (ev->xkey.keycode == 0)) @@ -1355,11 +1360,11 @@ XPointer client_data; return True; } - _Xlcwcstombs(ic->core.im->core.lcd, ic->private.local.composed->mb, - ic->private.local.composed->wc, 10); + _Xlcwcstombs(ic->core.im->core.lcd, &b->mb[b->tree[ic->private.local.composed].mb], + &b->wc[b->tree[ic->private.local.composed].wc], 10); - _Xlcmbstoutf8(ic->core.im->core.lcd, ic->private.local.composed->utf8, - ic->private.local.composed->mb, 10); + _Xlcmbstoutf8(ic->core.im->core.lcd, &b->utf8[b->tree[ic->private.local.composed].utf8], + &b->mb[b->tree[ic->private.local.composed].mb], 10); /* Remember the last character inputted * (as fallback in case StringConversionCallback is not provided) Index: lib/X11/imThaiIc.c =================================================================== RCS file: /cvs/xorg/xc/lib/X11/imThaiIc.c,v retrieving revision 1.2 diff -u -p -r1.2 imThaiIc.c --- lib/X11/imThaiIc.c 23 Apr 2004 18:43:24 -0000 1.2 +++ lib/X11/imThaiIc.c 28 Feb 2005 15:26:46 -0000 @@ -59,6 +59,8 @@ _XimThaiDestroyIC( XIC xic) { Xic ic = (Xic)xic; + DefTreeBase *b = &ic->private.local.base; + if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) { _XimThaiUnSetFocus(xic); } @@ -67,14 +69,14 @@ _XimThaiDestroyIC( ic->private.local.ic_resources = NULL; } - Xfree(ic->private.local.context->mb); - Xfree(ic->private.local.context->wc); - Xfree(ic->private.local.context->utf8); - Xfree(ic->private.local.context); - Xfree(ic->private.local.composed->mb); - Xfree(ic->private.local.composed->wc); - Xfree(ic->private.local.composed->utf8); - Xfree(ic->private.local.composed); + if (b->tree) Xfree (b->tree); + if (b->mb) Xfree (b->mb); + if (b->wc) Xfree (b->wc); + if (b->utf8) Xfree (b->utf8); + b->tree = NULL; + b->mb = NULL; + b->wc = NULL; + b->utf8 = NULL; return; } @@ -104,11 +106,12 @@ _XimThaiReset( XIC xic) { Xic ic = (Xic)xic; + DefTreeBase *b = &ic->private.local.base; ic->private.local.thai.comp_state = 0; ic->private.local.thai.keysym = 0; - ic->private.local.composed->mb[0] = '\0'; - ic->private.local.composed->wc[0] = 0; - ic->private.local.composed->utf8[0] = '\0'; + b->mb[b->tree[ic->private.local.composed].mb] = '\0'; + b->wc[b->tree[ic->private.local.composed].wc] = '\0'; + b->utf8[b->tree[ic->private.local.composed].utf8] = '\0'; } Private char * @@ -151,6 +154,7 @@ _XimThaiCreateIC( XIMResourceList res; unsigned int num; int len; + DefTree *tree; if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) { return ((XIC)NULL); @@ -160,30 +164,23 @@ _XimThaiCreateIC( ic->methods = &Thai_ic_methods; ic->core.im = im; ic->core.filter_events = KeyPressMask; - if ((ic->private.local.context = (DefTree *)Xmalloc(sizeof(DefTree))) - == (DefTree *)NULL) - goto Set_Error; - if ((ic->private.local.context->mb = (char *)Xmalloc(10)) - == (char *)NULL) - goto Set_Error; - if ((ic->private.local.context->wc = (wchar_t *)Xmalloc(10*sizeof(wchar_t))) - == (wchar_t *)NULL) - goto Set_Error; - if ((ic->private.local.context->utf8 = (char *)Xmalloc(10)) - == (char *)NULL) - goto Set_Error; - if ((ic->private.local.composed = (DefTree *)Xmalloc(sizeof(DefTree))) - == (DefTree *)NULL) + + if (! (ic->private.local.base.tree = tree = (DefTree *)Xmalloc(sizeof(DefTree)*3)) ) goto Set_Error; - if ((ic->private.local.composed->mb = (char *)Xmalloc(10)) - == (char *)NULL) + if (! (ic->private.local.base.mb = (char *)Xmalloc(21)) ) goto Set_Error; - if ((ic->private.local.composed->wc = (wchar_t *)Xmalloc(10*sizeof(wchar_t))) - == (wchar_t *)NULL) + if (! (ic->private.local.base.wc = (wchar_t*)Xmalloc(sizeof(wchar_t)*21)) ) goto Set_Error; - if ((ic->private.local.composed->utf8 = (char *)Xmalloc(10)) - == (char *)NULL) + if (! (ic->private.local.base.utf8 = (char *)Xmalloc(21)) ) goto Set_Error; + ic->private.local.context = 1; + tree[1].mb = 1; + tree[1].wc = 1; + tree[1].utf8 = 1; + ic->private.local.composed = 2; + tree[2].mb = 11; + tree[2].wc = 11; + tree[2].utf8 = 11; ic->private.local.thai.comp_state = 0; ic->private.local.thai.keysym = 0;