Posted to tcl by GPS at Fri Jun 06 21:09:54 GMT 2008view raw

  1. + Status status = XBufferOverflow;
  2. +
  3. + while (status == XBufferOverflow) {
  4. + len = Xutf8LookupString(winPtr->inputContext, &eventPtr->xkey,
  5. + Tcl_DStringValue(dsPtr), len, NULL, &status);
  6. + Tcl_DStringSetLength(dsPtr, len);
  7. + }
  8.  
  9. This is from libX11-1.1.3/src/xlibi18n/ICWrap.c:
  10. Xutf8LookupString(..) {
  11. if (ic->core.im) {
  12. if (ic->methods->utf8_lookup_string)
  13. return (*ic->methods->utf8_lookup_string) (ic, ev, buffer, nbytes,
  14. keysym, status);
  15. else if (ic->methods->mb_lookup_string)
  16. return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
  17. keysym, status);
  18. }
  19. return XLookupNone;
  20. }
  21.  
  22. I'm guessing it's unlikely for ic->core.im to be false, but it might be good to be protective. The way the while loop is coded, the XBufferOverflow state would continue forever. One problem is: Xlib.h:#define XLookupNone 1
  23.  
  24. So it's somewhat error prone. The return would be 1, which is interpretted as a length, and the XBufferOverflow state continues. Unless I'm missing something this seems off. Perhaps one way around it is to initialize the status to something other than XBufferOverflow, perhaps 0 or -1, assuming the XBufferOverflow-like macros don't use those values.
  25.