Is gp_exit() used at exit in current gnuplot?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Is gp_exit() used at exit in current gnuplot?

tmacchant
This is related to bug #1913.

In stdfn.c

there stated


/* Calls the cleanup functions registered using gp_atexit().
 * Normally gnuplot should be exited using gp_exit(). In some cases, this is not
 * possible (notably when returning from main(), where some compilers get
 * confused because they expect a return statement at the very end. In that
 * case, gp_exit_cleanup() should be called before the return statement.
 */


*****************************

Normally gnuplot should be exited using gp_exit().
***************************


However, quick test by gdb

gdb gnuplot
b gp_exit_cleanup
b gp_exit
b debug_exit_handler
r

At gnuplot prompt

gnuplot> exit

gdb tells that gnuplot does not end by gp_exit but by debug_exit_handler.
by exit command value of exit_handlers


On  cygwin

Breakpoint 1, gp_exit_cleanup () at ../../gnuplot/src/stdfn.c:440
440     {
(gdb) n
[New Thread 8120.0x26b8]
447         while (exit_handlers) {
(gdb) n
449             (*handler->function)();
(gdb) n
[New Thread 8120.0x27cc]
451             exit_handlers = handler->next;
(gdb) n
452             free(handler);
(gdb) n
451             exit_handlers = handler->next;
(gdb) n
452             free(handler);
(gdb) n
447         while (exit_handlers) {
(gdb) n
449             (*handler->function)();
(gdb) n
451             exit_handlers = handler->next;
(gdb) n
452             free(handler);
(gdb) n
451             exit_handlers = handler->next;
(gdb) n
452             free(handler);
(gdb) n
447         while (exit_handlers) {
(gdb) n
454     }
(gdb) n
main (argc=<optimized out>, argv=<optimized out>)
    at ../../gnuplot/src/plot.c:694
694         return exit_status;
(gdb) n
695     }
(gdb) n
0x61007acf in cygwin_exit_return () from /usr/bin/cygwin1.dll
(gdb) c
Continuing.

Breakpoint 3, debug_exit_handler () at ../../gnuplot/src/stdfn.c:461
461         if (exit_handlers) {
(gdb) p exit_handlers
$1 = (struct EXIT_HANDLER *) 0x0
(gdb) c
Continuing.
[Thread 8120.0x1708 exited with code 0]
[Thread 8120.0x26b8 exited with code 0]
[Thread 8120.0x1094 exited with code 0]
[Thread 8120.0x27cc exited with code 0]
[Thread 8120.0x22c8 exited with code 0]
[Inferior 1 (process 8120) exited normally]


The above also happens on lubuntu.

Similar behavior is observed on windows


Entering exit command
gp_exit_cleanup () is called in main in plot.c on Cygwin and lubuntu.
gp_exit_cleanup () is called in WinMain (wgnuplot) or main (gnuplot) in wimmain.c on windows.


Even exit command, gp_exit() seems not to be used.

Is

*****************************

Normally gnuplot should be exited using gp_exit().
***************************

true at present ?

Tatsuro


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: Is gp_exit() used at exit in current gnuplot?

tmacchant
----- Original Message -----

> From: Tatsuro MATSUOKA
> To: [hidden email]
> Cc:
> Date: 2017/2/28, Tue 10:38
> Subject: Is gp_exit() used at exit in current gnuplot?
>
>T his is related to bug #1913.
>
> In stdfn.c
>
> there stated
>
>
> /* Calls the cleanup functions registered using gp_atexit().
>  * Normally gnuplot should be exited using gp_exit(). In some cases, this is not
>  * possible (notably when returning from main(), where some compilers get
>  * confused because they expect a return statement at the very end. In that
>  * case, gp_exit_cleanup() should be called before the return statement.
>  */
>
>
> *****************************
>
> Normally gnuplot should be exited using gp_exit().
> ***************************
>
>
> However, quick test by gdb
>
> gdb gnuplot
> b gp_exit_cleanup
> b gp_exit
> b debug_exit_handler
> r
>
> At gnuplot prompt
>
> gnuplot> exit
>
> gdb tells that gnuplot does not end by gp_exit but by debug_exit_handler.
> by exit command value of exit_handlers
>
>
> On  cygwin
>
> Breakpoint 1, gp_exit_cleanup () at ../../gnuplot/src/stdfn.c:440
> 440     {
> (gdb) n
> [New Thread 8120.0x26b8]
> 447         while (exit_handlers) {
> (gdb) n
> 449             (*handler->function)();
> (gdb) n
> [New Thread 8120.0x27cc]
> 451             exit_handlers = handler->next;
> (gdb) n
> 452             free(handler);
> (gdb) n
> 451             exit_handlers = handler->next;
> (gdb) n
> 452             free(handler);
> (gdb) n
> 447         while (exit_handlers) {
> (gdb) n
> 449             (*handler->function)();
> (gdb) n
> 451             exit_handlers = handler->next;
> (gdb) n
> 452             free(handler);
> (gdb) n
> 451             exit_handlers = handler->next;
> (gdb) n
> 452             free(handler);
> (gdb) n
> 447         while (exit_handlers) {
> (gdb) n
> 454     }
> (gdb) n
> main (argc=<optimized out>, argv=<optimized out>)
>     at ../../gnuplot/src/plot.c:694
> 694         return exit_status;
> (gdb) n
> 695     }
> (gdb) n
> 0x61007acf in cygwin_exit_return () from /usr/bin/cygwin1.dll
> (gdb) c
> Continuing.
>
> Breakpoint 3, debug_exit_handler () at ../../gnuplot/src/stdfn.c:461
> 461         if (exit_handlers) {
> (gdb) p exit_handlers
> $1 = (struct EXIT_HANDLER *) 0x0
> (gdb) c
> Continuing.
> [Thread 8120.0x1708 exited with code 0]
> [Thread 8120.0x26b8 exited with code 0]
> [Thread 8120.0x1094 exited with code 0]
> [Thread 8120.0x27cc exited with code 0]
> [Thread 8120.0x22c8 exited with code 0]
> [Inferior 1 (process 8120) exited normally]
>
>
> The above also happens on lubuntu.
>
> Similar behavior is observed on windows
>
>
> Entering exit command
> gp_exit_cleanup () is called in main in plot.c on Cygwin and lubuntu.
> gp_exit_cleanup () is called in WinMain (wgnuplot) or main (gnuplot) in
> wimmain.c on windows.
>
>
> Even exit command, gp_exit() seems not to be used.
>
> Is
>
> *****************************
>
> Normally gnuplot should be exited using gp_exit().
> ***************************
>
> true at present ?
>
> Tatsuro
>

Excuse me for my writing without reading the code in detail.
gp_exit() seems to be used in many place in the code.
Therefore gp_exit() is surely used in current gnuplot.
However, "gnuplot> exit" does not use gp_exit() as written in the previous post.

I feel that the message
 
Gnuplot not exited using gp_exit(). Exit handlers may not work correctly!

in debug_exit_handler in stdfn.c is better to be modified.

Tatsuro

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: Is gp_exit() used at exit in current gnuplot?

sfeam
In reply to this post by tmacchant
On Tuesday, 28 February 2017 10:38:04 AM Tatsuro MATSUOKA wrote:

> This is related to bug #1913.
>
> In stdfn.c
>
> there stated
>
>
> /* Calls the cleanup functions registered using gp_atexit().
>  * Normally gnuplot should be exited using gp_exit(). In some cases, this is not
>  * possible (notably when returning from main(), where some compilers get
>  * confused because they expect a return statement at the very end. In that
>  * case, gp_exit_cleanup() should be called before the return statement.
>  */
>
>
> *****************************
> Normally gnuplot should be exited using gp_exit().
> ***************************

I think the intended meaning is
"If you were going to terminate the program by calling exit(), don't do that.
Instead call gp_exit()."  

However the normal exit from main() in a C language program is by "return", not "exit()".
So gnuplot's main() routine does not  call either exit() or gp_exit().  Instead it calls
gp_exit_cleanup() followed by "return".
Thus it does exactly what the comment describes.  

> Excuse me for my writing without reading the code in detail.
> gp_exit() seems to be used in many place in the code.
> Therefore gp_exit() is surely used in current gnuplot.

Yes.  For example If you say
gnuplot>  exit gnuplot
then it calls gp_exit().

> However, "gnuplot> exit" does not use gp_exit() as written in the
> previous post.
>
> I feel that the message
>
> Gnuplot not exited using gp_exit(). Exit handlers may not work correctly!
>
> in debug_exit_handler in stdfn.c is better to be modified.

I think you are correct that the message is not accurate.
It would be better to say
"Gnuplot not exiting normally. Exit handlers may not work correctly!"
gp_exit() is one way of exiting normally, but exiting by return from main()
is also a way of exiting normally.

In your case (Bug 1913) I guess neither of these normal ways to exit is happening.
Instead gnuplot is killed by the operating system because you hit  the "X button".

        Ethan





 
> Tatsuro

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: Is gp_exit() used at exit in current gnuplot?

tmacchant
----- Original Message -----

> From: sfeam
> To: gnuplot-beta Tatsuro MATSUOKA
> Cc:
> Date: 2017/2/28, Tue 13:51
> Subject: Re: Is gp_exit() used at exit in current gnuplot?
>
> On Tuesday, 28 February 2017 10:38:04 AM Tatsuro MATSUOKA wrote:
>>  This is related to bug #1913.
>>
>>  In stdfn.c
>>
>>  there stated
>>
>>
>>  /* Calls the cleanup functions registered using gp_atexit().
>>   * Normally gnuplot should be exited using gp_exit(). In some cases, this
> is not
>>   * possible (notably when returning from main(), where some compilers get
>>   * confused because they expect a return statement at the very end. In that
>>   * case, gp_exit_cleanup() should be called before the return statement.
>>   */
>>
>>
>>  *****************************
>>  Normally gnuplot should be exited using gp_exit().
>>  ***************************
>
> I think the intended meaning is
> "If you were going to terminate the program by calling exit(), don't do
> that.
> Instead call gp_exit()." 
>
> However the normal exit from main() in a C language program is by
> "return", not "exit()".
> So gnuplot's main() routine does not  call either exit() or gp_exit(). 
> Instead it calls
> gp_exit_cleanup() followed by "return".
> Thus it does exactly what the comment describes. 
>
>>  Excuse me for my writing without reading the code in detail.
>>  gp_exit() seems to be used in many place in the code.
>>  Therefore gp_exit() is surely used in current gnuplot.
>
> Yes.  For example If you say
> gnuplot>  exit gnuplot
> then it calls gp_exit().
>
>>  However, "gnuplot> exit" does not use gp_exit() as written in
> the
>>  previous post.
>>
>>  I feel that the message
>>
>>  Gnuplot not exited using gp_exit(). Exit handlers may not work correctly!
>>
>>  in debug_exit_handler in stdfn.c is better to be modified.
>
> I think you are correct that the message is not accurate.
> It would be better to say
> "Gnuplot not exiting normally. Exit handlers may not work correctly!"
> gp_exit() is one way of exiting normally, but exiting by return from main()
> is also a way of exiting normally.
>
> In your case (Bug 1913) I guess neither of these normal ways to exit is
> happening.
> Instead gnuplot is killed by the operating system because you hit  the "X
> button".
>
>     Ethan
>
>
>
Thank you for your comprehensive explanation.
I hope that message  in debug_exit_handler will be modified as you indicaded

"Gnuplot not exiting normally. Exit handlers may not work correctly!"

Tatsuro


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: Is gp_exit() used at exit in current gnuplot?

sfeam
On Tuesday, 28 February 2017 02:57:46 PM Tatsuro MATSUOKA wrote:

> ----- Original Message -----
>
> > From: sfeam
> > To: gnuplot-beta Tatsuro MATSUOKA
> > Cc:
> > Date: 2017/2/28, Tue 13:51
> > Subject: Re: Is gp_exit() used at exit in current gnuplot?
> >
> > On Tuesday, 28 February 2017 10:38:04 AM Tatsuro MATSUOKA wrote:
> >>  This is related to bug #1913.
> >>
> >>  In stdfn.c
> >>
> >>  there stated
> >>
> >>
> >>  /* Calls the cleanup functions registered using gp_atexit().
> >>   * Normally gnuplot should be exited using gp_exit(). In some cases, this
> > is not
> >>   * possible (notably when returning from main(), where some compilers get
> >>   * confused because they expect a return statement at the very end. In that
> >>   * case, gp_exit_cleanup() should be called before the return statement.
> >>   */
> >>
> >>
> >>  *****************************
> >>  Normally gnuplot should be exited using gp_exit().
> >>  ***************************
> >
> > I think the intended meaning is
> > "If you were going to terminate the program by calling exit(), don't do
> > that.
> > Instead call gp_exit()."  
> >
> > However the normal exit from main() in a C language program is by
> > "return", not "exit()".
> > So gnuplot's main() routine does not  call either exit() or gp_exit().  
> > Instead it calls
> > gp_exit_cleanup() followed by "return".
> > Thus it does exactly what the comment describes.  
> >
> >>  Excuse me for my writing without reading the code in detail.
> >>  gp_exit() seems to be used in many place in the code.
> >>  Therefore gp_exit() is surely used in current gnuplot.
> >
> > Yes.  For example If you say
> > gnuplot>  exit gnuplot
> > then it calls gp_exit().
> >
> >>  However, "gnuplot> exit" does not use gp_exit() as written in
> > the
> >>  previous post.
> >>
> >>  I feel that the message
> >>
> >>  Gnuplot not exited using gp_exit(). Exit handlers may not work correctly!
> >>
> >>  in debug_exit_handler in stdfn.c is better to be modified.
> >
> > I think you are correct that the message is not accurate.
> > It would be better to say
> > "Gnuplot not exiting normally. Exit handlers may not work correctly!"
> > gp_exit() is one way of exiting normally, but exiting by return from main()
> > is also a way of exiting normally.
> >
> > In your case (Bug 1913) I guess neither of these normal ways to exit is
> > happening.
> > Instead gnuplot is killed by the operating system because you hit  the "X
> > button".
> >
> >     Ethan
> >
> >
> >
> Thank you for your comprehensive explanation.
> I hope that message  in debug_exit_handler will be modified as you indicaded
>
> "Gnuplot not exiting normally. Exit handlers may not work correctly!"


OK.  It now says:
    "Gnuplot exiting abnormally. Trying to execute exit handlers anyway."

So far as I can see, the only purpose of this message is to help debug
the exit sequence, like you are doing with Bug 1913.

        Ethan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
Reply | Threaded
Open this post in threaded view
|

Re: Is gp_exit() used at exit in current gnuplot?

tmacchant
----- Original Message -----

> From: sfeam
> To: gnuplot-beta Tatsuro MATSUOKA
> Cc:
> Date: 2017/2/28, Tue 15:54
> Subject: Re: Is gp_exit() used at exit in current gnuplot?
>
>>  Thank you for your comprehensive explanation.
>>  I hope that message  in debug_exit_handler will be modified as you
> indicaded
>>
>>  "Gnuplot not exiting normally. Exit handlers may not work
> correctly!"
>
>
> OK.  It now says:
>     "Gnuplot exiting abnormally. Trying to execute exit handlers
> anyway."
>
> So far as I can see, the only purpose of this message is to help debug
> the exit sequence, like you are doing with Bug 1913.
>
>     Ethan
>

I have confirmed the change of message.

Thanks!

Tatsuro


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
gnuplot-beta mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta