Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ jobs:
- name: Build
run: cmake --build build --config ${{ matrix.build_type }}

# Every exported symbol must be public or carry the pslp_ prefix
- name: Check exported symbols
if: runner.os != 'Windows'
run: sh cmake/pslp_symbols.sh check build/libPSLP.*

- name: Run tests
run: cd build && ctest -C ${{ matrix.build_type }} --verbose
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ target_include_directories(PSLP
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/explorers/fold>
)

# Prefix the internal symbols with pslp_, so that they cannot clash with the
# symbols of a program that embeds PSLP. The header is generated by
# cmake/pslp_symbols.sh and must be seen by every source file that uses an
# internal function, hence the forced include.
set(PSLP_NAMESPACE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/core/pslp_namespace.h)
if (MSVC)
set(PSLP_FORCE_INCLUDE /FI${PSLP_NAMESPACE_HEADER})
else()
set(PSLP_FORCE_INCLUDE -include ${PSLP_NAMESPACE_HEADER})
endif()
target_compile_options(PSLP PRIVATE ${PSLP_FORCE_INCLUDE})

# Common compile options
if (MSVC)
target_compile_options(PSLP PRIVATE /W4)
Expand Down Expand Up @@ -168,6 +180,8 @@ if(PSLP_BUILD_TESTING)
)

target_compile_definitions(all_tests PRIVATE TESTING)
# the tests call internal functions, so they need the same renames
target_compile_options(all_tests PRIVATE ${PSLP_FORCE_INCLUDE})

add_test(NAME all_tests COMMAND all_tests)
else()
Expand Down
123 changes: 123 additions & 0 deletions cmake/pslp_symbols.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/sh
# Keeps the symbols that libPSLP exports free of name clashes.
#
# Every function with external linkage that is not part of the public API
# (cmake/public_symbols.txt) gets the prefix pslp_ through the generated header
# include/core/pslp_namespace.h, which CMake force-includes into every source
# file of the library and of the tests.
#
# pslp_symbols.sh generate <lib>... rewrite the header from the libraries
# pslp_symbols.sh check <lib>... fail if a symbol is exported unprefixed
#
# After adding or removing a function that is not static, build the library
# and run 'generate' on it. To cover the functions that only exist in some
# configurations, pass both a Release build and a Debug build with
# -DPSLP_BUILD_TESTING=ON.

set -eu

prefix=pslp_
here=$(cd "$(dirname "$0")" && pwd)
public="$here/public_symbols.txt"
header="$here/../include/core/pslp_namespace.h"

usage()
{
sed -n '2,15p' "$0" | sed 's/^# \{0,1\}//'
exit 2
}

# Prints the defined global symbols of the given libraries, one per line.
# Names that start with an underscore belong to the toolchain and are skipped.
exported()
{
if [ "$(uname)" = Darwin ]; then
strip_underscore='s/^_//' # Mach-O puts an underscore before C names
else
strip_underscore=''
fi
for lib in "$@"; do
nm -g "$lib"
done | awk 'NF == 3 && $2 ~ /^[A-TV-Z]$/ { print $3 }' |
sed "$strip_underscore" | { grep -v '^_' || true; } | LC_ALL=C sort -u
}

[ $# -ge 2 ] || usage
mode=$1
shift
for lib in "$@"; do
if [ ! -f "$lib" ]; then
echo "pslp_symbols.sh: no such library: $lib" >&2
exit 1
fi
done

case $mode in
generate)
names=$(exported "$@" | sed "s/^$prefix//" |
{ grep -vxF -f "$public" || true; } | LC_ALL=C sort -u)
{
cat <<'EOF'
/*
* Copyright 2025-2026 Daniel Cederberg
*
* This file is part of the PSLP project (LP Presolver).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* Generated by cmake/pslp_symbols.sh, do not edit by hand.

Gives every internal function with external linkage the prefix pslp_, so
that the symbols of libPSLP cannot clash with those of a program or library
that embeds it. CMake force-includes this header into every source file of
the library and of the tests; the sources keep using the short names. The
public functions (PSLP_API.h) are not renamed. */

#ifndef PSLP_NAMESPACE_H
#define PSLP_NAMESPACE_H

/* clang-format off */
EOF
for name in $names; do
echo "#define $name $prefix$name"
done
printf '/* clang-format on */\n\n#endif /* PSLP_NAMESPACE_H */\n'
} >"$header"
echo "wrote $(echo "$names" | wc -l | tr -d ' ') names to $header"
;;
check)
symbols=$(exported "$@")
bad=$(echo "$symbols" | grep -v "^$prefix" | grep -vxF -f "$public" || true)
missing=$(echo "$symbols" | LC_ALL=C sort -u |
LC_ALL=C comm -13 - "$public" || true)
status=0
if [ -n "$bad" ]; then
echo "Exported without the $prefix prefix and not in public_symbols.txt:"
echo "$bad" | sed 's/^/ /'
echo "Make the function static, or rebuild and run"
echo " sh cmake/pslp_symbols.sh generate <lib>..."
status=1
fi
if [ -n "$missing" ]; then
echo "Listed in public_symbols.txt but not exported:"
echo "$missing" | sed 's/^/ /'
status=1
fi
[ $status -eq 0 ] && echo "exported symbols OK ($(echo "$symbols" | wc -l | tr -d ' '))"
exit $status
;;
*)
usage
;;
esac
13 changes: 13 additions & 0 deletions cmake/public_symbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
default_settings
free_presolver
free_presolver_reduced_problem
free_settings
map_original_sol_to_reduced
new_presolver
new_presolver_from_problem
postsolve
postsolve_dual_infeas_ray
postsolve_primal_infeas_ray
run_presolver
set_settings_false
set_settings_true
7 changes: 0 additions & 7 deletions include/core/Activity.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,6 @@ Altered_Activity update_activity_coeff_change(Activity *act, double lb, double u
double old_coeff, double new_coeff,
ColTag cTag);

/* Updates the activity struct when a bound changes. */
Altered_Activity update_act_bound_change(Activity *act, double coeff,
double old_bound, double new_bound,
bool finite_bound, bool lower,
const double *vals, const int *cols,
int len, const struct Bound *bounds);

void remove_finite_lb_from_activities(const struct ConstColView *col, Activity *acts,
double bound);

Expand Down
Loading
Loading