Skip to content

Commit

Permalink
simplify Snprintf implementation
Browse files Browse the repository at this point in the history
- assume vsnprintf (or _vsnprintf with old MSVS) to be present, instead of
  checking with configure; configure check for (_)vsnprintf doesn't seem to
  work with current MSVS (maybe these are macros)
- remove old code for SunOS that wasn't in IpJournalist anyway
  • Loading branch information
svigerske committed Dec 11, 2024
1 parent f4bba1f commit 893b3f2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 145 deletions.
94 changes: 4 additions & 90 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2583,78 +2583,6 @@ printf "%s\n" "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_check_decl

# ac_fn_cxx_check_func LINENO FUNC VAR
# ------------------------------------
# Tests whether FUNC exists, setting the cache variable VAR accordingly
ac_fn_cxx_check_func ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
printf %s "checking for $2... " >&6; }
if eval test \${$3+y}
then :
printf %s "(cached) " >&6
else case e in #(
e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
For example, HP-UX 11i <limits.h> declares gettimeofday. */
#define $2 innocuous_$2

/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $2 (void); below. */

#include <limits.h>
#undef $2

/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char $2 (void);
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined __stub_$2 || defined __stub___$2
choke me
#endif

#ifdef F77_DUMMY_MAIN

# ifdef __cplusplus
extern "C"
# endif
int F77_DUMMY_MAIN() { return 1; }

#endif
int
main (void)
{
return $2 ();
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"
then :
eval "$3=yes"
else case e in #(
e) eval "$3=no" ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam \
conftest$ac_exeext conftest.$ac_ext ;;
esac
fi
eval ac_res=\$$3
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_cxx_check_func
ac_configure_args_raw=
for ac_arg
do
Expand Down Expand Up @@ -28217,9 +28145,9 @@ printf "%s\n" "#define IPOPT_C_FINITE $COIN_C_FINITE" >>confdefs.h
fi


#########################
# va_copy and vsnprintf #
#########################
###########
# va_copy #
###########

ac_fn_check_decl "$LINENO" "va_copy" "ac_cv_have_decl_va_copy" "#include <cstdarg>
" "$ac_cxx_undeclared_builtin_options" "CXXFLAGS"
Expand All @@ -28230,20 +28158,6 @@ printf "%s\n" "#define IPOPT_HAS_VA_COPY 1" >>confdefs.h

fi

for ac_func in vsnprintf _vsnprintf
do :
as_ac_var=`printf "%s\n" "ac_cv_func_$ac_func" | sed "$as_sed_sh"`
ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"
then :
cat >>confdefs.h <<_ACEOF
#define `printf "%s\n" "HAVE_$ac_func" | sed "$as_sed_cpp"` 1
_ACEOF
break
fi

done

###########################
# Random number generator #
###########################
Expand Down Expand Up @@ -28489,7 +28403,7 @@ else case e in #(
JAVA_TEST=Test.java
CLASS_TEST=Test.class
cat << \EOF > $JAVA_TEST
/* #line 28492 "configure" */
/* #line 28406 "configure" */
public class Test {
}
EOF
Expand Down
7 changes: 3 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,12 @@ AC_LANG_PUSH(C++)

AC_COIN_CHECK_ISFINITE

#########################
# va_copy and vsnprintf #
#########################
###########
# va_copy #
###########

AC_CHECK_DECL([va_copy],[AC_DEFINE([IPOPT_HAS_VA_COPY],[1],
[Define to 1 if va_copy is available])],,[#include <cstdarg>])
AC_CHECK_FUNCS([vsnprintf _vsnprintf],[break])

###########################
# Random number generator #
Expand Down
2 changes: 0 additions & 2 deletions doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -2353,9 +2353,7 @@ PREDEFINED = IPOPT_HAS_ASL \
HAVE_DLFCN_H \
HAVE_DRAND48 \
HAVE_PARDISO \
HAVE_SNPRINTF \
HAVE_VA_COPY \
HAVE_VSNPRINTF \
HAVE_WSMP \
F77_FUNC(x)=x \
IPOPT_LAPACK_FUNC(x)=x \
Expand Down
45 changes: 2 additions & 43 deletions src/Common/IpUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
#include <csignal>
#include <limits>

// The special treatment of vsnprintf on SUN has been suggested by Lou Hafer 2010/07/04
#if defined(HAVE_VSNPRINTF) && defined(__SUNPRO_CC)
namespace std
{
#include <iso/stdio_c99.h>
}
#if defined(_MSC_VER) && _MSC_VER < 1900
#define vsnprintf _vsnprintf
#endif

// The following code has been copied from CoinUtils' CoinTime
Expand Down Expand Up @@ -313,47 +309,10 @@ int Snprintf(
...
)
{
#if defined(HAVE_VSNPRINTF) && defined(__SUNPRO_CC)
std::va_list ap;
#else
va_list ap;
#endif
va_start(ap, format);
int ret;
#ifdef IPOPT_HAS_VA_COPY
va_list apcopy;
va_copy(apcopy, ap);
# ifdef HAVE_VSNPRINTF
# ifdef __SUNPRO_CC
ret = std::vsnprintf(str, size, format, apcopy);
# else
ret = vsnprintf(str, size, format, apcopy);
# endif
# else
# ifdef HAVE__VSNPRINTF
ret = _vsnprintf(str, size, format, apcopy);
# else
ret = vsprintf(str, format, apcopy);
(void) size;
# endif
# endif
va_end(apcopy);
#else
# ifdef HAVE_VSNPRINTF
# ifdef __SUNPRO_CC
ret = std::vsnprintf(str, size, format, ap);
# else
ret = vsnprintf(str, size, format, ap);
# endif
# else
# ifdef HAVE__VSNPRINTF
ret = _vsnprintf(str, size, format, ap);
# else
ret = vsprintf(str, format, ap);
(void) size;
# endif
# endif
#endif
va_end(ap);
return ret;
}
Expand Down
6 changes: 0 additions & 6 deletions src/Common/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H

/* Define to 1 if you have the 'vsnprintf' function. */
#undef HAVE_VSNPRINTF

/* Define to 1 if windows.h is available. */
#undef HAVE_WINDOWS_H

/* Define to 1 if you have the '_vsnprintf' function. */
#undef HAVE__VSNPRINTF

/* Library Visibility Attribute */
#undef HSLLIB_EXPORT

Expand Down

0 comments on commit 893b3f2

Please sign in to comment.