I was thinking the same thing. The __atoe function must be making a copy of
the string and sticking it in the msg variable, and the strcpy is operating
on that.

Joe

On Mon, Oct 7, 2024 at 12:29 PM Colin Paice <
[email protected]> wrote:

> ...  mark 2 answer.
> Perhaps const char* msg=(*env)->GetStringUTFChars(env,jParm,0);     returns
> a copy of the string.  So it can be released immediately.
> The __atoe((char*) msg);  works on the copy.
>
> On Mon, 7 Oct 2024 at 18:07, Eric Erickson <[email protected]> wrote:
>
> > I have not done any serious JNI work in about 20+ years and it was on
> > another platform (OS/2) rather than z/OS. But I've inherited some code
> and
> > I noticed something that I don't think is right, but would like to get a
> > confirmation from anyone with more experience. This is a code fragment as
> > written.
> >
> >  /* --- Get the parm input, and convert to EBCDIC  ---- */
> >
> >  const char* msg=(*env)->GetStringUTFChars(env,jParm,0);
> >
> >  /*
> >
> >  **  Convert string to EBCDIC
> >
> >  */
> >
> >  __atoe((char*) msg);
> >
> >  /*
> >
> >  **  Release the passed string
> >
> >  */
> >
> >  (*env)->ReleaseStringUTFChars(env, jParm, msg);
> >
> >
> >  /* --- Setup 1K Area to pass (leave space for NULL)    */
> >
> >  passarea = malloc(1024);           /* Get area        */
> >
> >  memset(passarea, 0, 1024);         /* Clear area      */
> >
> >  strcpy(passarea,msg);              /* Put parm in     */
> >
> > Based on what I've read about the GetStringxxxx and ReleaseStringxxx I
> > believe that the ReleaseStringxxx should be placed AFTER the strcpy of
> the
> > msg into the passarea. The documentation says to call the ReleastString
> > once you are done using the string.
> >
> > That leads me to believe that the code fragment should look like the
> > following.
> >
> > /* --- Get the parm input, and convert to EBCDIC  ---- */
> >
> >  const char* msg=(*env)->GetStringUTFChars(env,jParm,0);
> >
> >  /*
> >
> >  **  Convert string to EBCDIC
> >
> >  */
> >
> >  __atoe((char*) msg);
> >
> >
> >  /* --- Setup 1K Area to pass (leave space for NULL)    */
> >
> >  passarea = malloc(1024);           /* Get area        */
> >
> >  memset(passarea, 0, 1024);         /* Clear area      */
> >
> >  strcpy(passarea,msg);              /* Put parm in     */
> >
> >  /*
> >
> >  **  Release the passed string
> >
> >  */
> >
> >  (*env)->ReleaseStringUTFChars(env, jParm, msg);
> >
> > I'm really surprised that this code does not abend or toss some kind of
> > error, if the string is getting marked as released before we are done
> with
> > it. I suppose it could be related to when the JVM actually runs the
> garbage
> > collection that recovers the storage, but to my mind this is an error
> just
> > waiting to happen.
> >
> > Am I right? If not can someone provide clarification as to why the
> > original form is correct?
> >
> > ----------------------------------------------------------------------
> > For IBM-MAIN subscribe / signoff / archive access instructions,
> > send email to [email protected] with the message: INFO IBM-MAIN
> >
>
> ----------------------------------------------------------------------
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to [email protected] with the message: INFO IBM-MAIN
>

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to