From eca400e95383b19f48484ad46144341c11d58b02 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 1 Jun 2021 10:29:54 +0100 Subject: [PATCH] don't set g_set_prgname() this should be set in the app layer, not by libraries --- libvips/include/vips/vips.h | 2 +- libvips/iofuncs/error.c | 2 +- libvips/iofuncs/image.c | 6 +++--- libvips/iofuncs/init.c | 37 ++++++++++++++++++++++++++++--------- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/libvips/include/vips/vips.h b/libvips/include/vips/vips.h index efb5bc1f..a1624261 100644 --- a/libvips/include/vips/vips.h +++ b/libvips/include/vips/vips.h @@ -170,8 +170,8 @@ extern "C" { vips_init( ARGV0 )) int vips_init( const char *argv0 ); - const char *vips_get_argv0( void ); +const char *vips_get_prgname( void ); void vips_shutdown( void ); void vips_thread_shutdown( void ); diff --git a/libvips/iofuncs/error.c b/libvips/iofuncs/error.c index 7125396a..86154bae 100644 --- a/libvips/iofuncs/error.c +++ b/libvips/iofuncs/error.c @@ -430,7 +430,7 @@ vips_error_exit( const char *fmt, ... ) if( fmt ) { va_list ap; - fprintf( stderr, "%s: ", g_get_prgname() ); + fprintf( stderr, "%s: ", vips_get_prgname() ); va_start( ap, fmt ); (void) vfprintf( stderr, fmt, ap ); diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index e34744ac..93cec059 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -760,7 +760,7 @@ vips_image_preeval_cb( VipsImage *image, VipsProgress *progress, int *last ) &tile_width, &tile_height, &n_lines ); printf( _( "%s %s: %d x %d pixels, %d threads, %d x %d tiles, " "%d lines in buffer" ), - g_get_prgname(), image->filename, + vips_get_prgname(), image->filename, image->Xsize, image->Ysize, vips_concurrency_get(), tile_width, tile_height, n_lines ); @@ -772,7 +772,7 @@ vips_image_eval_cb( VipsImage *image, VipsProgress *progress, int *last ) { if( progress->percent != *last ) { printf( _( "%s %s: %d%% complete" ), - g_get_prgname(), image->filename, + vips_get_prgname(), image->filename, progress->percent ); printf( "\r" ); fflush( stdout ); @@ -791,7 +791,7 @@ vips_image_posteval_cb( VipsImage *image, VipsProgress *progress, void *data ) /* Spaces at end help to erase the %complete message we overwrite. */ printf( _( "%s %s: done in %.3gs \n" ), - g_get_prgname(), image->filename, + vips_get_prgname(), image->filename, g_timer_elapsed( progress->start, NULL ) ); } diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index e47c008a..b9561aea 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -126,6 +126,10 @@ GTimer *vips__global_timer = NULL; */ static char *vips__argv0 = NULL; +/* Keep a copy of the last component of argv0 here. + */ +static char *vips__prgname = NULL; + /* Leak check on exit. */ int vips__leak = 0; @@ -143,7 +147,8 @@ static gint64 vips_pipe_read_limit = 1024 * 1024 * 1024; * * See also: VIPS_INIT(). * - * Returns: a pointer to an internal copy of the argv0 string passed to + * Returns: (transfer none): a pointer to an internal copy of the + * argv0 string passed to * VIPS_INIT(). Do not free this value */ const char * @@ -152,6 +157,27 @@ vips_get_argv0( void ) return( vips__argv0 ); } +/** + * vips_get_prgname: + * + * Return the program name. This can be useful for the user tio see,. + * + * See also: VIPS_INIT(). + * + * Returns: (transfer none): a pointer to an internal copy of the program + * name. Do not free this value + */ +const char * +vips_get_prgname( void ) +{ + const char *prgname; + + if( (prgname = g_get_prgname()) ) + return( prgname ); + else + return( vips__prgname ); +} + /** * VIPS_INIT: * @ARGV0: name of application @@ -422,14 +448,7 @@ vips_init( const char *argv0 ) vips__global_timer = g_timer_new(); VIPS_SETSTR( vips__argv0, argv0 ); - - if( argv0 ) { - char *prgname; - - prgname = g_path_get_basename( argv0 ); - g_set_prgname( prgname ); - g_free( prgname ); - } + vips__prgname = g_path_get_basename( argv0 ); vips__thread_profile_attach( "main" );