mysqlnd_alloc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2006-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andrey Hristov <andrey@php.net> |
  16. | Ulf Wendel <uw@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #ifndef MYSQLND_ALLOC_H
  20. #define MYSQLND_ALLOC_H
  21. PHPAPI extern const char * mysqlnd_debug_std_no_trace_funcs[];
  22. #define MYSQLND_MEM_D ZEND_FILE_LINE_DC
  23. #define MYSQLND_MEM_C ZEND_FILE_LINE_CC
  24. struct st_mysqlnd_allocator_methods
  25. {
  26. void * (*m_emalloc)(size_t size MYSQLND_MEM_D);
  27. void * (*m_pemalloc)(size_t size, zend_bool persistent MYSQLND_MEM_D);
  28. void * (*m_ecalloc)(unsigned int nmemb, size_t size MYSQLND_MEM_D);
  29. void * (*m_pecalloc)(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D);
  30. void * (*m_erealloc)(void *ptr, size_t new_size MYSQLND_MEM_D);
  31. void * (*m_perealloc)(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D);
  32. void (*m_efree)(void *ptr MYSQLND_MEM_D);
  33. void (*m_pefree)(void *ptr, zend_bool persistent MYSQLND_MEM_D);
  34. void * (*m_malloc)(size_t size MYSQLND_MEM_D);
  35. void * (*m_calloc)(unsigned int nmemb, size_t size MYSQLND_MEM_D);
  36. void * (*m_realloc)(void *ptr, size_t new_size MYSQLND_MEM_D);
  37. void (*m_free)(void *ptr MYSQLND_MEM_D);
  38. char * (*m_pememdup)(const char * const ptr, size_t size, zend_bool persistent MYSQLND_MEM_D);
  39. char * (*m_pestrndup)(const char * const ptr, size_t size, zend_bool persistent MYSQLND_MEM_D);
  40. char * (*m_pestrdup)(const char * const ptr, zend_bool persistent MYSQLND_MEM_D);
  41. int (*m_sprintf)(char **pbuf, size_t max_len, const char *format, ...);
  42. int (*m_vsprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
  43. void (*m_sprintf_free)(char * p);
  44. };
  45. PHPAPI extern struct st_mysqlnd_allocator_methods mysqlnd_allocator;
  46. #define mnd_emalloc(size) mysqlnd_allocator.m_emalloc((size) MYSQLND_MEM_C)
  47. #define mnd_pemalloc(size, pers) mysqlnd_allocator.m_pemalloc((size), (pers) MYSQLND_MEM_C)
  48. #define mnd_ecalloc(nmemb, size) mysqlnd_allocator.m_ecalloc((nmemb), (size) MYSQLND_MEM_C)
  49. #define mnd_pecalloc(nmemb, size, p) mysqlnd_allocator.m_pecalloc((nmemb), (size), (p) MYSQLND_MEM_C)
  50. #define mnd_erealloc(ptr, new_size) mysqlnd_allocator.m_erealloc((ptr), (new_size) MYSQLND_MEM_C)
  51. #define mnd_perealloc(ptr, new_size, p) mysqlnd_allocator.m_perealloc((ptr), (new_size), (p) MYSQLND_MEM_C)
  52. #define mnd_efree(ptr) mysqlnd_allocator.m_efree((ptr) MYSQLND_MEM_C)
  53. #define mnd_pefree(ptr, pers) mysqlnd_allocator.m_pefree((ptr), (pers) MYSQLND_MEM_C)
  54. #define mnd_malloc(size) mysqlnd_allocator.m_malloc((size) MYSQLND_MEM_C)
  55. #define mnd_calloc(nmemb, size) mysqlnd_allocator.m_calloc((nmemb), (size) MYSQLND_MEM_C)
  56. #define mnd_realloc(ptr, new_size) mysqlnd_allocator.m_realloc((ptr), (new_size) MYSQLND_MEM_C)
  57. #define mnd_free(ptr) mysqlnd_allocator.m_free((ptr) MYSQLND_MEM_C)
  58. #define mnd_pememdup(ptr, size, pers) mysqlnd_allocator.m_pememdup((ptr), (size), (pers) MYSQLND_MEM_C)
  59. #define mnd_pestrndup(ptr, size, pers) mysqlnd_allocator.m_pestrndup((ptr), (size), (pers) MYSQLND_MEM_C)
  60. #define mnd_pestrdup(ptr, pers) mysqlnd_allocator.m_pestrdup((ptr), (pers) MYSQLND_MEM_C)
  61. #define mnd_sprintf(p, mx_len, fmt,...) mysqlnd_allocator.m_sprintf((p), (mx_len), (fmt), __VA_ARGS__)
  62. #define mnd_vsprintf(p, mx_len, fmt,ap) mysqlnd_allocator.m_vsprintf((p), (mx_len), (fmt), (ap))
  63. #define mnd_sprintf_free(p) mysqlnd_allocator.m_sprintf_free((p))
  64. static inline MYSQLND_STRING mnd_dup_cstring(const MYSQLND_CSTRING str, const zend_bool persistent)
  65. {
  66. const MYSQLND_STRING ret = {(char*) mnd_pemalloc(str.l + 1, persistent), str.l};
  67. if (ret.s) {
  68. memcpy(ret.s, str.s, str.l);
  69. ret.s[str.l] = '\0';
  70. }
  71. return ret;
  72. }
  73. static inline MYSQLND_CSTRING mnd_str2c(const MYSQLND_STRING str)
  74. {
  75. const MYSQLND_CSTRING ret = {str.s, str.l};
  76. return ret;
  77. }
  78. #endif /* MYSQLND_ALLOC_H */
  79. /*
  80. * Local variables:
  81. * tab-width: 4
  82. * c-basic-offset: 4
  83. * End:
  84. * vim600: noet sw=4 ts=4 fdm=marker
  85. * vim<600: noet sw=4 ts=4
  86. */