From 387a44f5ece0af6e805bd1a469d1aa1358d60d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 21 Nov 2018 21:31:07 +0100 Subject: [PATCH] guile: add support of Guile 2.2 (issue #1098) --- cmake/FindGuile.cmake | 2 +- configure.ac | 2 +- src/plugins/guile/weechat-guile-api.c | 17 +++++++-- src/plugins/guile/weechat-guile.c | 52 +++++++++++++++++++++++++++ src/plugins/guile/weechat-guile.h | 11 ++++++ 5 files changed, 79 insertions(+), 5 deletions(-) diff --git a/cmake/FindGuile.cmake b/cmake/FindGuile.cmake index e283e51f8..7573b0879 100644 --- a/cmake/FindGuile.cmake +++ b/cmake/FindGuile.cmake @@ -33,7 +33,7 @@ endif() find_package(PkgConfig) if(PKG_CONFIG_FOUND) - pkg_search_module(GUILE guile-2.0) + pkg_search_module(GUILE guile-2.2 guile-2.0) if(GUILE_FOUND) # check if variable "scm_install_gmp_memory_functions" exists set(CMAKE_REQUIRED_INCLUDES ${GUILE_INCLUDE_DIRS}) diff --git a/configure.ac b/configure.ac index ea014a988..53a2f3dba 100644 --- a/configure.ac +++ b/configure.ac @@ -727,7 +727,7 @@ if test "x$enable_guile" = "xyes" ; then guile_found="no" AC_MSG_CHECKING(for Guile headers and libraries) echo - for v in "2.0" ; do + for v in "2.2" "2.0" ; do pkgconfig_guile_found=`$PKGCONFIG --exists guile-$v 2>/dev/null` if test "x$?" = "x0" ; then GUILE_VERSION=`$PKGCONFIG --modversion guile-$v` diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index 331ce0e64..d54eb11ee 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -4874,10 +4874,17 @@ weechat_guile_api_upgrade_close (SCM upgrade_file) void weechat_guile_api_module_init (void *data) { - scm_t_bits port_type; +#if SCM_MAJOR_VERSION >= 3 || (SCM_MAJOR_VERSION == 2 && SCM_MINOR_VERSION >= 2) + /* Guile >= 2.2 */ + scm_t_port_type *port_type; - /* make C compiler happy */ - (void) data; + port_type = scm_make_port_type ("weechat_stdout", + &weechat_guile_port_fill_input, + &weechat_guile_port_write); + guile_port = scm_c_make_port (port_type, 0, 0); +#else + /* Guile < 2.2 */ + scm_t_bits port_type; port_type = scm_make_port_type ("weechat_stdout", &weechat_guile_port_fill_input, @@ -4886,6 +4893,10 @@ weechat_guile_api_module_init (void *data) SCM_SET_CELL_TYPE (guile_port, port_type | SCM_OPN | SCM_WRTNG); scm_set_current_output_port (guile_port); scm_set_current_error_port (guile_port); +#endif + + /* make C compiler happy */ + (void) data; /* interface functions */ API_DEF_FUNC(register, 7); diff --git a/src/plugins/guile/weechat-guile.c b/src/plugins/guile/weechat-guile.c index 0ea420582..e9056ad36 100644 --- a/src/plugins/guile/weechat-guile.c +++ b/src/plugins/guile/weechat-guile.c @@ -1127,6 +1127,21 @@ weechat_guile_signal_script_action_cb (const void *pointer, void *data, * Fills input. */ +#if SCM_MAJOR_VERSION >= 3 || (SCM_MAJOR_VERSION == 2 && SCM_MINOR_VERSION >= 2) +/* Guile >= 2.2 */ +size_t +weechat_guile_port_fill_input (SCM port, SCM dst, size_t start, size_t count) +{ + /* make C compiler happy */ + (void) port; + (void) dst; + (void) start; + (void) count; + + return ' '; +} +#else +/* Guile < 2.2 */ int weechat_guile_port_fill_input (SCM port) { @@ -1135,11 +1150,47 @@ weechat_guile_port_fill_input (SCM port) return ' '; } +#endif /* * Write. */ +#if SCM_MAJOR_VERSION >= 3 || (SCM_MAJOR_VERSION == 2 && SCM_MINOR_VERSION >= 2) +/* Guile >= 2.2 */ +size_t +weechat_guile_port_write (SCM port, SCM src, size_t start, size_t count) +{ + char *data2, *ptr_data, *ptr_newline; + const char *data; + + /* make C compiler happy */ + (void) port; + + data = scm_to_locale_string (src); + + data2 = malloc (count + 1); + if (!data2) + return 0; + + memcpy (data2, data + start, count); + data2[count] = '\0'; + + ptr_data = data2; + while ((ptr_newline = strchr (ptr_data, '\n')) != NULL) + { + ptr_newline[0] = '\0'; + weechat_string_dyn_concat (guile_buffer_output, ptr_data); + weechat_guile_output_flush (); + ptr_newline[0] = '\n'; + ptr_data = ++ptr_newline; + } + weechat_string_dyn_concat (guile_buffer_output, ptr_data); + + return count; +} +#else +/* Guile < 2.2 */ void weechat_guile_port_write (SCM port, const void *data, size_t size) { @@ -1166,6 +1217,7 @@ weechat_guile_port_write (SCM port, const void *data, size_t size) } weechat_string_dyn_concat (guile_buffer_output, ptr_data); } +#endif /* * Initializes guile plugin. diff --git a/src/plugins/guile/weechat-guile.h b/src/plugins/guile/weechat-guile.h index ee1a7a144..b21da36a6 100644 --- a/src/plugins/guile/weechat-guile.h +++ b/src/plugins/guile/weechat-guile.h @@ -20,6 +20,8 @@ #ifndef WEECHAT_PLUGIN_GUILE_H #define WEECHAT_PLUGIN_GUILE_H +#include + #define weechat_plugin weechat_guile_plugin #define GUILE_PLUGIN_NAME "guile" @@ -45,7 +47,16 @@ extern struct t_hashtable *weechat_guile_alist_to_hashtable (SCM dict, extern void *weechat_guile_exec (struct t_plugin_script *script, int ret_type, const char *function, char *format, void **argv); +#if SCM_MAJOR_VERSION >= 3 || (SCM_MAJOR_VERSION == 2 && SCM_MINOR_VERSION >= 2) +/* Guile >= 2.2 */ +extern size_t weechat_guile_port_fill_input (SCM port, SCM dst, + size_t start, size_t count); +extern size_t weechat_guile_port_write (SCM port, SCM src, + size_t start, size_t count); +#else +/* Guile < 2.2 */ extern int weechat_guile_port_fill_input (SCM port); extern void weechat_guile_port_write (SCM port, const void *data, size_t size); +#endif #endif /* WEECHAT_PLUGIN_GUILE_H */