service_mysql_alloc.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License, version 2.0, for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  18. #ifndef MYSQL_SERVICE_MYSQL_ALLOC_INCLUDED
  19. #define MYSQL_SERVICE_MYSQL_ALLOC_INCLUDED
  20. #ifndef MYSQL_ABI_CHECK
  21. #include <stdlib.h>
  22. #endif
  23. /* PSI_memory_key */
  24. #include "mysql/psi/psi_memory.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* myf */
  29. typedef int myf_t;
  30. typedef void * (*mysql_malloc_t)(PSI_memory_key key, size_t size, myf_t flags);
  31. typedef void * (*mysql_realloc_t)(PSI_memory_key key, void *ptr, size_t size, myf_t flags);
  32. typedef void (*mysql_claim_t)(void *ptr);
  33. typedef void (*mysql_free_t)(void *ptr);
  34. typedef void * (*my_memdup_t)(PSI_memory_key key, const void *from, size_t length, myf_t flags);
  35. typedef char * (*my_strdup_t)(PSI_memory_key key, const char *from, myf_t flags);
  36. typedef char * (*my_strndup_t)(PSI_memory_key key, const char *from, size_t length, myf_t flags);
  37. struct mysql_malloc_service_st
  38. {
  39. mysql_malloc_t mysql_malloc;
  40. mysql_realloc_t mysql_realloc;
  41. mysql_claim_t mysql_claim;
  42. mysql_free_t mysql_free;
  43. my_memdup_t my_memdup;
  44. my_strdup_t my_strdup;
  45. my_strndup_t my_strndup;
  46. };
  47. extern struct mysql_malloc_service_st *mysql_malloc_service;
  48. #ifdef MYSQL_DYNAMIC_PLUGIN
  49. #define my_malloc mysql_malloc_service->mysql_malloc
  50. #define my_realloc mysql_malloc_service->mysql_realloc
  51. #define my_claim mysql_malloc_service->mysql_claim
  52. #define my_free mysql_malloc_service->mysql_free
  53. #define my_memdup mysql_malloc_service->my_memdup
  54. #define my_strdup mysql_malloc_service->my_strdup
  55. #define my_strndup mysql_malloc_service->my_strndup
  56. #else
  57. extern void * my_malloc(PSI_memory_key key, size_t size, myf_t flags);
  58. extern void * my_realloc(PSI_memory_key key, void *ptr, size_t size, myf_t flags);
  59. extern void my_claim(void *ptr);
  60. extern void my_free(void *ptr);
  61. extern void * my_memdup(PSI_memory_key key, const void *from, size_t length, myf_t flags);
  62. extern char * my_strdup(PSI_memory_key key, const char *from, myf_t flags);
  63. extern char * my_strndup(PSI_memory_key key, const char *from, size_t length, myf_t flags);
  64. #endif
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif