Skip to content

Commit 29a13c0

Browse files
committed
check for exception propagation in udunits2, closes #423
1 parent 1148f59 commit 29a13c0

File tree

5 files changed

+159
-18
lines changed

5 files changed

+159
-18
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: units
2-
Version: 1.0-0.3
2+
Version: 1.0-0.4
33
Title: Measurement Units for R Vectors
44
Authors@R: c(person("Edzer", "Pebesma", role = c("aut", "cre"), email = "edzer.pebesma@uni-muenster.de", comment = c(ORCID = "0000-0001-8049-7069")),
55
person("Thomas", "Mailund", role = "aut", email = "mailund@birc.au.dk"),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
* Wrap all pointers to avoid memory leaks derived from errors.
1212

13+
* Check for exception propagation in udunits2; #423
14+
1315
# version 1.0-0
1416

1517
* Breaking change: a new tokenizer fixes longstanding issues with parsing

configure

Lines changed: 121 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/sh
22
# Guess values for system-dependent variables and create Makefiles.
3-
# Generated by GNU Autoconf 2.72 for units 1.0-0.
3+
# Generated by GNU Autoconf 2.72 for units 1.0-0.4.
44
#
55
# Report bugs to <edzer.pebesma@uni-muenster.de>.
66
#
@@ -603,8 +603,8 @@ MAKEFLAGS=
603603
# Identity of this package.
604604
PACKAGE_NAME='units'
605605
PACKAGE_TARNAME='units'
606-
PACKAGE_VERSION='1.0-0'
607-
PACKAGE_STRING='units 1.0-0'
606+
PACKAGE_VERSION='1.0-0.4'
607+
PACKAGE_STRING='units 1.0-0.4'
608608
PACKAGE_BUGREPORT='edzer.pebesma@uni-muenster.de'
609609
PACKAGE_URL=''
610610

@@ -1260,7 +1260,7 @@ if test "$ac_init_help" = "long"; then
12601260
# Omit some internal or obsolete options to make the list less imposing.
12611261
# This message is too long to be a string in the A/UX 3.1 sh.
12621262
cat <<_ACEOF
1263-
'configure' configures units 1.0-0 to adapt to many kinds of systems.
1263+
'configure' configures units 1.0-0.4 to adapt to many kinds of systems.
12641264
12651265
Usage: $0 [OPTION]... [VAR=VALUE]...
12661266
@@ -1322,7 +1322,7 @@ fi
13221322

13231323
if test -n "$ac_init_help"; then
13241324
case $ac_init_help in
1325-
short | recursive ) echo "Configuration of units 1.0-0:";;
1325+
short | recursive ) echo "Configuration of units 1.0-0.4:";;
13261326
esac
13271327
cat <<\_ACEOF
13281328
@@ -1411,7 +1411,7 @@ fi
14111411
test -n "$ac_init_help" && exit $ac_status
14121412
if $ac_init_version; then
14131413
cat <<\_ACEOF
1414-
units configure 1.0-0
1414+
units configure 1.0-0.4
14151415
generated by GNU Autoconf 2.72
14161416
14171417
Copyright (C) 2023 Free Software Foundation, Inc.
@@ -1646,6 +1646,50 @@ fi
16461646
as_fn_set_status $ac_retval
16471647

16481648
} # ac_fn_c_try_compile
1649+
1650+
# ac_fn_cxx_try_run LINENO
1651+
# ------------------------
1652+
# Try to run conftest.$ac_ext, and return whether this succeeded. Assumes that
1653+
# executables *can* be run.
1654+
ac_fn_cxx_try_run ()
1655+
{
1656+
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
1657+
if { { ac_try="$ac_link"
1658+
case "(($ac_try" in
1659+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
1660+
*) ac_try_echo=$ac_try;;
1661+
esac
1662+
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
1663+
printf "%s\n" "$ac_try_echo"; } >&5
1664+
(eval "$ac_link") 2>&5
1665+
ac_status=$?
1666+
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
1667+
test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
1668+
{ { case "(($ac_try" in
1669+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
1670+
*) ac_try_echo=$ac_try;;
1671+
esac
1672+
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
1673+
printf "%s\n" "$ac_try_echo"; } >&5
1674+
(eval "$ac_try") 2>&5
1675+
ac_status=$?
1676+
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
1677+
test $ac_status = 0; }; }
1678+
then :
1679+
ac_retval=0
1680+
else case e in #(
1681+
e) printf "%s\n" "$as_me: program exited with status $ac_status" >&5
1682+
printf "%s\n" "$as_me: failed program was:" >&5
1683+
sed 's/^/| /' conftest.$ac_ext >&5
1684+
1685+
ac_retval=$ac_status ;;
1686+
esac
1687+
fi
1688+
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
1689+
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
1690+
as_fn_set_status $ac_retval
1691+
1692+
} # ac_fn_cxx_try_run
16491693
ac_configure_args_raw=
16501694
for ac_arg
16511695
do
@@ -1670,7 +1714,7 @@ cat >config.log <<_ACEOF
16701714
This file contains any messages produced by compilers while
16711715
running configure, to aid debugging if configure makes a mistake.
16721716
1673-
It was created by units $as_me 1.0-0, which was
1717+
It was created by units $as_me 1.0-0.4, which was
16741718
generated by GNU Autoconf 2.72. Invocation command line was
16751719
16761720
$ $0$ac_configure_args_raw
@@ -4295,24 +4339,32 @@ if test "${ac_cv_lib_expat_XML_ParserCreate}" = yes; then
42954339
LIBS="${LIBS} -lexpat"
42964340
fi
42974341

