ICU API proposal: U_..._API_CLASS macros

10 views
Skip to first unread message

Fredrik Roubert

unread,
Jun 16, 2025, 10:33:04 AMJun 16
to icu-d...@unicode.org
Dear ICU team & users,

I would like to propose the following API for: ICU 78

Please provide feedback by: this Wednesday, 2025-06-18

Designated API reviewer: Markus

Ticket: https://unicode-org.atlassian.net/browse/ICU-23136

utypes.h:


#ifndef U_FORCE_HIDE_DRAFT_API

/**
* \def U_DATA_API_CLASS
* Set to export library symbols from inside the stubdata library,
* and to import them from outside, to be used on a class.
* @draft ICU 78
*/

/**
* \def U_COMMON_API_CLASS
* Set to export library symbols from inside the common library,
* and to import them from outside, to be used on a class.
* @draft ICU 78
*/

/**
* \def U_I18N_API_CLASS
* Set to export library symbols from inside the i18n library,
* and to import them from outside, to be used on a class.
* @draft ICU 78
*/

/**
* \def U_LAYOUT_API_CLASS
* Set to export library symbols from inside the layout engine library,
* and to import them from outside, to be used on a class.
* @draft ICU 78
*/

/**
* \def U_LAYOUTEX_API_CLASS
* Set to export library symbols from inside the layout extensions library,
* and to import them from outside, to be used on a class.
* @draft ICU 78
*/

/**
* \def U_IO_API_CLASS
* Set to export library symbols from inside the ustdio library,
* and to import them from outside, to be used on a class.
* @draft ICU 78
*/

/**
* \def U_TOOLUTIL_API_CLASS
* Set to export library symbols from inside the toolutil library,
* and to import them from outside, to be used on a class.
* @draft ICU 78
*/

// When used on Windows, the U_..._API macros expand to __declspec(dllexport)
// and __declspec(dllimport), which when used on a class results in all members
// of the class being exported, including private members, which is problematic
// for classes that have private members that can't be exported (such as
// templates from the standard library):
//
// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4251
//
#if U_PLATFORM_HAS_WIN32_API
#define U_DATA_API_CLASS
#define U_COMMON_API_CLASS
#define U_I18N_API_CLASS
#define U_LAYOUT_API_CLASS
#define U_LAYOUTEX_API_CLASS
#define U_IO_API_CLASS
#define U_TOOLUTIL_API_CLASS
#else
#define U_DATA_API_CLASS U_DATA_API
#define U_COMMON_API_CLASS U_COMMON_API
#define U_I18N_API_CLASS U_I18N_API
#define U_LAYOUT_API_CLASS U_LAYOUT_API
#define U_LAYOUTEX_API_CLASS U_LAYOUTEX_API
#define U_IO_API_CLASS U_IO_API
#define U_TOOLUTIL_API_CLASS U_TOOLUTIL_API
#endif

#endif // U_FORCE_HIDE_DRAFT_API


https://github.com/unicode-org/icu/pull/3521

--
Fredrik Roubert
rou...@google.com

Markus Scherer

unread,
Jun 16, 2025, 2:55:11 PMJun 16
to Fredrik Roubert, icu-d...@unicode.org
Thanks, lgtm.
By way of explanation, Fredrik is working on more fine-grained DLL export, so that private members of public classes can use some STL types.
We still need class-level export specifiers on most platforms, but member-level export specifiers on Windows.
These new macros are platform-specific for that purpose.

markus
Reply all
Reply to author
Forward
0 new messages