Skip to content

Commit

Permalink
Place scribbu types & functions in module (scribbu), even
Browse files Browse the repository at this point in the history
when defined in C.

This commit will place the snarfed functions provided by
libscribbu.so into module `(scribbu)` and updates
`scribbu.scm` to load the extension.
  • Loading branch information
Michael Herstine committed Sep 16, 2023
1 parent e544648 commit 8720aa6
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 23 deletions.
4 changes: 2 additions & 2 deletions macros/ltoptions.m4
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Helper functions for option handling. -*- Autoconf -*-
#
# Copyright (C) 2004-2005, 2007-2009, 2011-2019, 2021-2022 Free
# Software Foundation, Inc.
# Copyright (C) 2004-2005, 2007-2009, 2011-2015 Free Software
# Foundation, Inc.
# Written by Gary V. Vaughan, 2004
#
# This file is free software; the Free Software Foundation gives
Expand Down
2 changes: 1 addition & 1 deletion macros/ltsugar.m4
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*-
#
# Copyright (C) 2004-2005, 2007-2008, 2011-2019, 2021-2022 Free Software
# Copyright (C) 2004-2005, 2007-2008, 2011-2015 Free Software
# Foundation, Inc.
# Written by Gary V. Vaughan, 2004
#
Expand Down
13 changes: 6 additions & 7 deletions macros/ltversion.m4
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ltversion.m4 -- version numbers -*- Autoconf -*-
#
# Copyright (C) 2004, 2011-2019, 2021-2022 Free Software Foundation,
# Inc.
# Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc.
# Written by Scott James Remnant, 2004
#
# This file is free software; the Free Software Foundation gives
Expand All @@ -10,15 +9,15 @@

# @configure_input@

# serial 4249 ltversion.m4
# serial 4179 ltversion.m4
# This file is part of GNU Libtool

m4_define([LT_PACKAGE_VERSION], [2.4.7.4-1ec8f-dirty])
m4_define([LT_PACKAGE_REVISION], [2.4.7.4])
m4_define([LT_PACKAGE_VERSION], [2.4.6])
m4_define([LT_PACKAGE_REVISION], [2.4.6])

AC_DEFUN([LTVERSION_VERSION],
[macro_version='2.4.7.4-1ec8f-dirty'
macro_revision='2.4.7.4'
[macro_version='2.4.6'
macro_revision='2.4.6'
_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
_LT_DECL(, macro_revision, 0)
])
4 changes: 2 additions & 2 deletions macros/lt~obsolete.m4
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*-
#
# Copyright (C) 2004-2005, 2007, 2009, 2011-2019, 2021-2022 Free
# Software Foundation, Inc.
# Copyright (C) 2004-2005, 2007, 2009, 2011-2015 Free Software
# Foundation, Inc.
# Written by Scott James Remnant, 2004.
#
# This file is free software; the Free Software Foundation gives
Expand Down
4 changes: 4 additions & 0 deletions scheme/scribbu.scm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
unknown-frame album-frame artist-frame
has-frame? get-frames))

;; Load the Scheme extension in `libscribbu.so` & invoke `init_scribbu()` therein to define types &
;; functions. Nb. These definitions will be in module `(scribbu)`.
(load-extension "libscribbu" "init_scribbu")

(use-modules (ice-9 ftw))
(use-modules (ice-9 match))
(use-modules (rnrs bytevectors))
Expand Down
33 changes: 26 additions & 7 deletions scribbu/scheme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,30 @@ extern "C" {
}
/// Define our types & functions at the top level of the current module
void
init_scribbu()
{
scribbu::init_symbols();
# ifndef SCM_MAGIC_SNARFER
# include "scheme.x"
# endif
scm_c_export(READ_ID3V1_TAG, READ_TAGSET, WITH_TRACK_IN, WRITE_ID3V1_TAG,
WRITE_TAGSET, nullptr);
}
/// Define our types & functions in the current module-- this function is
/// just a shim to allow us to initialize this from either the Guile REPL or
/// when loading the extension from Scheme.
void
init_scribbu_shim(void*) {
init_scribbu();
}
SCM
get_version_variable(void*)
{
Expand Down Expand Up @@ -854,16 +878,11 @@ extern "C" {
{
const init_guile *pig = reinterpret_cast<const init_guile*>(praw);

scribbu::init_symbols();

# ifndef SCM_MAGIC_SNARFER
# include "scheme.x"
# endif

// scm_c_define_module("scribbu-int", init_scribbu_shim, nullptr);
customize_welcome();
customize_load_path(pig->datadir_);

return 0;
return nullptr;
}

} // End extern "C".
Expand Down
7 changes: 5 additions & 2 deletions test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
AM_TESTS_ENVIRONMENT = \
abs_top_builddir=$(abs_top_builddir)
check_PROGRAMS = unit
SUBDIRS = data
EXTRA_DIST = test-util test-split test-rename test-report test-report-tdf \
Expand All @@ -7,7 +9,7 @@ EXTRA_DIST = test-util test-split test-rename test-report test-report-tdf \
test-tagsets-from-scheme.scm test-tagsets-from-scheme \
test-frames-from-scheme.scm test-frames-from-scheme \
test-scripting test-options test-popm test-xtag test-text test-genre \
test-m3u
test-m3u test-snarfed-in-scribbu
CLEANFILES = id3v20B id3v21B report.last.csv report-tdf.last.tdf \
report.csv report-last.csv report-tdf.tdf \
id3v20A trackB id3v1A trackA \
Expand All @@ -34,7 +36,8 @@ TESTS = $(check_PROGRAMS) test-split test-rename test-report test-report-tdf \
test-dump test-with-track-in test-fs-generator \
test-cleanup-encoded-by test-cleanup-from-audacity \
test-tagsets-from-scheme test-frames-from-scheme test-scripting \
test-options test-popm test-xtag test-text test-genre test-m3u
test-options test-popm test-xtag test-text test-genre test-m3u \
test-snarfed-in-scribbu
unit_SOURCES = unit.cc unit.hh charsets.cc ostream.cc id3v1.cc framesv2.cc \
framesv22.cc framesv23.cc framesv24.cc id3v2.cc id3v22.cc id3v23.cc \
id3v24.cc id3v2-utils.cc pprinter.cc csv-pprinter.cc mp3.cc tdf-pprinter.cc \
Expand Down
1 change: 1 addition & 0 deletions test/id3v2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*
*/

#include <boost/test/unit_test_suite.hpp>
#include <scribbu/id3v2-utils.hh>

#include "unit.hh"
Expand Down
2 changes: 1 addition & 1 deletion test/test-fs-generator
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
testdir=/tmp/scribbu-test/scheme
mkdir -p $testdir/a/b
touch $testdir/foo $testdir/a/bar $testdir/a/b/splat
guile -L ${srcdir}/../scheme -s ${srcdir}/test-fs-generator.scm
LD_LIBRARY_PATH=${abs_top_builddir}/scribbu/.libs guile -L ${srcdir}/../scheme -s ${srcdir}/test-fs-generator.scm
1 change: 0 additions & 1 deletion test/test-fs-generator.scm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
;;;;
;;;;


(use-modules (scribbu))
(define test-dir "/tmp/scribbu-test/scheme")
(define G (fs-tree-generator test-dir))
Expand Down
57 changes: 57 additions & 0 deletions test/test-snarfed-in-scribbu
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

tmpfile=/tmp/test-scripting.scm
scribbu_dir=`cd ../src; pwd`
lib_dir=`cd ../scribbu; pwd`
case `uname` in
Linux)
echo "#!${scribbu_dir}/scribbu \\" > $tmpfile;;
Darwin)
# Workaround for MacOS-- should be; for some reason I don't
# understand (and don't care to debug), the `src/scribbu'
# libtool script doesn't work well with the extended #! line
# I use below. So, I call the MacOS binary directly, being careful
# to set DYLD_LIBRARY_PATH (like the libtool script would)
# so that we load the .so under test and not any previously installed
# version.
echo "#!${scribbu_dir}/.libs/scribbu \\" > $tmpfile;
export DYLD_LIBRARY_PATH=$lib_dir/.libs:$DYLD_LIBRARY_PATH;;
*)
echo "Unknown system" 2>&1;
exit 1;;
esac

cat >> $tmpfile<<EOF
-e main -s
!#
;; Should fail
(set! x (read-id3v1-tag "data/id3v1.2.3.tag"))
EOF

chmod a+x $tmpfile
export GUILE_AUTO_COMPILE=0
cols=$(tput cols)
export GUILE_LOAD_PATH=${srcdir}/../scheme

eval "$($tmpfile \
2> >(t_err=$(cat); typeset -p t_err) \
> >(t_std=$(cat); typeset -p t_std) )"
t_stat=$?
t_err=$(echo "$t_err" | grep -vE ';;; note: source file /tmp/test-scripting.scm' | grep -v 'newer than compiled')
if [ $t_stat -ne 0 ]; then
>&2 echo "Non-zero exit code ($t_stat)."
echo "stdout:"
echo "$t_std"
echo "stderr:"
echo "$t_err"
exit 1
fi

if [ "${t_err}" !~ "Unbound variable: read-id3v1-tag" ]; then
>&2 echo "Unexpected stderr"
echo "stdout:"
echo "$t_std"
echo "stderr:"
echo "$t_err"
exit 1
fi

0 comments on commit 8720aa6

Please sign in to comment.