4298-
ac_fn_cxx_check_header_compile "$LINENO" "udunits2.h" "ac_cv_header_udunits2_h" "$ac_includes_default"
4342+
for ac_header in udunits2.h
4343+
do :
4344+
ac_fn_cxx_check_header_compile "$LINENO" "udunits2.h" "ac_cv_header_udunits2_h" "$ac_includes_default"
42994345
if test "x$ac_cv_header_udunits2_h" = xyes
43004346
then :
4301-
UDUNITS2_DIR=0
4347+
printf "%s\n" "#define HAVE_UDUNITS2_H 1" >>confdefs.h
4348+
UDUNITS2_DIR=0
43024349
else case e in #(
43034350
e)
4351+
for ac_header in udunits2/udunits2.h
4352+
do :
43044353
ac_fn_cxx_check_header_compile "$LINENO" "udunits2/udunits2.h" "ac_cv_header_udunits2_udunits2_h" "$ac_includes_default"
43054354
if test "x$ac_cv_header_udunits2_udunits2_h" = xyes
43064355
then :
4307-
UDUNITS2_DIR=1
4356+
printf "%s\n" "#define HAVE_UDUNITS2_UDUNITS2_H 1" >>confdefs.h
4357+
UDUNITS2_DIR=1
43084358
else case e in #(
43094359
e) UD_ERROR="udunits2.h was not found" ;;
43104360
esac
43114361
fi
4312-
;;
4362+
4363+
done ;;
43134364
esac
43144365
fi
43154366

4367+
done
43164368
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ut_read_xml in -ludunits2" >&5
43174369
printf %s "checking for ut_read_xml in -ludunits2... " >&6; }
43184370
if test ${ac_cv_lib_udunits2_ut_read_xml+y}
@@ -4376,6 +4428,62 @@ as_fn_error $? "
43764428
43774429
See 'config.log' for more details" "$LINENO" 5; } fi
43784430

4431+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for exception propagation in -ludunits2" >&5
4432+
printf %s "checking for exception propagation in -ludunits2... " >&6; }
4433+
if test "$cross_compiling" = yes
4434+
then :
4435+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unknown (cross-compiling)" >&5
4436+
printf "%s\n" "unknown (cross-compiling)" >&6; }
4437+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Cross-compiling: cannot verify exception propagation in udunits2. Assuming it works." >&5
4438+
printf "%s\n" "$as_me: WARNING: Cross-compiling: cannot verify exception propagation in udunits2. Assuming it works." >&2;}
4439+
4440+
else case e in #(
4441+
e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
4442+
/* end confdefs.h. */
4443+
4444+
#include <stdexcept>
4445+
#include <cstdarg>
4446+
#ifdef HAVE_UDUNITS2_UDUNITS2_H
4447+
# include <udunits2/udunits2.h>
4448+
#else
4449+
# include <udunits2.h>
4450+
#endif
4451+
extern "C" {
4452+
int ud_handler(const char* fmt, va_list args) {
4453+
throw std::runtime_error("udunits error");
4454+
return 0;
4455+
}
4456+
}
4457+
4458+
int
4459+
main (void)
4460+
{
4461+
4462+
ut_set_error_message_handler(ud_handler);
4463+
try { ut_read_xml("nonexistent.xml"); }
4464+
catch (...) { return 0; }
4465+
return 1;
4466+
4467+
;
4468+
return 0;
4469+
}
4470+
_ACEOF
4471+
if ac_fn_cxx_try_run "$LINENO"
4472+
then :
4473+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
4474+
printf "%s\n" "yes" >&6; }
4475+
else case e in #(
4476+
e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
4477+
printf "%s\n" "no" >&6; }
4478+
as_fn_error $? "The udunits2 library does not support exception propagation. Please reinstall it with -fexceptions enabled." "$LINENO" 5 ;;
4479+
esac
4480+
fi
4481+
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
4482+
conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
4483+
esac
4484+
fi
4485+
4486+
43794487

43804488

43814489

@@ -4918,7 +5026,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
49185026
# report actual input values of CONFIG_FILES etc. instead of their
49195027
# values after options handling.
49205028
ac_log="
4921-
This file was extended by units $as_me 1.0-0, which was
5029+
This file was extended by units $as_me 1.0-0.4, which was
49225030
generated by GNU Autoconf 2.72. Invocation command line was
49235031
49245032
CONFIG_FILES = $CONFIG_FILES
@@ -4973,7 +5081,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
49735081
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
49745082
ac_cs_config='$ac_cs_config_escaped'
49755083
ac_cs_version="\\
4976-
units config.status 1.0-0
5084+
units config.status 1.0-0.4
49775085
configured by $0, generated by GNU Autoconf 2.72,
49785086
with options \\"\$ac_cs_config\\"
49795087

configure.ac

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ if test "${ac_cv_lib_expat_XML_ParserCreate}" = yes; then
5959
LIBS="${LIBS} -lexpat"
6060
fi
6161

62-
AC_CHECK_HEADER(udunits2.h, UDUNITS2_DIR=0, [
63-
AC_CHECK_HEADER(udunits2/udunits2.h, UDUNITS2_DIR=1,
62+
AC_CHECK_HEADERS(udunits2.h, UDUNITS2_DIR=0, [
63+
AC_CHECK_HEADERS(udunits2/udunits2.h, UDUNITS2_DIR=1,
6464
UD_ERROR="udunits2.h was not found") ])
6565
AC_CHECK_LIB(udunits2, ut_read_xml,
6666
LIBS="${LIBS} -ludunits2",
@@ -81,6 +81,36 @@ if test "${UD_ERROR}" != "" ; then AC_MSG_FAILURE([
8181
--------------------------------------------------------------------------------
8282
]) fi
8383

84+
AC_MSG_CHECKING([for exception propagation in -ludunits2])
85+
AC_RUN_IFELSE([AC_LANG_PROGRAM(
86+
[[
87+
#include <stdexcept>
88+
#include <cstdarg>
89+
#ifdef HAVE_UDUNITS2_UDUNITS2_H
90+
# include <udunits2/udunits2.h>
91+
#else
92+
# include <udunits2.h>
93+
#endif
94+
extern "C" {
95+
int ud_handler(const char* fmt, va_list args) {
96+
throw std::runtime_error("udunits error");
97+
return 0;
98+
}
99+
}
100+
]],
101+
[[
102+
ut_set_error_message_handler(ud_handler);
103+
try { ut_read_xml("nonexistent.xml"); }
104+
catch (...) { return 0; }
105+
return 1;
106+
]])],
107+
[AC_MSG_RESULT([yes])],
108+
[AC_MSG_RESULT([no])
109+
AC_MSG_ERROR([The udunits2 library does not support exception propagation. Please reinstall it with -fexceptions enabled.])],
110+
[AC_MSG_RESULT([unknown (cross-compiling)])
111+
AC_MSG_WARN([Cross-compiling: cannot verify exception propagation in udunits2. Assuming it works.])]
112+
)
113+
84114
AC_SUBST([CXX_STD])
85115
AC_SUBST([LIBS])
86116
AC_SUBST([UD_CPPFLAGS])

src/udunits.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
#include "units_types.h"
1212

1313
extern "C" {
14-
void r_error_fn(const char* fmt, va_list args) {
14+
int r_error_fn(const char* fmt, va_list args) {
1515
char buf[256];
1616
vsnprintf(buf, (size_t) 256, fmt, args);
1717
Rcpp::stop("%s", buf);
18+
return 0;
1819
}
1920
}
2021

@@ -42,7 +43,7 @@ void ud_init(CharacterVector path) {
4243
}
4344
if (sys == NULL)
4445
sys = ut_read_xml(NULL); // #nocov
45-
ut_set_error_message_handler((ut_error_message_handler) r_error_fn);
46+
ut_set_error_message_handler(r_error_fn);
4647
if (sys == NULL)
4748
stop("no database found!"); // #nocov
4849
}

0 commit comments

Comments
 (0)