guile: add support of Guile 2.2 (issue #1098)

This commit is contained in:
Sébastien Helleu 2018-11-21 21:31:07 +01:00
parent e1a4612797
commit 387a44f5ec
5 changed files with 79 additions and 5 deletions

View File

@ -33,7 +33,7 @@ endif()
find_package(PkgConfig) find_package(PkgConfig)
if(PKG_CONFIG_FOUND) if(PKG_CONFIG_FOUND)
pkg_search_module(GUILE guile-2.0) pkg_search_module(GUILE guile-2.2 guile-2.0)
if(GUILE_FOUND) if(GUILE_FOUND)
# check if variable "scm_install_gmp_memory_functions" exists # check if variable "scm_install_gmp_memory_functions" exists
set(CMAKE_REQUIRED_INCLUDES ${GUILE_INCLUDE_DIRS}) set(CMAKE_REQUIRED_INCLUDES ${GUILE_INCLUDE_DIRS})

View File

@ -727,7 +727,7 @@ if test "x$enable_guile" = "xyes" ; then
guile_found="no" guile_found="no"
AC_MSG_CHECKING(for Guile headers and libraries) AC_MSG_CHECKING(for Guile headers and libraries)
echo 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` pkgconfig_guile_found=`$PKGCONFIG --exists guile-$v 2>/dev/null`
if test "x$?" = "x0" ; then if test "x$?" = "x0" ; then
GUILE_VERSION=`$PKGCONFIG --modversion guile-$v` GUILE_VERSION=`$PKGCONFIG --modversion guile-$v`

View File

@ -4874,10 +4874,17 @@ weechat_guile_api_upgrade_close (SCM upgrade_file)
void void
weechat_guile_api_module_init (void *data) 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 */ port_type = scm_make_port_type ("weechat_stdout",
(void) data; &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", port_type = scm_make_port_type ("weechat_stdout",
&weechat_guile_port_fill_input, &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_CELL_TYPE (guile_port, port_type | SCM_OPN | SCM_WRTNG);
scm_set_current_output_port (guile_port); scm_set_current_output_port (guile_port);
scm_set_current_error_port (guile_port); scm_set_current_error_port (guile_port);
#endif
/* make C compiler happy */
(void) data;
/* interface functions */ /* interface functions */
API_DEF_FUNC(register, 7); API_DEF_FUNC(register, 7);

View File

@ -1127,6 +1127,21 @@ weechat_guile_signal_script_action_cb (const void *pointer, void *data,
* Fills input. * 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 int
weechat_guile_port_fill_input (SCM port) weechat_guile_port_fill_input (SCM port)
{ {
@ -1135,11 +1150,47 @@ weechat_guile_port_fill_input (SCM port)
return ' '; return ' ';
} }
#endif
/* /*
* Write. * 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 void
weechat_guile_port_write (SCM port, const void *data, size_t size) 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); weechat_string_dyn_concat (guile_buffer_output, ptr_data);
} }
#endif
/* /*
* Initializes guile plugin. * Initializes guile plugin.

View File

@ -20,6 +20,8 @@
#ifndef WEECHAT_PLUGIN_GUILE_H #ifndef WEECHAT_PLUGIN_GUILE_H
#define WEECHAT_PLUGIN_GUILE_H #define WEECHAT_PLUGIN_GUILE_H
#include <libguile.h>
#define weechat_plugin weechat_guile_plugin #define weechat_plugin weechat_guile_plugin
#define GUILE_PLUGIN_NAME "guile" #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, extern void *weechat_guile_exec (struct t_plugin_script *script,
int ret_type, const char *function, int ret_type, const char *function,
char *format, void **argv); 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 int weechat_guile_port_fill_input (SCM port);
extern void weechat_guile_port_write (SCM port, const void *data, size_t size); extern void weechat_guile_port_write (SCM port, const void *data, size_t size);
#endif
#endif /* WEECHAT_PLUGIN_GUILE_H */ #endif /* WEECHAT_PLUGIN_GUILE_H */