Skip to content

Commit

Permalink
Use more specialized API flags for template classes (bug #61711).
Browse files Browse the repository at this point in the history
* oct-conf-post-public.in.h: Add more specific attributes for exporting
(specialized) template class instantiations.
* liboctave/array/Array.h (Array<T>): Also dllexport member function definitions
(on Windows).
* Array-*.cc: Move extern template class declarations to before including
"Array-base.cc" to avoid some implicit instantiations.
* all files: Use new macros for visibility attributes.
  • Loading branch information
mmuetzel committed Nov 5, 2022
1 parent 8899b78 commit 9562cef
Show file tree
Hide file tree
Showing 33 changed files with 418 additions and 251 deletions.
7 changes: 3 additions & 4 deletions libinterp/template-inst/Array-tc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
# include "config.h"
#endif

#include "Array.h"
#include "Array-oct.cc"

#include "ov.h"
Expand All @@ -45,13 +44,13 @@
#endif

NO_INSTANTIATE_ARRAY_SORT_API (octave_value, OCTINTERP_API);
INSTANTIATE_ARRAY (octave_value, OCTINTERP_API);
INSTANTIATE_ARRAY (octave_value, OCTINTERP_CLASS_TEMPLATE_INSTANTIATION_API);

NO_INSTANTIATE_ARRAY_SORT_API (octave_value *, OCTINTERP_API);
INSTANTIATE_ARRAY (octave_value *, OCTINTERP_API);
INSTANTIATE_ARRAY (octave_value *, OCTINTERP_CLASS_TEMPLATE_INSTANTIATION_API);

NO_INSTANTIATE_ARRAY_SORT_API (octave::cdef_object, OCTINTERP_API);
INSTANTIATE_ARRAY (octave::cdef_object, OCTINTERP_API);
INSTANTIATE_ARRAY (octave::cdef_object, OCTINTERP_CLASS_TEMPLATE_INSTANTIATION_API);

#if defined (HAVE_PRAGMA_GCC_VISIBILITY)
# pragma GCC visibility pop
Expand Down
6 changes: 3 additions & 3 deletions libinterp/template-inst/Array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// being implicitly instantiated in compilation units including this file.

// instantiated in Array-tc.cc
extern template class Array<octave_value>;
extern template class Array<octave_value *>;
extern template class Array<octave::cdef_object>;
extern template class OCTINTERP_EXTERN_TEMPLATE_API Array<octave_value>;
extern template class OCTINTERP_EXTERN_TEMPLATE_API Array<octave_value *>;
extern template class OCTINTERP_EXTERN_TEMPLATE_API Array<octave::cdef_object>;
9 changes: 5 additions & 4 deletions liboctave/array/Array-C.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
#include "lo-mappers.h"

#include "Array.h"
#include "Array-base.cc"
#include "oct-sort.cc"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class Array<octave::idx_vector>;
extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
extern template class Array<octave_idx_type>;

#include "Array-base.cc"
#include "oct-sort.cc"

template <>
inline bool
sort_isnan<Complex> (const Complex& x)
Expand Down Expand Up @@ -94,7 +95,7 @@ safe_comparator (sortmode mode, const Array<Complex>& a, bool allow_chk)

template class octave_sort<Complex>;

INSTANTIATE_ARRAY (Complex, OCTAVE_API);
INSTANTIATE_ARRAY (Complex, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);

template OCTAVE_API std::ostream& operator << (std::ostream&,
const Array<Complex>&);
Expand Down
15 changes: 8 additions & 7 deletions liboctave/array/Array-b.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@
// Instantiate Arrays of bool values.

#include "Array.h"
#include "Array-base.cc"

#define INLINE_ASCENDING_SORT 1
#define INLINE_DESCENDING_SORT 1
#include "oct-sort.cc"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class Array<octave::idx_vector>;
extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
extern template class Array<octave_idx_type>;

#include "Array-base.cc"

#define INLINE_ASCENDING_SORT 1
#define INLINE_DESCENDING_SORT 1
#include "oct-sort.cc"

// Specialize bool sorting (aka stable partitioning).

template <bool desc>
Expand Down Expand Up @@ -120,7 +121,7 @@ octave_sort<bool>::sort (bool *data, octave_idx_type *idx, octave_idx_type nel,

template class octave_sort<bool>;

INSTANTIATE_ARRAY (bool, OCTAVE_API);
INSTANTIATE_ARRAY (bool, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);

template OCTAVE_API std::ostream& operator << (std::ostream&,
const Array<bool>&);
Expand Down
10 changes: 1 addition & 9 deletions liboctave/array/Array-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2792,19 +2792,11 @@ void Array<T, Alloc>::instantiation_guard ()
T::__xXxXx__ ();
}

#if defined (__clang__)
# define INSTANTIATE_ARRAY(T, API) \
#define INSTANTIATE_ARRAY(T, API) \
template <> API void \
Array<T>::instantiation_guard () { } \
\
template class API Array<T>
#else
# define INSTANTIATE_ARRAY(T, API) \
template <> API void \
Array<T>::instantiation_guard () { } \
\
template class Array<T>
#endif

// FIXME: is this used?

Expand Down
15 changes: 8 additions & 7 deletions liboctave/array/Array-ch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@
// Instantiate Arrays of char values.

#include "Array.h"
#include "Array-base.cc"

#define INLINE_ASCENDING_SORT 1
#define INLINE_DESCENDING_SORT 1
#include "oct-sort.cc"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class Array<octave::idx_vector>;
extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
extern template class Array<octave_idx_type>;

#include "Array-base.cc"

#define INLINE_ASCENDING_SORT 1
#define INLINE_DESCENDING_SORT 1
#include "oct-sort.cc"

template class octave_sort<char>;

INSTANTIATE_ARRAY (char, OCTAVE_API);
INSTANTIATE_ARRAY (char, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);

template OCTAVE_API std::ostream& operator << (std::ostream&,
const Array<char>&);
Expand Down
15 changes: 8 additions & 7 deletions liboctave/array/Array-d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@

#include "lo-mappers.h"
#include "Array.h"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
extern template class Array<octave_idx_type>;

#include "Array-base.cc"
#include "oct-locbuf.h"

#define INLINE_ASCENDING_SORT 1
#define INLINE_DESCENDING_SORT 1
#include "oct-sort.cc"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class Array<octave::idx_vector>;
extern template class Array<octave_idx_type>;

template <>
inline bool
sort_isnan<double> (double x)
Expand Down Expand Up @@ -165,7 +166,7 @@ Array<double>::issorted (sortmode mode) const

template class octave_sort<double>;

INSTANTIATE_ARRAY (double, OCTAVE_API);
INSTANTIATE_ARRAY (double, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);

template OCTAVE_API std::ostream& operator << (std::ostream&,
const Array<double>&);
Expand Down
15 changes: 8 additions & 7 deletions liboctave/array/Array-f.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@

#include "lo-mappers.h"
#include "Array.h"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
extern template class Array<octave_idx_type>;

#include "Array-base.cc"
#include "oct-locbuf.h"

#define INLINE_ASCENDING_SORT 1
#define INLINE_DESCENDING_SORT 1
#include "oct-sort.cc"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class Array<octave::idx_vector>;
extern template class Array<octave_idx_type>;

template <>
inline bool
sort_isnan<float> (float x)
Expand Down Expand Up @@ -165,7 +166,7 @@ Array<float>::issorted (sortmode mode) const

template class octave_sort<float>;

INSTANTIATE_ARRAY (float, OCTAVE_API);
INSTANTIATE_ARRAY (float, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);

template OCTAVE_API std::ostream& operator << (std::ostream&,
const Array<float>&);
Expand Down
9 changes: 5 additions & 4 deletions liboctave/array/Array-fC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
#include "lo-mappers.h"

#include "Array.h"
#include "Array-base.cc"
#include "oct-sort.cc"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class Array<octave::idx_vector>;
extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;
extern template class Array<octave_idx_type>;

#include "Array-base.cc"
#include "oct-sort.cc"

template <>
inline bool
sort_isnan<FloatComplex> (const FloatComplex& x)
Expand Down Expand Up @@ -94,7 +95,7 @@ safe_comparator (sortmode mode, const Array<FloatComplex>& a, bool allow_chk)

template class octave_sort<FloatComplex>;

INSTANTIATE_ARRAY (FloatComplex, OCTAVE_API);
INSTANTIATE_ARRAY (FloatComplex, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);

template OCTAVE_API std::ostream& operator << (std::ostream&,
const Array<FloatComplex>&);
Expand Down
4 changes: 2 additions & 2 deletions liboctave/array/Array-fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
# include <memory_resource>

template <typename T, typename Alloc = std::pmr::polymorphic_allocator<T>>
class OCTARRAY_API Array;
class OCTAVE_TEMPLATE_API Array;

#else
# include <memory>

template <typename T, typename Alloc = std::allocator<T>>
class OCTARRAY_API Array;
class OCTAVE_TEMPLATE_API Array;

#endif

Expand Down
47 changes: 24 additions & 23 deletions liboctave/array/Array-i.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@
// Instantiate Arrays of integer values.

#include "Array.h"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class OCTAVE_EXTERN_TEMPLATE_API Array<octave::idx_vector>;

#include "Array-base.cc"

#define INLINE_ASCENDING_SORT 1
#define INLINE_DESCENDING_SORT 1
#include "oct-sort.cc"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class Array<octave::idx_vector>;

template class octave_sort<signed char>;
//template class octave_sort<short>;
template class octave_sort<int>;
Expand All @@ -51,12 +52,12 @@ template class octave_sort<long>;
template class octave_sort<long long>;
#endif

INSTANTIATE_ARRAY (signed char, OCTAVE_API);
//INSTANTIATE_ARRAY (short, OCTAVE_API);
INSTANTIATE_ARRAY (int, OCTAVE_API);
INSTANTIATE_ARRAY (long, OCTAVE_API);
INSTANTIATE_ARRAY (signed char, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
//INSTANTIATE_ARRAY (short, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (int, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (long, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
#if defined (OCTAVE_HAVE_LONG_LONG_INT)
INSTANTIATE_ARRAY (long long, OCTAVE_API);
INSTANTIATE_ARRAY (long long, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
#endif

template class octave_sort<unsigned char>;
Expand All @@ -67,33 +68,33 @@ template class octave_sort<unsigned long>;
template class octave_sort<unsigned long long>;
#endif

INSTANTIATE_ARRAY (unsigned char, OCTAVE_API);
INSTANTIATE_ARRAY (unsigned short, OCTAVE_API);
INSTANTIATE_ARRAY (unsigned int, OCTAVE_API);
INSTANTIATE_ARRAY (unsigned long, OCTAVE_API);
INSTANTIATE_ARRAY (unsigned char, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (unsigned short, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (unsigned int, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (unsigned long, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
#if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
INSTANTIATE_ARRAY (unsigned long long, OCTAVE_API);
INSTANTIATE_ARRAY (unsigned long long, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
#endif

template class octave_sort<octave_int8>;
template class octave_sort<octave_int16>;
template class octave_sort<octave_int32>;
template class octave_sort<octave_int64>;

INSTANTIATE_ARRAY (octave_int8, OCTAVE_API);
INSTANTIATE_ARRAY (octave_int16, OCTAVE_API);
INSTANTIATE_ARRAY (octave_int32, OCTAVE_API);
INSTANTIATE_ARRAY (octave_int64, OCTAVE_API);
INSTANTIATE_ARRAY (octave_int8, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (octave_int16, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (octave_int32, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (octave_int64, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);

template class octave_sort<octave_uint8>;
template class octave_sort<octave_uint16>;
template class octave_sort<octave_uint32>;
template class octave_sort<octave_uint64>;

INSTANTIATE_ARRAY (octave_uint8, OCTAVE_API);
INSTANTIATE_ARRAY (octave_uint16, OCTAVE_API);
INSTANTIATE_ARRAY (octave_uint32, OCTAVE_API);
INSTANTIATE_ARRAY (octave_uint64, OCTAVE_API);
INSTANTIATE_ARRAY (octave_uint8, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (octave_uint16, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (octave_uint32, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
INSTANTIATE_ARRAY (octave_uint64, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);

#include "DiagArray2.h"
#include "DiagArray2.cc"
Expand Down
5 changes: 3 additions & 2 deletions liboctave/array/Array-idx-vec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
#include "idx-vector.h"

#include "Array.h"
#include "Array-base.cc"

// Prevent implicit instantiations on some systems (Windows, others?)
// that can lead to duplicate definitions of static data members.

extern template class Array<octave_idx_type>;

#include "Array-base.cc"

NO_INSTANTIATE_ARRAY_SORT_API (octave::idx_vector, OCTAVE_API);

INSTANTIATE_ARRAY (octave::idx_vector, OCTAVE_API);
INSTANTIATE_ARRAY (octave::idx_vector, OCTAVE_CLASS_TEMPLATE_INSTANTIATION_API);
Loading

0 comments on commit 9562cef

Please sign in to comment.