apr_pools.inc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. { Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. }
  16. {
  17. * @file apr_pools.h
  18. * @brief APR memory allocation
  19. *
  20. * Resource allocation routines...
  21. *
  22. * designed so that we don't have to keep track of EVERYTHING so that
  23. * it can be explicitly freed later (a fundamentally unsound strategy ---
  24. * particularly in the presence of die()).
  25. *
  26. * Instead, we maintain pools, and allocate items (both memory and I/O
  27. * handlers) from the pools --- currently there are two, one for per
  28. * transaction info, and one for config info. When a transaction is over,
  29. * we can delete everything in the per-transaction apr_pool_t without fear,
  30. * and without thinking too hard about it either.
  31. }
  32. {#include "apr.h"
  33. #include "apr_errno.h"
  34. #include "apr_general.h"{ { for APR_STRINGIFY }
  35. //#include "apr_want.h"
  36. {
  37. * @defgroup apr_pools Memory Pool Functions
  38. * @ingroup APR
  39. * @
  40. }
  41. { The fundamental pool type }
  42. type
  43. apr_pool_t = record end;
  44. Papr_pool_t = ^apr_pool_t;
  45. PPapr_pool_t = ^Papr_pool_t;
  46. {
  47. * Declaration helper macro to construct apr_foo_pool_get()s.
  48. *
  49. * This standardized macro is used by opaque (APR) data types to return
  50. * the apr_pool_t that is associated with the data type.
  51. *
  52. * APR_POOL_DECLARE_ACCESSOR() is used in a header file to declare the
  53. * accessor function. A typical usage and result would be:
  54. * <pre>
  55. * APR_POOL_DECLARE_ACCESSOR(file);
  56. * becomes:
  57. * APR_DECLARE(apr_pool_t *) apr_file_pool_get(apr_file_t *ob);
  58. * </pre>
  59. * @remark Doxygen unwraps this macro (via doxygen.conf) to provide
  60. * actual help for each specific occurance of apr_foo_pool_get.
  61. * @remark the linkage is specified for APR. It would be possible to expand
  62. * the macros to support other linkages.
  63. }
  64. {#define APR_POOL_DECLARE_ACCESSOR(type) \
  65. APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \
  66. (const apr_##type##_t *the##type)
  67. }
  68. {
  69. * Implementation helper macro to provide apr_foo_pool_get()s.
  70. *
  71. * In the implementation, the APR_POOL_IMPLEMENT_ACCESSOR() is used to
  72. * actually define the function. It assumes the field is named "pool".
  73. }
  74. {#define APR_POOL_IMPLEMENT_ACCESSOR(type) \
  75. APR_DECLARE(apr_pool_t *) apr_##type##_pool_get \
  76. (const apr_##type##_t *the##type) \}
  77. { return the##type->pool; }
  78. {
  79. * Pool debug levels
  80. *
  81. * <pre>
  82. * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  83. * ---------------------------------
  84. * | | | | | | | | x | General debug code enabled (usefull in
  85. * combination with --with-efence).
  86. *
  87. * | | | | | | | x | | Verbose output on stderr (report
  88. * CREATE, CLEAR, DESTROY).
  89. *
  90. * | | | | x | | | | | Verbose output on stderr (report
  91. * PALLOC, PCALLOC).
  92. *
  93. * | | | | | | x | | | Lifetime checking. On each use of a
  94. * pool, check its lifetime. If the pool
  95. * is out of scope, abort().
  96. * In combination with the verbose flag
  97. * above, it will output LIFE in such an
  98. * event prior to aborting.
  99. *
  100. * | | | | | x | | | | Pool owner checking. On each use of a
  101. * pool, check if the current thread is the
  102. * pools owner. If not, abort(). In
  103. * combination with the verbose flag above,
  104. * it will output OWNER in such an event
  105. * prior to aborting. Use the debug
  106. * function apr_pool_owner_set() to switch
  107. * a pools ownership.
  108. *
  109. * When no debug level was specified, assume general debug mode.
  110. * If level 0 was specified, debugging is switched off
  111. * </pre>
  112. }
  113. {#if defined(APR_POOL_DEBUG)
  114. #if (APR_POOL_DEBUG != 0) && (APR_POOL_DEBUG - 0 == 0)
  115. #undef APR_POOL_DEBUG
  116. #define APR_POOL_DEBUG 1
  117. #endif
  118. #else
  119. #define APR_POOL_DEBUG 0
  120. #endif
  121. }
  122. { the place in the code where the particular function was called }
  123. //#define APR_POOL__FILE_LINE__ __FILE__ ":" APR_STRINGIFY(__LINE__)
  124. { A function that is called when allocation fails. }
  125. type
  126. apr_abortfunc_t = function (retcode: Integer): Integer;
  127. {
  128. * APR memory structure manipulators (pools, tables, and arrays).
  129. }
  130. {
  131. * Initialization
  132. }
  133. {
  134. * Setup all of the internal structures required to use pools
  135. * @remark Programs do NOT need to call this directly. APR will call this
  136. * automatically from apr_initialize.
  137. * @internal
  138. }
  139. function apr_pool_initialize: apr_status_t;
  140. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  141. external LibAPR name LibNamePrefix + 'apr_pool_initialize' + LibSuff0;
  142. {
  143. * Tear down all of the internal structures required to use pools
  144. * @remark Programs do NOT need to call this directly. APR will call this
  145. * automatically from apr_terminate.
  146. * @internal
  147. }
  148. procedure apr_pool_terminate;
  149. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  150. external LibAPR name LibNamePrefix + 'apr_pool_terminate' + LibSuff0;
  151. {
  152. * Pool creation/destruction
  153. }
  154. {$include apr_allocator.inc}
  155. {
  156. * Create a new pool.
  157. * @param newpool The pool we have just created.
  158. * @param parent The parent pool. If this is NULL, the new pool is a root
  159. * pool. If it is non-NULL, the new pool will inherit all
  160. * of its parent pool's attributes, except the apr_pool_t will
  161. * be a sub-pool.
  162. * @param abort_fn A function to use if the pool cannot allocate more memory.
  163. * @param allocator The allocator to use with the new pool. If NULL the
  164. * allocator of the parent pool will be used.
  165. }
  166. function apr_pool_create_ex(newpool: PPapr_pool_t;
  167. parent: Papr_pool_t; abort_fn: apr_abortfunc_t;
  168. allocator: Papr_allocator_t): apr_status_t;
  169. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  170. external LibAPR name LibNamePrefix + 'apr_pool_create_ex' + LibSuff16;
  171. {
  172. * Debug version of apr_pool_create_ex.
  173. * @param newpool @see apr_pool_create.
  174. * @param parent @see apr_pool_create.
  175. * @param abort_fn @see apr_pool_create.
  176. * @param allocator @see apr_pool_create.
  177. * @param file_line Where the function is called from.
  178. * This is usually APR_POOL__FILE_LINE__.
  179. * @remark Only available when APR_POOL_DEBUG is defined.
  180. * Call this directly if you have you apr_pool_create_ex
  181. * calls in a wrapper function and wish to override
  182. * the file_line argument to reflect the caller of
  183. * your wrapper function. If you do not have
  184. * apr_pool_create_ex in a wrapper, trust the macro
  185. * and don't call apr_pool_create_ex_debug directly.
  186. }
  187. function apr_pool_create_ex_debug(newpool: PPapr_pool_t;
  188. parent: Papr_pool_t; abort_fn: apr_abortfunc_t;
  189. allocator: Papr_allocator_t; const file_line: PChar): apr_status_t;
  190. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  191. external LibAPR name LibNamePrefix + 'apr_pool_create_ex_debug' + LibSuff20;
  192. {#if APR_POOL_DEBUG
  193. #define apr_pool_create_ex(newpool, parent, abort_fn, allocator) \
  194. apr_pool_create_ex_debug(newpool, parent, abort_fn, allocator, \
  195. APR_POOL__FILE_LINE__)
  196. #endif
  197. }
  198. {
  199. * Create a new pool.
  200. * @param newpool The pool we have just created.
  201. * @param parent The parent pool. If this is NULL, the new pool is a root
  202. * pool. If it is non-NULL, the new pool will inherit all
  203. * of its parent pool's attributes, except the apr_pool_t will
  204. * be a sub-pool.
  205. }
  206. {$ifdef DOXYGEN}
  207. function apr_pool_create(newpool: PPapr_pool_t;
  208. parent: Papr_pool_t): apr_status_t;
  209. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  210. external LibAPR name LibNamePrefix + 'apr_pool_create' + LibSuff8;
  211. {$else}
  212. {.$ifdef APR_POOL_DEBUG}
  213. {#define apr_pool_create(newpool, parent) \
  214. apr_pool_create_ex_debug(newpool, parent, NULL, NULL, \
  215. APR_POOL__FILE_LINE__)}
  216. {.$else}
  217. function apr_pool_create(newpool: PPapr_pool_t; parent: Papr_pool_t): apr_status_t;
  218. {.$endif}
  219. {$endif}
  220. { @deprecated @see apr_pool_create_ex }
  221. {#if APR_POOL_DEBUG
  222. #define apr_pool_sub_make(newpool, parent, abort_fn) \
  223. (void)apr_pool_create_ex_debug(newpool, parent, abort_fn, \
  224. NULL, \
  225. APR_POOL__FILE_LINE__)
  226. #else}
  227. function apr_pool_sub_make(newpool: PPapr_pool_t; parent: Papr_pool_t;
  228. abort_fn: apr_abortfunc_t): apr_status_t;
  229. //#endif
  230. {
  231. * Find the pools allocator
  232. * @param pool The pool to get the allocator from.
  233. }
  234. function apr_pool_allocator_get(pool: Papr_pool_t): Papr_allocator_t;
  235. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  236. external LibAPR name LibNamePrefix + 'apr_pool_allocator_get' + LibSuff4;
  237. {
  238. * Clear all memory in the pool and run all the cleanups. This also destroys all
  239. * subpools.
  240. * @param p The pool to clear
  241. * @remark This does not actually free the memory, it just allows the pool
  242. * to re-use this memory for the next allocation.
  243. * @see apr_pool_destroy()
  244. }
  245. procedure apr_pool_clear(p: Papr_pool_t);
  246. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  247. external LibAPR name LibNamePrefix + 'apr_pool_clear' + LibSuff4;
  248. {
  249. * Debug version of apr_pool_clear.
  250. * @param p See: apr_pool_clear.
  251. * @param file_line Where the function is called from.
  252. * This is usually APR_POOL__FILE_LINE__.
  253. * @remark Only available when APR_POOL_DEBUG is defined.
  254. * Call this directly if you have you apr_pool_clear
  255. * calls in a wrapper function and wish to override
  256. * the file_line argument to reflect the caller of
  257. * your wrapper function. If you do not have
  258. * apr_pool_clear in a wrapper, trust the macro
  259. * and don't call apr_pool_destroy_clear directly.
  260. }
  261. procedure apr_pool_clear_debug(p: Papr_pool_t; const file_line: PChar);
  262. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  263. external LibAPR name LibNamePrefix + 'apr_pool_clear_debug' + LibSuff8;
  264. {#if APR_POOL_DEBUG
  265. #define apr_pool_clear(p) \
  266. apr_pool_clear_debug(p, APR_POOL__FILE_LINE__)
  267. #endif}
  268. {
  269. * Destroy the pool. This takes similar action as apr_pool_clear() and then
  270. * frees all the memory.
  271. * @param p The pool to destroy
  272. * @remark This will actually free the memory
  273. }
  274. procedure apr_pool_destroy(p: Papr_pool_t);
  275. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  276. external LibAPR name LibNamePrefix + 'apr_pool_destroy' + LibSuff4;
  277. {
  278. * Debug version of apr_pool_destroy.
  279. * @param p See: apr_pool_destroy.
  280. * @param file_line Where the function is called from.
  281. * This is usually APR_POOL__FILE_LINE__.
  282. * @remark Only available when APR_POOL_DEBUG is defined.
  283. * Call this directly if you have you apr_pool_destroy
  284. * calls in a wrapper function and wish to override
  285. * the file_line argument to reflect the caller of
  286. * your wrapper function. If you do not have
  287. * apr_pool_destroy in a wrapper, trust the macro
  288. * and don't call apr_pool_destroy_debug directly.
  289. }
  290. procedure apr_pool_destroy_debug(p: Papr_pool_t; const file_line: PChar);
  291. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  292. external LibAPR name LibNamePrefix + 'apr_pool_destroy_debug' + LibSuff8;
  293. {#if APR_POOL_DEBUG
  294. #define apr_pool_destroy(p) \
  295. apr_pool_destroy_debug(p, APR_POOL__FILE_LINE__)
  296. #endif}
  297. {
  298. * Memory allocation
  299. }
  300. {
  301. * Allocate a block of memory from a pool
  302. * @param p The pool to allocate from
  303. * @param size The amount of memory to allocate
  304. * @return The allocated memory
  305. }
  306. function apr_palloc(p: Papr_pool_t; size: apr_size_t): Pointer;
  307. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  308. external LibAPR name LibNamePrefix + 'apr_palloc' + LibSuff8;
  309. {
  310. * Debug version of apr_palloc
  311. * @param p See: apr_palloc
  312. * @param size See: apr_palloc
  313. * @param file_line Where the function is called from.
  314. * This is usually APR_POOL__FILE_LINE__.
  315. * @return See: apr_palloc
  316. }
  317. function apr_palloc_debug(p: Papr_pool_t; size: apr_size_t;
  318. const file_line: PChar): Pointer;
  319. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  320. external LibAPR name LibNamePrefix + 'apr_palloc_debug' + LibSuff12;
  321. {#if APR_POOL_DEBUG
  322. #define apr_palloc(p, size) \
  323. apr_palloc_debug(p, size, APR_POOL__FILE_LINE__)
  324. #endif
  325. }
  326. {
  327. * Allocate a block of memory from a pool and set all of the memory to 0
  328. * @param p The pool to allocate from
  329. * @param size The amount of memory to allocate
  330. * @return The allocated memory
  331. }
  332. {#if defined(DOXYGEN)}
  333. function apr_pcalloc(p: Papr_pool_t; size: apr_size_t): Pointer;
  334. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  335. external LibAPR name LibNamePrefix + 'apr_pcalloc' + LibSuff8;
  336. {#elif !APR_POOL_DEBUG
  337. #define apr_pcalloc(p, size) memset(apr_palloc(p, size), 0, size)
  338. #endif
  339. }
  340. {
  341. * Debug version of apr_pcalloc
  342. * @param p See: apr_pcalloc
  343. * @param size See: apr_pcalloc
  344. * @param file_line Where the function is called from.
  345. * This is usually APR_POOL__FILE_LINE__.
  346. * @return See: apr_pcalloc
  347. }
  348. {APR_DECLARE(void *) apr_pcalloc_debug(apr_pool_t *p, apr_size_t size,
  349. const char *file_line);
  350. #if APR_POOL_DEBUG
  351. #define apr_pcalloc(p, size) \
  352. apr_pcalloc_debug(p, size, APR_POOL__FILE_LINE__)
  353. #endif
  354. }
  355. {
  356. * Pool Properties
  357. }
  358. {
  359. * Set the function to be called when an allocation failure occurs.
  360. * @remark If the program wants APR to exit on a memory allocation error,
  361. * then this function can be called to set the callback to use (for
  362. * performing cleanup and then exiting). If this function is not called,
  363. * then APR will return an error and expect the calling program to
  364. * deal with the error accordingly.
  365. }
  366. procedure apr_pool_abort_set(abortfunc: apr_abortfunc_t; pool: Papr_pool_t);
  367. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  368. external LibAPR name LibNamePrefix + 'apr_pool_abort_set' + LibSuff8;
  369. { @deprecated @see apr_pool_abort_set }
  370. {APR_DECLARE(void) apr_pool_set_abort(apr_abortfunc_t abortfunc,
  371. apr_pool_t *pool);
  372. }
  373. {
  374. * Get the abort function associated with the specified pool.
  375. * @param pool The pool for retrieving the abort function.
  376. * @return The abort function for the given pool.
  377. }
  378. function apr_pool_abort_get(pool: Papr_pool_t): apr_abortfunc_t;
  379. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  380. external LibAPR name LibNamePrefix + 'apr_pool_abort_get' + LibSuff4;
  381. { @deprecated @see apr_pool_abort_get }
  382. //APR_DECLARE(apr_abortfunc_t) apr_pool_get_abort(apr_pool_t *pool);
  383. {
  384. * Get the parent pool of the specified pool.
  385. * @param pool The pool for retrieving the parent pool.
  386. * @return The parent of the given pool.
  387. }
  388. function apr_pool_parent_get(pool: Papr_pool_t): Papr_pool_t;
  389. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  390. external LibAPR name LibNamePrefix + 'apr_pool_parent_get' + LibSuff4;
  391. { @deprecated @see apr_pool_parent_get }
  392. //APR_DECLARE(apr_pool_t *) apr_pool_get_parent(apr_pool_t *pool);
  393. {
  394. * Determine if pool a is an ancestor of pool b
  395. * @param a The pool to search
  396. * @param b The pool to search for
  397. * @return True if a is an ancestor of b, NULL is considered an ancestor
  398. * of all pools.
  399. }
  400. function apr_pool_is_ancestor(a, b: Papr_pool_t): Integer;
  401. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  402. external LibAPR name LibNamePrefix + 'apr_pool_is_ancestor' + LibSuff8;
  403. {
  404. * Tag a pool (give it a name)
  405. * @param pool The pool to tag
  406. * @param tag The tag
  407. }
  408. procedure apr_pool_tag(pool: Papr_pool_t; tag: PChar);
  409. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  410. external LibAPR name LibNamePrefix + 'apr_pool_tag' + LibSuff8;
  411. {
  412. * User data management
  413. }
  414. {
  415. * Set the data associated with the current pool
  416. * @param data The user data associated with the pool.
  417. * @param key The key to use for association
  418. * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
  419. * @param pool The current pool
  420. * @warning The data to be attached to the pool should have a life span
  421. * at least as long as the pool it is being attached to.
  422. *
  423. * Users of APR must take EXTREME care when choosing a key to
  424. * use for their data. It is possible to accidentally overwrite
  425. * data by choosing a key that another part of the program is using.
  426. * Therefore it is advised that steps are taken to ensure that unique
  427. * keys are used for all of the userdata objects in a particular pool
  428. * (the same key in two different pools or a pool and one of its
  429. * subpools is okay) at all times. Careful namespace prefixing of
  430. * key names is a typical way to help ensure this uniqueness.
  431. }
  432. //function apr_pool_userdata_set(
  433. // const data: Pointer; const key: PChar;
  434. // cleanup: function(param: Pointer): apr_status_t,
  435. // pool: Papr_pool_t): apr_status_t;
  436. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  437. // external LibAPR name LibNamePrefix + 'apr_pool_userdata_set' + LibSuff20;
  438. {
  439. * Set the data associated with the current pool
  440. * @param data The user data associated with the pool.
  441. * @param key The key to use for association
  442. * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
  443. * @param pool The current pool
  444. * @note same as apr_pool_userdata_set(), except that this version doesn't
  445. * make a copy of the key (this function is useful, for example, when
  446. * the key is a string literal)
  447. * @warning This should NOT be used if the key could change addresses by
  448. * any means between the apr_pool_userdata_setn() call and a
  449. * subsequent apr_pool_userdata_get() on that key, such as if a
  450. * static string is used as a userdata key in a DSO and the DSO could
  451. * be unloaded and reloaded between the _setn() and the _get(). You
  452. * MUST use apr_pool_userdata_set() in such cases.
  453. * @warning More generally, the key and the data to be attached to the
  454. * pool should have a life span at least as long as the pool itself.
  455. *
  456. }
  457. //function apr_pool_userdata_setn(
  458. // const data: Pointer; const key: PChar;
  459. // cleanup: function(param: Pointer): apr_status_t,
  460. // pool: Papr_pool_t): apr_status_t;
  461. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  462. // external LibAPR name LibNamePrefix + 'apr_pool_userdata_setn' + LibSuff20;
  463. {
  464. * Return the data associated with the current pool.
  465. * @param data The user data associated with the pool.
  466. * @param key The key for the data to retrieve
  467. * @param pool The current pool.
  468. }
  469. function apr_pool_userdata_get(data: PPointer; const key: PChar;
  470. pool: Papr_pool_t): apr_status_t;
  471. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  472. external LibAPR name LibNamePrefix + 'apr_pool_userdata_get' + LibSuff12;
  473. {
  474. * Cleanup
  475. *
  476. * Cleanups are performed in the reverse order they were registered. That is:
  477. * Last In, First Out.
  478. }
  479. {
  480. * Register a function to be called when a pool is cleared or destroyed
  481. * @param p The pool register the cleanup with
  482. * @param data The data to pass to the cleanup function.
  483. * @param plain_cleanup The function to call when the pool is cleared
  484. * or destroyed
  485. * @param child_cleanup The function to call when a child process is being
  486. * shutdown - this function is called in the child, obviously!
  487. }
  488. type
  489. plain_cleanup_t = function(param: Pointer): apr_status_t; cdecl;
  490. child_cleanup_t = function(param: Pointer): apr_status_t; cdecl;
  491. procedure apr_pool_cleanup_register(p: Papr_pool_t;
  492. const data: Pointer;
  493. plain_cleanup: plain_cleanup_t;
  494. child_cleanup: child_cleanup_t);
  495. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  496. external LibAPR name LibNamePrefix + 'apr_pool_cleanup_register' + LibSuff16;
  497. {
  498. * Remove a previously registered cleanup function
  499. * @param p The pool remove the cleanup from
  500. * @param data The data to remove from cleanup
  501. * @param cleanup The function to remove from cleanup
  502. * @remarks For some strange reason only the plain_cleanup is handled by this
  503. * function
  504. }
  505. //procedure apr_pool_cleanup_for_exec;
  506. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  507. // external LibAPR name LibNamePrefix + 'apr_pool_cleanup_for_exec' + LibSuff0;
  508. //APR_DECLARE(void) apr_pool_cleanup_kill(apr_pool_t *p, const void *data,
  509. // apr_status_t cleanup)(void );
  510. {
  511. * Replace the child cleanup of a previously registered cleanup
  512. * @param p The pool of the registered cleanup
  513. * @param data The data of the registered cleanup
  514. * @param plain_cleanup The plain cleanup function of the registered cleanup
  515. * @param child_cleanup The function to register as the child cleanup
  516. }
  517. //procedure apr_pool_cleanup_for_exec;
  518. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  519. // external LibAPR name LibNamePrefix + 'apr_pool_cleanup_for_exec' + LibSuff0;
  520. {APR_DECLARE(void) apr_pool_child_cleanup_set(
  521. apr_pool_t *p,
  522. const void *data,
  523. apr_status_t plain_cleanup)(void ,
  524. apr_status_t child_cleanup)(void );
  525. }
  526. {
  527. * Run the specified cleanup function immediately and unregister it. Use
  528. * @a data instead of the data that was registered with the cleanup.
  529. * @param p The pool remove the cleanup from
  530. * @param data The data to remove from cleanup
  531. * @param cleanup The function to remove from cleanup
  532. }
  533. //procedure apr_pool_cleanup_for_exec;
  534. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  535. // external LibAPR name LibNamePrefix + 'apr_pool_cleanup_for_exec' + LibSuff0;
  536. {APR_DECLARE(apr_status_t) apr_pool_cleanup_run(
  537. apr_pool_t *p,
  538. void *data,
  539. apr_status_t cleanup)(void );}
  540. {
  541. * An empty cleanup function
  542. * @param data The data to cleanup
  543. }
  544. //APR_DECLARE_NONSTD(apr_status_t) apr_pool_cleanup_null(void *data);
  545. { Preparing for exec() --- close files, etc., but *don't* flush I/O
  546. * buffers, *don't* wait for subprocesses, and *don't* free any memory.
  547. }
  548. {
  549. * Run all of the child_cleanups, so that any unnecessary files are
  550. * closed because we are about to exec a new program
  551. }
  552. procedure apr_pool_cleanup_for_exec;
  553. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  554. external LibAPR name LibNamePrefix + 'apr_pool_cleanup_for_exec' + LibSuff0;
  555. {
  556. * @defgroup PoolDebug Pool Debugging functions.
  557. *
  558. * pools have nested lifetimes -- sub_pools are destroyed when the
  559. * parent pool is cleared. We allow certain liberties with operations
  560. * on things such as tables (and on other structures in a more general
  561. * sense) where we allow the caller to insert values into a table which
  562. * were not allocated from the table's pool. The table's data will
  563. * remain valid as long as all the pools from which its values are
  564. * allocated remain valid.
  565. *
  566. * For example, if B is a sub pool of A, and you build a table T in
  567. * pool B, then it's safe to insert data allocated in A or B into T
  568. * (because B lives at most as long as A does, and T is destroyed when
  569. * B is cleared/destroyed). On the other hand, if S is a table in
  570. * pool A, it is safe to insert data allocated in A into S, but it
  571. * is *not safe* to insert data allocated from B into S... because
  572. * B can be cleared/destroyed before A is (which would leave dangling
  573. * pointers in T's data structures).
  574. *
  575. * In general we say that it is safe to insert data into a table T
  576. * if the data is allocated in any ancestor of T's pool. This is the
  577. * basis on which the APR_POOL_DEBUG code works -- it tests these ancestor
  578. * relationships for all data inserted into tables. APR_POOL_DEBUG also
  579. * provides tools (apr_pool_find, and apr_pool_is_ancestor) for other
  580. * folks to implement similar restrictions for their own data
  581. * structures.
  582. *
  583. * However, sometimes this ancestor requirement is inconvenient --
  584. * sometimes we're forced to create a sub pool (such as through
  585. * apr_sub_req_lookup_uri), and the sub pool is guaranteed to have
  586. * the same lifetime as the parent pool. This is a guarantee implemented
  587. * by the *caller*, not by the pool code. That is, the caller guarantees
  588. * they won't destroy the sub pool individually prior to destroying the
  589. * parent pool.
  590. *
  591. * In this case the caller must call apr_pool_join() to indicate this
  592. * guarantee to the APR_POOL_DEBUG code. There are a few examples spread
  593. * through the standard modules.
  594. *
  595. * These functions are only implemented when #APR_POOL_DEBUG is set.
  596. *
  597. }
  598. {$if defined(APR_POOL_DEBUG) or defined(DOXYGEN)}
  599. {
  600. * Guarantee that a subpool has the same lifetime as the parent.
  601. * @param p The parent pool
  602. * @param sub The subpool
  603. }
  604. procedure apr_pool_join(p, sub: Papr_pool_t);
  605. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  606. external LibAPR name LibNamePrefix + 'apr_pool_join' + LibSuff8;
  607. {
  608. * Find a pool from something allocated in it.
  609. * @param mem The thing allocated in the pool
  610. * @return The pool it is allocated in
  611. }
  612. function apr_pool_find(const mem: Pointer): Papr_pool_t;
  613. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  614. external LibAPR name LibNamePrefix + 'apr_pool_find' + LibSuff4;
  615. {
  616. * Report the number of bytes currently in the pool
  617. * @param p The pool to inspect
  618. * @param recurse Recurse/include the subpools' sizes
  619. * @return The number of bytes
  620. }
  621. function apr_pool_num_bytes(p: Papr_pool_t; recurse: Integer): apr_size_t;
  622. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  623. external LibAPR name LibNamePrefix + 'apr_pool_num_bytes' + LibSuff8;
  624. {
  625. * Lock a pool
  626. * @param pool The pool to lock
  627. * @param flag The flag
  628. }
  629. procedure apr_pool_lock(pool: Papr_pool_t; flag: Integer);
  630. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  631. external LibAPR name LibNamePrefix + 'apr_pool_lock' + LibSuff8;
  632. {$else} { APR_POOL_DEBUG or DOXYGEN }
  633. {#ifdef apr_pool_join
  634. #undef apr_pool_join
  635. #endif
  636. #define apr_pool_join(a,b)
  637. #ifdef apr_pool_lock
  638. #undef apr_pool_lock
  639. #endif
  640. #define apr_pool_lock(pool, lock)}
  641. {$endif} { APR_POOL_DEBUG or DOXYGEN }