[comp.windows.x.motif] _XmCharsetCanonicalize

monica@nereid.jpl.nasa.gov (Monica Rivera) (03/26/91)

	I am using Douglas Young's xs_str_array_to_xmstr function
(from The X Window System, Douglas Young, Prentice Hall, 1990, p. 237)
and it works great in motif 1.1, but I've been getting a core dump
at the following call when using motif 1.1.1:

     xmstr = XmStringConcat(xmstr, 
    		            XmStringCreate(cs[i],
                            XmSTRING_DEFAULT_CHARSET)
                           );

	This is where dbx says it bombs:


program terminated by signal SEGV (no mapping at the fault address)
(dbx) where
strlen() at 0xdd668
_isISO() at 0x7f5e0
_XmCharsetCanonicalize() at 0x7f55c
XmStringCreate() at 0x7bdec
xs_str_array_to_xmstr(cs = 0x137fb8, n = 38), line 104 in "xallbc2_cb.c"
my_help(w = 0x179100, file_name = 0xfc3af "xallbc2.hlp"), line 170 in "xallbc2_c
b.c"
help_fcn(w = 0x1fc288, str = 0x11e341 "", callData = 0xf7fff444 ""), line 428 in
 "xallbc2_cb.c"
_XtCallCallbacks() at 0xa1748
XtCallCallbackList() at 0xa199c
`PushB`ActivateCommon() at 0x3909c
`PushB`Activate() at 0x38ecc
_XtTranslateEvent() at 0xc0044
DispatchEvent() at 0xa9a78
DecideToDispatch() at 0xaa154
XtDispatchEvent() at 0xaa200
XtAppMainLoop() at 0xaa500
XtMainLoop() at 0xaa4e0
main(argc = 1, argv = 0xf7fffc34, envp = 0xf7fffc3c), line 173 in "xallbc2.c"
(dbx)


	Is there a way around this problem?


-- 
    -     ------       -                              Monica Rivera
   | |   | ----  \    | |                             ms T-1704H
   | |   | |   \ |    | |                             4800 Oak Grove Drive
   | |   | | --  |    | |                             Pasadena, CA 91109
---| |   | | \__/     | |___                          monica@triton.jpl.nasa.gov
\____|et |_|ropulsion |_____\aboratory                (818) 354-0512

hildjj@MODAL375.ME.VT.EDU (Joe Hildebrand) (03/26/91)

>         I am using Douglas Young's xs_str_array_to_xmstr function
> (from The X Window System, Douglas Young, Prentice Hall, 1990, p. 237)
> and it works great in motif 1.1, but I've been getting a core dump
> at the following call when using motif 1.1.1:

>      xmstr = XmStringConcat(xmstr, 
>                             XmStringCreate(cs[i],
>                             XmSTRING_DEFAULT_CHARSET)
>                            );

Maybe there is some reason why you really want to use this function, but an
equivalent one (i think) is:

XmString XmS(strig)
   char *strig;
{
   return(XmStringLtoRCreate(strig, XmSTRING_DEFAULT_CHARSET));
}

Where you just put a '\n' into your string whenever you want a new line.
-joe
_      ________
\\    //------
 \\  //   ||     All opinions are my own,
  \\//    ||     -rw-r--r--   1 hildjj   users     2048 Mar 215 08:59 opinions
   --     
Joe Hildebrand  [hildjj@modal375.me.vt.edu (128.173.5.186)]
Virginia Tech Department of Mechanical Engineering
Blacksburg, VA
and
Babcock & Wilcox Nuclear Services, Lynchburg, VA
(804)847-3953

jr@twisted.dkw.com (J.R. Jesson) (03/28/91)

In article <6139@mahendo.Jpl.Nasa.Gov>, monica@nereid.jpl.nasa.gov (Monica Rivera) writes:
|> 
|> 	I am using Douglas Young's xs_str_array_to_xmstr function
|> (from The X Window System, Douglas Young, Prentice Hall, 1990, p. 237)
|> and it works great in motif 1.1, but I've been getting a core dump
|> at the following call when using motif 1.1.1:
|> 
|>      xmstr = XmStringConcat(xmstr, 
|>     		            XmStringCreate(cs[i],
|>                             XmSTRING_DEFAULT_CHARSET)
|>                            );
|> 
|> 	This is where dbx says it bombs:
*Beautiful* dbx stuff deleted

I'm not sure what is causing your dump, but be aware that you _are_
creating a memory leak with that call.  In particular, the docs for
XmStringCreate say that it creates a new compound string, leaving the 
two calling args intact.  So, by doing the XmStringCreate in-line, and
assigning the result of the call to xmstr you are inadvertently allocating
memory that you cant free.  Here is a safer way do do the call:

  XmString a, b, xmstr;

  a = XmStringCreate(cs[i], XmSTRING_DEFAULT_CHARSET);
  b = xmstr;
  xmstr = XmStringConcat(a,b);
  XtFree(a);
  XtFree(b);
---
Hope this helps,

J.R. Jesson
"The Unix Guy is always the last to know"

nazgul@alfalfa.com (Kee Hinckley) (03/28/91)

>   XmString a, b, xmstr;
> 
>   a = XmStringCreate(cs[i], XmSTRING_DEFAULT_CHARSET);
>   b = xmstr;
>   xmstr = XmStringConcat(a,b);
>   XtFree(a);
>   XtFree(b);
Better make that XmStringFree instead of XtFree or you may have
leaks of your own :-).

Alfalfa Software, Inc.          |       Poste:  The EMail for Unix
nazgul@alfalfa.com              |       Send Anything... Anywhere
617/646-7703 (voice/fax)        |       info@alfalfa.com

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.