apr_pools.inc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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 (useful 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. {$ifdef APR_POOL_DEBUG}
  114. {/* If APR_POOL_DEBUG is blank, we get 1; if it is a number, we get -1. */
  115. #if (APR_POOL_DEBUG - APR_POOL_DEBUG -1 == 1)
  116. #undef APR_POOL_DEBUG
  117. #define APR_POOL_DEBUG 1
  118. #endif}
  119. {$else}
  120. const
  121. APR_POOL_DEBUG = 0;
  122. {$endif}
  123. { the place in the code where the particular function was called }
  124. //#define APR_POOL__FILE_LINE__ __FILE__ ":" APR_STRINGIFY(__LINE__)
  125. { A function that is called when allocation fails. }
  126. type
  127. apr_abortfunc_t = function (retcode: Integer): Integer;
  128. {
  129. * APR memory structure manipulators (pools, tables, and arrays).
  130. }
  131. {
  132. * Initialization
  133. }
  134. {
  135. * Setup all of the internal structures required to use pools
  136. * @remark Programs do NOT need to call this directly. APR will call this
  137. * automatically from apr_initialize.
  138. * @internal
  139. }
  140. function apr_pool_initialize: apr_status_t;
  141. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  142. external LibAPR name LibNamePrefix + 'apr_pool_initialize' + LibSuff0;
  143. {
  144. * Tear down all of the internal structures required to use pools
  145. * @remark Programs do NOT need to call this directly. APR will call this
  146. * automatically from apr_terminate.
  147. * @internal
  148. }
  149. procedure apr_pool_terminate;
  150. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  151. external LibAPR name LibNamePrefix + 'apr_pool_terminate' + LibSuff0;
  152. {
  153. * Pool creation/destruction
  154. }
  155. {$include apr_allocator.inc}
  156. {
  157. * Create a new pool.
  158. * @param newpool The pool we have just created.
  159. * @param parent The parent pool. If this is NULL, the new pool is a root
  160. * pool. If it is non-NULL, the new pool will inherit all
  161. * of its parent pool's attributes, except the apr_pool_t will
  162. * be a sub-pool.
  163. * @param abort_fn A function to use if the pool cannot allocate more memory.
  164. * @param allocator The allocator to use with the new pool. If NULL the
  165. * allocator of the parent pool will be used.
  166. }
  167. function apr_pool_create_ex(newpool: PPapr_pool_t;
  168. parent: Papr_pool_t; abort_fn: apr_abortfunc_t;
  169. allocator: Papr_allocator_t): apr_status_t;
  170. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  171. external LibAPR name LibNamePrefix + 'apr_pool_create_ex' + LibSuff16;
  172. {
  173. * Debug version of apr_pool_create_ex.
  174. * @param newpool @see apr_pool_create.
  175. * @param parent @see apr_pool_create.
  176. * @param abort_fn @see apr_pool_create.
  177. * @param allocator @see apr_pool_create.
  178. * @param file_line Where the function is called from.
  179. * This is usually APR_POOL__FILE_LINE__.
  180. * @remark Only available when APR_POOL_DEBUG is defined.
  181. * Call this directly if you have you apr_pool_create_ex
  182. * calls in a wrapper function and wish to override
  183. * the file_line argument to reflect the caller of
  184. * your wrapper function. If you do not have
  185. * apr_pool_create_ex in a wrapper, trust the macro
  186. * and don't call apr_pool_create_ex_debug directly.
  187. }
  188. function apr_pool_create_ex_debug(newpool: PPapr_pool_t;
  189. parent: Papr_pool_t; abort_fn: apr_abortfunc_t;
  190. allocator: Papr_allocator_t; const file_line: PChar): apr_status_t;
  191. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  192. external LibAPR name LibNamePrefix + 'apr_pool_create_ex_debug' + LibSuff20;
  193. {#if APR_POOL_DEBUG
  194. #define apr_pool_create_ex(newpool, parent, abort_fn, allocator) \
  195. apr_pool_create_ex_debug(newpool, parent, abort_fn, allocator, \
  196. APR_POOL__FILE_LINE__)
  197. #endif
  198. }
  199. {
  200. * Create a new pool.
  201. * @param newpool The pool we have just created.
  202. * @param parent The parent pool. If this is NULL, the new pool is a root
  203. * pool. If it is non-NULL, the new pool will inherit all
  204. * of its parent pool's attributes, except the apr_pool_t will
  205. * be a sub-pool.
  206. }
  207. {$ifdef DOXYGEN}
  208. function apr_pool_create(newpool: PPapr_pool_t;
  209. parent: Papr_pool_t): apr_status_t;
  210. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  211. external LibAPR name LibNamePrefix + 'apr_pool_create' + LibSuff8;
  212. {$else}
  213. {.$ifdef APR_POOL_DEBUG}
  214. {#define apr_pool_create(newpool, parent) \
  215. apr_pool_create_ex_debug(newpool, parent, NULL, NULL, \
  216. APR_POOL__FILE_LINE__)}
  217. {.$else}
  218. function apr_pool_create(newpool: PPapr_pool_t; parent: Papr_pool_t): apr_status_t;
  219. {.$endif}
  220. {$endif}
  221. {
  222. * Find the pools allocator
  223. * @param pool The pool to get the allocator from.
  224. }
  225. function apr_pool_allocator_get(pool: Papr_pool_t): Papr_allocator_t;
  226. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  227. external LibAPR name LibNamePrefix + 'apr_pool_allocator_get' + LibSuff4;
  228. {
  229. * Clear all memory in the pool and run all the cleanups. This also destroys all
  230. * subpools.
  231. * @param p The pool to clear
  232. * @remark This does not actually free the memory, it just allows the pool
  233. * to re-use this memory for the next allocation.
  234. * @see apr_pool_destroy()
  235. }
  236. procedure apr_pool_clear(p: Papr_pool_t);
  237. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  238. external LibAPR name LibNamePrefix + 'apr_pool_clear' + LibSuff4;
  239. {
  240. * Debug version of apr_pool_clear.
  241. * @param p See: apr_pool_clear.
  242. * @param file_line Where the function is called from.
  243. * This is usually APR_POOL__FILE_LINE__.
  244. * @remark Only available when APR_POOL_DEBUG is defined.
  245. * Call this directly if you have you apr_pool_clear
  246. * calls in a wrapper function and wish to override
  247. * the file_line argument to reflect the caller of
  248. * your wrapper function. If you do not have
  249. * apr_pool_clear in a wrapper, trust the macro
  250. * and don't call apr_pool_destroy_clear directly.
  251. }
  252. procedure apr_pool_clear_debug(p: Papr_pool_t; const file_line: PChar);
  253. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  254. external LibAPR name LibNamePrefix + 'apr_pool_clear_debug' + LibSuff8;
  255. {#if APR_POOL_DEBUG
  256. #define apr_pool_clear(p) \
  257. apr_pool_clear_debug(p, APR_POOL__FILE_LINE__)
  258. #endif}
  259. {
  260. * Destroy the pool. This takes similar action as apr_pool_clear() and then
  261. * frees all the memory.
  262. * @param p The pool to destroy
  263. * @remark This will actually free the memory
  264. }
  265. procedure apr_pool_destroy(p: Papr_pool_t);
  266. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  267. external LibAPR name LibNamePrefix + 'apr_pool_destroy' + LibSuff4;
  268. {
  269. * Debug version of apr_pool_destroy.
  270. * @param p See: apr_pool_destroy.
  271. * @param file_line Where the function is called from.
  272. * This is usually APR_POOL__FILE_LINE__.
  273. * @remark Only available when APR_POOL_DEBUG is defined.
  274. * Call this directly if you have you apr_pool_destroy
  275. * calls in a wrapper function and wish to override
  276. * the file_line argument to reflect the caller of
  277. * your wrapper function. If you do not have
  278. * apr_pool_destroy in a wrapper, trust the macro
  279. * and don't call apr_pool_destroy_debug directly.
  280. }
  281. procedure apr_pool_destroy_debug(p: Papr_pool_t; const file_line: PChar);
  282. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  283. external LibAPR name LibNamePrefix + 'apr_pool_destroy_debug' + LibSuff8;
  284. {#if APR_POOL_DEBUG
  285. #define apr_pool_destroy(p) \
  286. apr_pool_destroy_debug(p, APR_POOL__FILE_LINE__)
  287. #endif}
  288. {
  289. * Memory allocation
  290. }
  291. {
  292. * Allocate a block of memory from a pool
  293. * @param p The pool to allocate from
  294. * @param size The amount of memory to allocate
  295. * @return The allocated memory
  296. }
  297. function apr_palloc(p: Papr_pool_t; size: apr_size_t): Pointer;
  298. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  299. external LibAPR name LibNamePrefix + 'apr_palloc' + LibSuff8;
  300. {
  301. * Debug version of apr_palloc
  302. * @param p See: apr_palloc
  303. * @param size See: apr_palloc
  304. * @param file_line Where the function is called from.
  305. * This is usually APR_POOL__FILE_LINE__.
  306. * @return See: apr_palloc
  307. }
  308. function apr_palloc_debug(p: Papr_pool_t; size: apr_size_t;
  309. const file_line: PChar): Pointer;
  310. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  311. external LibAPR name LibNamePrefix + 'apr_palloc_debug' + LibSuff12;
  312. {#if APR_POOL_DEBUG
  313. #define apr_palloc(p, size) \
  314. apr_palloc_debug(p, size, APR_POOL__FILE_LINE__)
  315. #endif
  316. }
  317. {
  318. * Allocate a block of memory from a pool and set all of the memory to 0
  319. * @param p The pool to allocate from
  320. * @param size The amount of memory to allocate
  321. * @return The allocated memory
  322. }
  323. {#if defined(DOXYGEN)}
  324. function apr_pcalloc(p: Papr_pool_t; size: apr_size_t): Pointer;
  325. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  326. external LibAPR name LibNamePrefix + 'apr_pcalloc' + LibSuff8;
  327. {#elif !APR_POOL_DEBUG
  328. #define apr_pcalloc(p, size) memset(apr_palloc(p, size), 0, size)
  329. #endif
  330. }
  331. {
  332. * Debug version of apr_pcalloc
  333. * @param p See: apr_pcalloc
  334. * @param size See: apr_pcalloc
  335. * @param file_line Where the function is called from.
  336. * This is usually APR_POOL__FILE_LINE__.
  337. * @return See: apr_pcalloc
  338. }
  339. {APR_DECLARE(void *) apr_pcalloc_debug(apr_pool_t *p, apr_size_t size,
  340. const char *file_line);
  341. #if APR_POOL_DEBUG
  342. #define apr_pcalloc(p, size) \
  343. apr_pcalloc_debug(p, size, APR_POOL__FILE_LINE__)
  344. #endif
  345. }
  346. {
  347. * Pool Properties
  348. }
  349. {
  350. * Set the function to be called when an allocation failure occurs.
  351. * @remark If the program wants APR to exit on a memory allocation error,
  352. * then this function can be called to set the callback to use (for
  353. * performing cleanup and then exiting). If this function is not called,
  354. * then APR will return an error and expect the calling program to
  355. * deal with the error accordingly.
  356. }
  357. procedure apr_pool_abort_set(abortfunc: apr_abortfunc_t; pool: Papr_pool_t);
  358. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  359. external LibAPR name LibNamePrefix + 'apr_pool_abort_set' + LibSuff8;
  360. {
  361. * Get the abort function associated with the specified pool.
  362. * @param pool The pool for retrieving the abort function.
  363. * @return The abort function for the given pool.
  364. }
  365. function apr_pool_abort_get(pool: Papr_pool_t): apr_abortfunc_t;
  366. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  367. external LibAPR name LibNamePrefix + 'apr_pool_abort_get' + LibSuff4;
  368. {
  369. * Get the parent pool of the specified pool.
  370. * @param pool The pool for retrieving the parent pool.
  371. * @return The parent of the given pool.
  372. }
  373. function apr_pool_parent_get(pool: Papr_pool_t): Papr_pool_t;
  374. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  375. external LibAPR name LibNamePrefix + 'apr_pool_parent_get' + LibSuff4;
  376. {
  377. * Determine if pool a is an ancestor of pool b.
  378. * @param a The pool to search
  379. * @param b The pool to search for
  380. * @return True if a is an ancestor of b, NULL is considered an ancestor
  381. * of all pools.
  382. * @remark if compiled with APR_POOL_DEBUG, this function will also
  383. * return true if A is a pool which has been guaranteed by the caller
  384. * (using apr_pool_join) to have a lifetime at least as long as some
  385. * ancestor of pool B.
  386. }
  387. function apr_pool_is_ancestor(a, b: Papr_pool_t): Integer;
  388. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  389. external LibAPR name LibNamePrefix + 'apr_pool_is_ancestor' + LibSuff8;
  390. {
  391. * Tag a pool (give it a name)
  392. * @param pool The pool to tag
  393. * @param tag The tag
  394. }
  395. procedure apr_pool_tag(pool: Papr_pool_t; tag: PChar);
  396. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  397. external LibAPR name LibNamePrefix + 'apr_pool_tag' + LibSuff8;
  398. {
  399. * User data management
  400. }
  401. {
  402. * Set the data associated with the current pool
  403. * @param data The user data associated with the pool.
  404. * @param key The key to use for association
  405. * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
  406. * @param pool The current pool
  407. * @warning The data to be attached to the pool should have a life span
  408. * at least as long as the pool it is being attached to.
  409. *
  410. * Users of APR must take EXTREME care when choosing a key to
  411. * use for their data. It is possible to accidentally overwrite
  412. * data by choosing a key that another part of the program is using.
  413. * Therefore it is advised that steps are taken to ensure that unique
  414. * keys are used for all of the userdata objects in a particular pool
  415. * (the same key in two different pools or a pool and one of its
  416. * subpools is okay) at all times. Careful namespace prefixing of
  417. * key names is a typical way to help ensure this uniqueness.
  418. }
  419. //function apr_pool_userdata_set(
  420. // const data: Pointer; const key: PChar;
  421. // cleanup: function(param: Pointer): apr_status_t,
  422. // pool: Papr_pool_t): apr_status_t;
  423. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  424. // external LibAPR name LibNamePrefix + 'apr_pool_userdata_set' + LibSuff20;
  425. {
  426. * Set the data associated with the current pool
  427. * @param data The user data associated with the pool.
  428. * @param key The key to use for association
  429. * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
  430. * @param pool The current pool
  431. * @note same as apr_pool_userdata_set(), except that this version doesn't
  432. * make a copy of the key (this function is useful, for example, when
  433. * the key is a string literal)
  434. * @warning This should NOT be used if the key could change addresses by
  435. * any means between the apr_pool_userdata_setn() call and a
  436. * subsequent apr_pool_userdata_get() on that key, such as if a
  437. * static string is used as a userdata key in a DSO and the DSO could
  438. * be unloaded and reloaded between the _setn() and the _get(). You
  439. * MUST use apr_pool_userdata_set() in such cases.
  440. * @warning More generally, the key and the data to be attached to the
  441. * pool should have a life span at least as long as the pool itself.
  442. *
  443. }
  444. //function apr_pool_userdata_setn(
  445. // const data: Pointer; const key: PChar;
  446. // cleanup: function(param: Pointer): apr_status_t,
  447. // pool: Papr_pool_t): apr_status_t;
  448. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  449. // external LibAPR name LibNamePrefix + 'apr_pool_userdata_setn' + LibSuff20;
  450. {
  451. * Return the data associated with the current pool.
  452. * @param data The user data associated with the pool.
  453. * @param key The key for the data to retrieve
  454. * @param pool The current pool.
  455. }
  456. function apr_pool_userdata_get(data: PPointer; const key: PChar;
  457. pool: Papr_pool_t): apr_status_t;
  458. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  459. external LibAPR name LibNamePrefix + 'apr_pool_userdata_get' + LibSuff12;
  460. {
  461. * @defgroup PoolCleanup Pool Cleanup Functions
  462. *
  463. * Cleanups are performed in the reverse order they were registered. That is:
  464. * Last In, First Out. A cleanup function can safely allocate memory from
  465. * the pool that is being cleaned up. It can also safely register additional
  466. * cleanups which will be run LIFO, directly after the current cleanup
  467. * terminates. Cleanups have to take caution in calling functions that
  468. * create subpools. Subpools, created during cleanup will NOT automatically
  469. * be cleaned up. In other words, cleanups are to clean up after themselves.
  470. *
  471. }
  472. {
  473. * Register a function to be called when a pool is cleared or destroyed
  474. * @param p The pool register the cleanup with
  475. * @param data The data to pass to the cleanup function.
  476. * @param plain_cleanup The function to call when the pool is cleared
  477. * or destroyed
  478. * @param child_cleanup The function to call when a child process is about
  479. * to exec - this function is called in the child, obviously!
  480. }
  481. type
  482. plain_cleanup_t = function(param: Pointer): apr_status_t; cdecl;
  483. child_cleanup_t = function(param: Pointer): apr_status_t; cdecl;
  484. procedure apr_pool_cleanup_register(p: Papr_pool_t;
  485. const data: Pointer;
  486. plain_cleanup: plain_cleanup_t;
  487. child_cleanup: child_cleanup_t);
  488. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  489. external LibAPR name LibNamePrefix + 'apr_pool_cleanup_register' + LibSuff16;
  490. {
  491. * Remove a previously registered cleanup function
  492. * @param p The pool remove the cleanup from
  493. * @param data The data to remove from cleanup
  494. * @param cleanup The function to remove from cleanup
  495. * @remarks For some strange reason only the plain_cleanup is handled by this
  496. * function
  497. }
  498. //procedure apr_pool_cleanup_for_exec;
  499. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  500. // external LibAPR name LibNamePrefix + 'apr_pool_cleanup_for_exec' + LibSuff0;
  501. //APR_DECLARE(void) apr_pool_cleanup_kill(apr_pool_t *p, const void *data,
  502. // apr_status_t cleanup)(void );
  503. {
  504. * Replace the child cleanup of a previously registered cleanup
  505. * @param p The pool of the registered cleanup
  506. * @param data The data of the registered cleanup
  507. * @param plain_cleanup The plain cleanup function of the registered cleanup
  508. * @param child_cleanup The function to register as the child cleanup
  509. }
  510. //procedure apr_pool_cleanup_for_exec;
  511. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  512. // external LibAPR name LibNamePrefix + 'apr_pool_cleanup_for_exec' + LibSuff0;
  513. {APR_DECLARE(void) apr_pool_child_cleanup_set(
  514. apr_pool_t *p,
  515. const void *data,
  516. apr_status_t plain_cleanup)(void ,
  517. apr_status_t child_cleanup)(void );
  518. }
  519. {
  520. * Run the specified cleanup function immediately and unregister it.
  521. *
  522. * The cleanup most recently registered with @a p having the same values of
  523. * @a data and @a cleanup will be removed and @a cleanup will be called
  524. * with @a data as the argument.
  525. *
  526. * @param p The pool to remove the cleanup from
  527. * @param data The data to remove from cleanup
  528. * @param cleanup The function to remove from cleanup
  529. }
  530. //procedure apr_pool_cleanup_for_exec;
  531. // {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  532. // external LibAPR name LibNamePrefix + 'apr_pool_cleanup_for_exec' + LibSuff0;
  533. {APR_DECLARE(apr_status_t) apr_pool_cleanup_run(
  534. apr_pool_t *p,
  535. void *data,
  536. apr_status_t cleanup)(void );}
  537. {
  538. * An empty cleanup function.
  539. *
  540. * Passed to apr_pool_cleanup_register() when no cleanup is required.
  541. *
  542. * @param data The data to cleanup, will not be used by this function.
  543. }
  544. //APR_DECLARE_NONSTD(apr_status_t) apr_pool_cleanup_null(void *data);
  545. {
  546. * Run all registered child cleanups, in preparation for an exec()
  547. * call in a forked child -- close files, etc., but *don't* flush I/O
  548. * buffers, *don't* wait for subprocesses, and *don't* free any
  549. * memory.
  550. }
  551. procedure apr_pool_cleanup_for_exec;
  552. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  553. external LibAPR name LibNamePrefix + 'apr_pool_cleanup_for_exec' + LibSuff0;
  554. {
  555. * @defgroup PoolDebug Pool Debugging functions.
  556. *
  557. * pools have nested lifetimes -- sub_pools are destroyed when the
  558. * parent pool is cleared. We allow certain liberties with operations
  559. * on things such as tables (and on other structures in a more general
  560. * sense) where we allow the caller to insert values into a table which
  561. * were not allocated from the table's pool. The table's data will
  562. * remain valid as long as all the pools from which its values are
  563. * allocated remain valid.
  564. *
  565. * For example, if B is a sub pool of A, and you build a table T in
  566. * pool B, then it's safe to insert data allocated in A or B into T
  567. * (because B lives at most as long as A does, and T is destroyed when
  568. * B is cleared/destroyed). On the other hand, if S is a table in
  569. * pool A, it is safe to insert data allocated in A into S, but it
  570. * is *not safe* to insert data allocated from B into S... because
  571. * B can be cleared/destroyed before A is (which would leave dangling
  572. * pointers in T's data structures).
  573. *
  574. * In general we say that it is safe to insert data into a table T
  575. * if the data is allocated in any ancestor of T's pool. This is the
  576. * basis on which the APR_POOL_DEBUG code works -- it tests these ancestor
  577. * relationships for all data inserted into tables. APR_POOL_DEBUG also
  578. * provides tools (apr_pool_find, and apr_pool_is_ancestor) for other
  579. * folks to implement similar restrictions for their own data
  580. * structures.
  581. *
  582. * However, sometimes this ancestor requirement is inconvenient --
  583. * sometimes it's necessary to create a sub pool where the sub pool is
  584. * guaranteed to have the same lifetime as the parent pool. This is a
  585. * guarantee implemented by the *caller*, not by the pool code. That
  586. * is, the caller guarantees they won't destroy the sub pool
  587. * individually prior to destroying the parent pool.
  588. *
  589. * In this case the caller must call apr_pool_join() to indicate this
  590. * guarantee to the APR_POOL_DEBUG code.
  591. *
  592. * These functions are only implemented when #APR_POOL_DEBUG is set.
  593. *
  594. }
  595. {$if defined(APR_POOL_DEBUG) or defined(DOXYGEN)}
  596. {
  597. * Guarantee that a subpool has the same lifetime as the parent.
  598. * @param p The parent pool
  599. * @param sub The subpool
  600. }
  601. procedure apr_pool_join(p, sub: Papr_pool_t);
  602. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  603. external LibAPR name LibNamePrefix + 'apr_pool_join' + LibSuff8;
  604. {
  605. * Find a pool from something allocated in it.
  606. * @param mem The thing allocated in the pool
  607. * @return The pool it is allocated in
  608. }
  609. function apr_pool_find(const mem: Pointer): Papr_pool_t;
  610. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  611. external LibAPR name LibNamePrefix + 'apr_pool_find' + LibSuff4;
  612. {
  613. * Report the number of bytes currently in the pool
  614. * @param p The pool to inspect
  615. * @param recurse Recurse/include the subpools' sizes
  616. * @return The number of bytes
  617. }
  618. function apr_pool_num_bytes(p: Papr_pool_t; recurse: Integer): apr_size_t;
  619. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  620. external LibAPR name LibNamePrefix + 'apr_pool_num_bytes' + LibSuff8;
  621. {
  622. * Lock a pool
  623. * @param pool The pool to lock
  624. * @param flag The flag
  625. }
  626. procedure apr_pool_lock(pool: Papr_pool_t; flag: Integer);
  627. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  628. external LibAPR name LibNamePrefix + 'apr_pool_lock' + LibSuff8;
  629. {$else} { APR_POOL_DEBUG or DOXYGEN }
  630. {#ifdef apr_pool_join
  631. #undef apr_pool_join
  632. #endif
  633. #define apr_pool_join(a,b)
  634. #ifdef apr_pool_lock
  635. #undef apr_pool_lock
  636. #endif
  637. #define apr_pool_lock(pool, lock)}
  638. {$endif} { APR_POOL_DEBUG or DOXYGEN }