xref: /aosp_15_r20/external/icu/libicu/cts_headers/ucln_imp.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker *
6*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2009-2011, International Business Machines
7*0e209d39SAndroid Build Coastguard Worker *                Corporation and others. All Rights Reserved.
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
10*0e209d39SAndroid Build Coastguard Worker *   file name:  ucln_imp.h
11*0e209d39SAndroid Build Coastguard Worker *   encoding:   UTF-8
12*0e209d39SAndroid Build Coastguard Worker *   tab size:   8 (not used)
13*0e209d39SAndroid Build Coastguard Worker *   indentation:4
14*0e209d39SAndroid Build Coastguard Worker *
15*0e209d39SAndroid Build Coastguard Worker *   This file contains the platform specific implementation of per-library cleanup.
16*0e209d39SAndroid Build Coastguard Worker *
17*0e209d39SAndroid Build Coastguard Worker */
18*0e209d39SAndroid Build Coastguard Worker 
19*0e209d39SAndroid Build Coastguard Worker 
20*0e209d39SAndroid Build Coastguard Worker #ifndef __UCLN_IMP_H__
21*0e209d39SAndroid Build Coastguard Worker #define __UCLN_IMP_H__
22*0e209d39SAndroid Build Coastguard Worker 
23*0e209d39SAndroid Build Coastguard Worker #include "ucln.h"
24*0e209d39SAndroid Build Coastguard Worker #include <stdlib.h>
25*0e209d39SAndroid Build Coastguard Worker 
26*0e209d39SAndroid Build Coastguard Worker /**
27*0e209d39SAndroid Build Coastguard Worker  * Auto cleanup of ICU libraries
28*0e209d39SAndroid Build Coastguard Worker  * There are several methods in per library cleanup of icu libraries:
29*0e209d39SAndroid Build Coastguard Worker  * 1) Compiler/Platform based cleanup:
30*0e209d39SAndroid Build Coastguard Worker  *   a) Windows MSVC uses DllMain()
31*0e209d39SAndroid Build Coastguard Worker  *   b) GCC uses destructor function attribute
32*0e209d39SAndroid Build Coastguard Worker  *   c) Sun Studio, AIX VA, and HP-UX aCC uses a linker option to set the exit function
33*0e209d39SAndroid Build Coastguard Worker  * 2) Using atexit()
34*0e209d39SAndroid Build Coastguard Worker  * 3) Implementing own automatic cleanup functions
35*0e209d39SAndroid Build Coastguard Worker  *
36*0e209d39SAndroid Build Coastguard Worker  * For option 1, ensure that UCLN_NO_AUTO_CLEANUP is set to 0 by using --enable-auto-cleanup
37*0e209d39SAndroid Build Coastguard Worker  * configure option or by otherwise setting UCLN_NO_AUTO_CLEANUP to 0
38*0e209d39SAndroid Build Coastguard Worker  * For option 2, follow option 1 and also define UCLN_AUTO_ATEXIT
39*0e209d39SAndroid Build Coastguard Worker  * For option 3, follow option 1 and also define UCLN_AUTO_LOCAL (see below for more information)
40*0e209d39SAndroid Build Coastguard Worker  */
41*0e209d39SAndroid Build Coastguard Worker 
42*0e209d39SAndroid Build Coastguard Worker #if !UCLN_NO_AUTO_CLEANUP
43*0e209d39SAndroid Build Coastguard Worker 
44*0e209d39SAndroid Build Coastguard Worker /*
45*0e209d39SAndroid Build Coastguard Worker  * The following declarations are for when UCLN_AUTO_LOCAL or UCLN_AUTO_ATEXIT
46*0e209d39SAndroid Build Coastguard Worker  * are defined. They are commented out because they are static and will be defined
47*0e209d39SAndroid Build Coastguard Worker  * later. The information is still here to provide some guidance for the developer
48*0e209d39SAndroid Build Coastguard Worker  * who chooses to use UCLN_AUTO_LOCAL.
49*0e209d39SAndroid Build Coastguard Worker  */
50*0e209d39SAndroid Build Coastguard Worker /**
51*0e209d39SAndroid Build Coastguard Worker  * Give the library an opportunity to register an automatic cleanup.
52*0e209d39SAndroid Build Coastguard Worker  * This may be called more than once.
53*0e209d39SAndroid Build Coastguard Worker  */
54*0e209d39SAndroid Build Coastguard Worker /*static void ucln_registerAutomaticCleanup();*/
55*0e209d39SAndroid Build Coastguard Worker /**
56*0e209d39SAndroid Build Coastguard Worker  * Unregister an automatic cleanup, if possible. Called from cleanup.
57*0e209d39SAndroid Build Coastguard Worker  */
58*0e209d39SAndroid Build Coastguard Worker /*static void ucln_unRegisterAutomaticCleanup();*/
59*0e209d39SAndroid Build Coastguard Worker 
60*0e209d39SAndroid Build Coastguard Worker #ifdef UCLN_TYPE_IS_COMMON
61*0e209d39SAndroid Build Coastguard Worker #   define UCLN_CLEAN_ME_UP u_cleanup()
62*0e209d39SAndroid Build Coastguard Worker #else
63*0e209d39SAndroid Build Coastguard Worker #   define UCLN_CLEAN_ME_UP ucln_cleanupOne(UCLN_TYPE)
64*0e209d39SAndroid Build Coastguard Worker #endif
65*0e209d39SAndroid Build Coastguard Worker 
66*0e209d39SAndroid Build Coastguard Worker /* ------------ automatic cleanup: registration. Choose ONE ------- */
67*0e209d39SAndroid Build Coastguard Worker #if defined(UCLN_AUTO_LOCAL)
68*0e209d39SAndroid Build Coastguard Worker /* To use:
69*0e209d39SAndroid Build Coastguard Worker  *  1. define UCLN_AUTO_LOCAL,
70*0e209d39SAndroid Build Coastguard Worker  *  2. create ucln_local_hook.c containing implementations of
71*0e209d39SAndroid Build Coastguard Worker  *           static void ucln_registerAutomaticCleanup()
72*0e209d39SAndroid Build Coastguard Worker  *           static void ucln_unRegisterAutomaticCleanup()
73*0e209d39SAndroid Build Coastguard Worker  */
74*0e209d39SAndroid Build Coastguard Worker #include "ucln_local_hook.c"
75*0e209d39SAndroid Build Coastguard Worker 
76*0e209d39SAndroid Build Coastguard Worker #elif defined(UCLN_AUTO_ATEXIT)
77*0e209d39SAndroid Build Coastguard Worker /*
78*0e209d39SAndroid Build Coastguard Worker  * Use the ANSI C 'atexit' function. Note that this mechanism does not
79*0e209d39SAndroid Build Coastguard Worker  * guarantee the order of cleanup relative to other users of ICU!
80*0e209d39SAndroid Build Coastguard Worker  */
81*0e209d39SAndroid Build Coastguard Worker static UBool gAutoCleanRegistered = false;
82*0e209d39SAndroid Build Coastguard Worker 
ucln_atexit_handler()83*0e209d39SAndroid Build Coastguard Worker static void ucln_atexit_handler()
84*0e209d39SAndroid Build Coastguard Worker {
85*0e209d39SAndroid Build Coastguard Worker     UCLN_CLEAN_ME_UP;
86*0e209d39SAndroid Build Coastguard Worker }
87*0e209d39SAndroid Build Coastguard Worker 
ucln_registerAutomaticCleanup()88*0e209d39SAndroid Build Coastguard Worker static void ucln_registerAutomaticCleanup()
89*0e209d39SAndroid Build Coastguard Worker {
90*0e209d39SAndroid Build Coastguard Worker     if(!gAutoCleanRegistered) {
91*0e209d39SAndroid Build Coastguard Worker         gAutoCleanRegistered = true;
92*0e209d39SAndroid Build Coastguard Worker         atexit(&ucln_atexit_handler);
93*0e209d39SAndroid Build Coastguard Worker     }
94*0e209d39SAndroid Build Coastguard Worker }
95*0e209d39SAndroid Build Coastguard Worker 
ucln_unRegisterAutomaticCleanup()96*0e209d39SAndroid Build Coastguard Worker static void ucln_unRegisterAutomaticCleanup () {
97*0e209d39SAndroid Build Coastguard Worker }
98*0e209d39SAndroid Build Coastguard Worker /* ------------end of automatic cleanup: registration. ------- */
99*0e209d39SAndroid Build Coastguard Worker 
100*0e209d39SAndroid Build Coastguard Worker #elif defined (UCLN_FINI)
101*0e209d39SAndroid Build Coastguard Worker /**
102*0e209d39SAndroid Build Coastguard Worker  * If UCLN_FINI is defined, it is the (versioned, etc) name of a cleanup
103*0e209d39SAndroid Build Coastguard Worker  * entrypoint. Add a stub to call ucln_cleanupOne
104*0e209d39SAndroid Build Coastguard Worker  * Used on AIX, Solaris, and HP-UX
105*0e209d39SAndroid Build Coastguard Worker  */
106*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 UCLN_FINI (void);
107*0e209d39SAndroid Build Coastguard Worker 
UCLN_FINI()108*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 UCLN_FINI ()
109*0e209d39SAndroid Build Coastguard Worker {
110*0e209d39SAndroid Build Coastguard Worker     /* This function must be defined, if UCLN_FINI is defined, else link error. */
111*0e209d39SAndroid Build Coastguard Worker      UCLN_CLEAN_ME_UP;
112*0e209d39SAndroid Build Coastguard Worker }
113*0e209d39SAndroid Build Coastguard Worker 
114*0e209d39SAndroid Build Coastguard Worker /* Windows: DllMain */
115*0e209d39SAndroid Build Coastguard Worker #elif U_PLATFORM_HAS_WIN32_API
116*0e209d39SAndroid Build Coastguard Worker /*
117*0e209d39SAndroid Build Coastguard Worker  * ICU's own DllMain.
118*0e209d39SAndroid Build Coastguard Worker  */
119*0e209d39SAndroid Build Coastguard Worker 
120*0e209d39SAndroid Build Coastguard Worker /* these are from putil.c */
121*0e209d39SAndroid Build Coastguard Worker /* READ READ READ READ!    Are you getting compilation errors from windows.h?
122*0e209d39SAndroid Build Coastguard Worker           Any source file which includes this (ucln_imp.h) header MUST
123*0e209d39SAndroid Build Coastguard Worker           be defined with language extensions ON. */
124*0e209d39SAndroid Build Coastguard Worker #ifndef WIN32_LEAN_AND_MEAN
125*0e209d39SAndroid Build Coastguard Worker #   define WIN32_LEAN_AND_MEAN
126*0e209d39SAndroid Build Coastguard Worker #endif
127*0e209d39SAndroid Build Coastguard Worker #   define VC_EXTRALEAN
128*0e209d39SAndroid Build Coastguard Worker #   define NOUSER
129*0e209d39SAndroid Build Coastguard Worker #   define NOSERVICE
130*0e209d39SAndroid Build Coastguard Worker #   define NOIME
131*0e209d39SAndroid Build Coastguard Worker #   define NOMCX
132*0e209d39SAndroid Build Coastguard Worker #   include <windows.h>
133*0e209d39SAndroid Build Coastguard Worker /*
134*0e209d39SAndroid Build Coastguard Worker  * This is a stub DllMain function with icu specific process handling code.
135*0e209d39SAndroid Build Coastguard Worker  */
DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)136*0e209d39SAndroid Build Coastguard Worker BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
137*0e209d39SAndroid Build Coastguard Worker {
138*0e209d39SAndroid Build Coastguard Worker     BOOL status = true;
139*0e209d39SAndroid Build Coastguard Worker 
140*0e209d39SAndroid Build Coastguard Worker     switch(fdwReason) {
141*0e209d39SAndroid Build Coastguard Worker         case DLL_PROCESS_ATTACH:
142*0e209d39SAndroid Build Coastguard Worker              /* ICU does not trap process attach, but must pass these through properly. */
143*0e209d39SAndroid Build Coastguard Worker             /* ICU specific process attach could go here */
144*0e209d39SAndroid Build Coastguard Worker             break;
145*0e209d39SAndroid Build Coastguard Worker 
146*0e209d39SAndroid Build Coastguard Worker         case DLL_PROCESS_DETACH:
147*0e209d39SAndroid Build Coastguard Worker             /* Here is the one we actually care about. */
148*0e209d39SAndroid Build Coastguard Worker 
149*0e209d39SAndroid Build Coastguard Worker             UCLN_CLEAN_ME_UP;
150*0e209d39SAndroid Build Coastguard Worker 
151*0e209d39SAndroid Build Coastguard Worker             break;
152*0e209d39SAndroid Build Coastguard Worker 
153*0e209d39SAndroid Build Coastguard Worker         case DLL_THREAD_ATTACH:
154*0e209d39SAndroid Build Coastguard Worker             /* ICU does not trap thread attach, but must pass these through properly. */
155*0e209d39SAndroid Build Coastguard Worker             /* ICU specific thread attach could go here */
156*0e209d39SAndroid Build Coastguard Worker             break;
157*0e209d39SAndroid Build Coastguard Worker 
158*0e209d39SAndroid Build Coastguard Worker         case DLL_THREAD_DETACH:
159*0e209d39SAndroid Build Coastguard Worker             /* ICU does not trap thread detach, but must pass these through properly. */
160*0e209d39SAndroid Build Coastguard Worker             /* ICU specific thread detach could go here */
161*0e209d39SAndroid Build Coastguard Worker             break;
162*0e209d39SAndroid Build Coastguard Worker 
163*0e209d39SAndroid Build Coastguard Worker     }
164*0e209d39SAndroid Build Coastguard Worker     return status;
165*0e209d39SAndroid Build Coastguard Worker }
166*0e209d39SAndroid Build Coastguard Worker 
167*0e209d39SAndroid Build Coastguard Worker #elif defined(__GNUC__)
168*0e209d39SAndroid Build Coastguard Worker /* GCC - use __attribute((destructor)) */
169*0e209d39SAndroid Build Coastguard Worker static void ucln_destructor()   __attribute__((destructor)) ;
170*0e209d39SAndroid Build Coastguard Worker 
ucln_destructor()171*0e209d39SAndroid Build Coastguard Worker static void ucln_destructor()
172*0e209d39SAndroid Build Coastguard Worker {
173*0e209d39SAndroid Build Coastguard Worker     UCLN_CLEAN_ME_UP;
174*0e209d39SAndroid Build Coastguard Worker }
175*0e209d39SAndroid Build Coastguard Worker 
176*0e209d39SAndroid Build Coastguard Worker #endif
177*0e209d39SAndroid Build Coastguard Worker 
178*0e209d39SAndroid Build Coastguard Worker #endif /* UCLN_NO_AUTO_CLEANUP */
179*0e209d39SAndroid Build Coastguard Worker 
180*0e209d39SAndroid Build Coastguard Worker #else
181*0e209d39SAndroid Build Coastguard Worker #error This file can only be included once.
182*0e209d39SAndroid Build Coastguard Worker #endif
183