From 43db3985d0c0f0321434f2bd1cda36c7dd4fa1e5 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 19 Apr 2022 16:41:18 +0100 Subject: [PATCH] try to always set the min stack size since musl users often don't know about this see https://github.com/libvips/libvips/issues/2761 --- ChangeLog | 1 + libvips/iofuncs/init.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index a6bed668..0bcb8b66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,7 @@ - add maxerror to gifsave [dloebl] - update libnsgif API [tlsa] - deprecate "properties" option to dzsave (now always on) +- always set the min stack size for pthreads, if we can 26/11/21 started 8.12.3 - better arg checking for hist_find_ndim [travisbell] diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index cc88238a..d758824b 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -447,6 +447,7 @@ vips_init( const char *argv0 ) static gboolean started = FALSE; static gboolean done = FALSE; const char *vips_min_stack_size; + gint64 min_stack_size; const char *prefix; const char *libdir; #ifdef ENABLE_NLS @@ -468,6 +469,14 @@ vips_init( const char *argv0 ) return( 0 ); started = TRUE; + /* Try to set a minimum stacksize, default 2mb. We need to do this + * before any threads start. + */ + min_stack_size = 2 * 1024 * 1024; + if( (vips_min_stack_size = g_getenv( "VIPS_MIN_STACK_SIZE" )) ) + min_stack_size = vips__parse_size( vips_min_stack_size ); + (void) set_stacksize( min_stack_size ); + if( g_getenv( "VIPS_INFO" ) #if ENABLE_DEPRECATED || g_getenv( "IM_INFO" ) @@ -665,11 +674,6 @@ vips_init( const char *argv0 ) if( g_getenv( "VIPS_BLOCK_UNTRUSTED" ) ) vips_block_untrusted_set( TRUE ); - /* Set a minimum stacksize, if we can. - */ - if( (vips_min_stack_size = g_getenv( "VIPS_MIN_STACK_SIZE" )) ) - (void) set_stacksize( vips__parse_size( vips_min_stack_size ) ); - done = TRUE; vips__thread_gate_stop( "init: startup" );