Fix building with -Dmodules=disabled (#2676)

* Fix building with -Dmodules=disabled

* Reformat line [skip ci]
This commit is contained in:
Kleis Auke Wolthuizen 2022-02-23 11:32:02 +01:00 committed by GitHub
parent d80185060d
commit 1e4cd2d5c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 3 deletions

View File

@ -613,6 +613,8 @@ static im_package *built_in[] = {
&im__resample, &im__resample,
&im__video &im__video
}; };
#ifdef ENABLE_MODULES
/* How we represent a loaded plugin. /* How we represent a loaded plugin.
*/ */
typedef struct _Plugin { typedef struct _Plugin {
@ -650,12 +652,14 @@ plugin_free( Plugin *plug )
return( 0 ); return( 0 );
} }
#endif
/* Load a plugin. /* Load a plugin.
*/ */
im_package * im_package *
im_load_plugin( const char *name ) im_load_plugin( const char *name )
{ {
#ifdef ENABLE_MODULES
Plugin *plug; Plugin *plug;
#ifdef DEBUG #ifdef DEBUG
@ -718,6 +722,12 @@ im_load_plugin( const char *name )
#endif /*DEBUG*/ #endif /*DEBUG*/
return( plug->pack ); return( plug->pack );
#else /*!ENABLE_MODULES*/
vips_error( "plugin",
"%s", _( "libvips built without modules support" ) );
return( NULL );
#endif /*ENABLE_MODULES*/
} }
/* Load all plugins in a directory ... look for '.plg' suffix. Error if we had /* Load all plugins in a directory ... look for '.plg' suffix. Error if we had
@ -726,6 +736,7 @@ im_load_plugin( const char *name )
int int
im_load_plugins( const char *fmt, ... ) im_load_plugins( const char *fmt, ... )
{ {
#ifdef ENABLE_MODULES
va_list ap; va_list ap;
char dir_name[VIPS_PATH_MAX]; char dir_name[VIPS_PATH_MAX];
GDir *dir; GDir *dir;
@ -763,6 +774,11 @@ im_load_plugins( const char *fmt, ... )
g_dir_close( dir ); g_dir_close( dir );
return( result ); return( result );
#else /*!ENABLE_MODULES*/
/* Silently succeed if we can't do modules.
*/
return( 0 );
#endif /*ENABLE_MODULES*/
} }
/* Close all loaded plugins. /* Close all loaded plugins.
@ -770,13 +786,16 @@ im_load_plugins( const char *fmt, ... )
int int
im_close_plugins( void ) im_close_plugins( void )
{ {
#ifdef ENABLE_MODULES
while( plugin_list ) while( plugin_list )
if( plugin_free( (Plugin *) plugin_list->data ) ) if( plugin_free( (Plugin *) plugin_list->data ) )
return( -1 ); return( -1 );
#endif
return( 0 ); return( 0 );
} }
#ifdef ENABLE_MODULES
/* Apply a user-function to a plugin package. /* Apply a user-function to a plugin package.
*/ */
static void * static void *
@ -787,6 +806,7 @@ apply_plugin( Plugin *plug, VSListMap2Fn fn, void *a )
else else
return( fn( plug->pack, a, NULL ) ); return( fn( plug->pack, a, NULL ) );
} }
#endif
/* Map a function over all packages. Map over plugins first, to allow /* Map a function over all packages. Map over plugins first, to allow
* overriding of VIPS functions. * overriding of VIPS functions.
@ -794,8 +814,12 @@ apply_plugin( Plugin *plug, VSListMap2Fn fn, void *a )
void * void *
im_map_packages( VSListMap2Fn fn, void *a ) im_map_packages( VSListMap2Fn fn, void *a )
{ {
#ifdef ENABLE_MODULES
void *r = im_slist_map2( plugin_list, void *r = im_slist_map2( plugin_list,
(VSListMap2Fn) apply_plugin, (void *) fn, a ); (VSListMap2Fn) apply_plugin, (void *) fn, a );
#else /*!ENABLE_MODULES*/
void *r = NULL;
#endif /*ENABLE_MODULES*/
/* If not there, try main VIPS package list. /* If not there, try main VIPS package list.
*/ */

View File

@ -254,6 +254,7 @@ vips_get_prgname( void )
* Returns: 0 on success, -1 otherwise * Returns: 0 on success, -1 otherwise
*/ */
#ifdef ENABLE_MODULES
/* Load all plugins in a directory ... look for '.<G_MODULE_SUFFIX>' or /* Load all plugins in a directory ... look for '.<G_MODULE_SUFFIX>' or
* '.plg' (deprecated) suffix. Error if we had any probs. * '.plg' (deprecated) suffix. Error if we had any probs.
*/ */
@ -313,6 +314,7 @@ vips_load_plugins( const char *fmt, ... )
return( result ); return( result );
} }
#endif
/* Install this log handler to hide warning messages. /* Install this log handler to hide warning messages.
*/ */
@ -597,7 +599,6 @@ vips_init( const char *argv0 )
*/ */
(void) vips_load_plugins( "%s/vips-modules-%d.%d", (void) vips_load_plugins( "%s/vips-modules-%d.%d",
libdir, VIPS_MAJOR_VERSION, VIPS_MINOR_VERSION ); libdir, VIPS_MAJOR_VERSION, VIPS_MINOR_VERSION );
#endif /*ENABLE_MODULES*/
#if ENABLE_DEPRECATED #if ENABLE_DEPRECATED
/* Load any vips8 plugins from the vips libdir. /* Load any vips8 plugins from the vips libdir.
@ -622,7 +623,8 @@ vips_init( const char *argv0 )
g_warning( "%s", vips_error_buffer() ); g_warning( "%s", vips_error_buffer() );
vips_error_clear(); vips_error_clear();
} }
#endif #endif /*ENABLE_DEPRECATED*/
#endif /*ENABLE_MODULES*/
/* Get the run-time compiler going. /* Get the run-time compiler going.
*/ */

View File

@ -611,6 +611,7 @@ main( int argc, char **argv )
; ;
if( main_option_plugin ) { if( main_option_plugin ) {
#if ENABLE_MODULES
#if ENABLE_DEPRECATED #if ENABLE_DEPRECATED
if( !im_load_plugin( main_option_plugin ) ) if( !im_load_plugin( main_option_plugin ) )
vips_error_exit( NULL ); vips_error_exit( NULL );
@ -622,7 +623,11 @@ main( int argc, char **argv )
vips_error_exit( _( "unable to load \"%s\" -- %s" ), vips_error_exit( _( "unable to load \"%s\" -- %s" ),
main_option_plugin, g_module_error() ); main_option_plugin, g_module_error() );
} }
#endif #endif /*ENABLE_DEPRECATED*/
#else /*!ENABLE_MODULES*/
g_warning( "%s", _( "plugin load disabled: "
"libvips built without modules support" ) );
#endif /*ENABLE_MODULES*/
} }
if( main_option_version ) if( main_option_version )