config.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. // clang-format off
  3. #define PK_VERSION "2.1.2"
  4. #define PK_VERSION_MAJOR 2
  5. #define PK_VERSION_MINOR 1
  6. #define PK_VERSION_PATCH 2
  7. /*************** feature settings ***************/
  8. #ifndef PK_ENABLE_OS // can be overridden by cmake
  9. #define PK_ENABLE_OS 1
  10. #endif
  11. #ifndef PK_ENABLE_THREADS // can be overridden by cmake
  12. #define PK_ENABLE_THREADS 1
  13. #endif
  14. #ifndef PK_ENABLE_DETERMINISM // must be enabled from cmake
  15. #define PK_ENABLE_DETERMINISM 0
  16. #endif
  17. #ifndef PK_ENABLE_WATCHDOG // can be overridden by cmake
  18. #define PK_ENABLE_WATCHDOG 0
  19. #endif
  20. #ifndef PK_ENABLE_CUSTOM_SNAME // can be overridden by cmake
  21. #define PK_ENABLE_CUSTOM_SNAME 0
  22. #endif
  23. #ifndef PK_ENABLE_MIMALLOC // can be overridden by cmake
  24. #define PK_ENABLE_MIMALLOC 0
  25. #endif
  26. // GC min threshold
  27. #ifndef PK_GC_MIN_THRESHOLD // can be overridden by cmake
  28. #define PK_GC_MIN_THRESHOLD 32768
  29. #endif
  30. // This is the maximum size of the value stack in py_TValue units
  31. // The actual size in bytes equals `sizeof(py_TValue) * PK_VM_STACK_SIZE`
  32. #ifndef PK_VM_STACK_SIZE // can be overridden by cmake
  33. #define PK_VM_STACK_SIZE 16384
  34. #endif
  35. // This is the maximum number of local variables in a function
  36. // (not recommended to change this)
  37. #ifndef PK_MAX_CO_VARNAMES // can be overridden by cmake
  38. #define PK_MAX_CO_VARNAMES 64
  39. #endif
  40. /*************** internal settings ***************/
  41. // This is the maximum character length of a module path
  42. #define PK_MAX_MODULE_PATH_LEN 63
  43. // This is some math constants
  44. #define PK_M_PI 3.1415926535897932384
  45. #define PK_M_E 2.7182818284590452354
  46. #define PK_M_DEG2RAD 0.017453292519943295
  47. #define PK_M_RAD2DEG 57.29577951308232
  48. // Hash table load factor (smaller ones mean less collision but more memory)
  49. // For class instance
  50. #define PK_INST_ATTR_LOAD_FACTOR 0.67f
  51. // For class itself
  52. #define PK_TYPE_ATTR_LOAD_FACTOR 0.5f
  53. #ifdef _WIN32
  54. #define PK_PLATFORM_SEP '\\'
  55. #else
  56. #define PK_PLATFORM_SEP '/'
  57. #endif
  58. #ifdef __cplusplus
  59. #ifndef restrict
  60. #define restrict
  61. #endif
  62. #endif
  63. #if PK_ENABLE_THREADS
  64. #define PK_THREAD_LOCAL _Thread_local
  65. #else
  66. #define PK_THREAD_LOCAL
  67. #endif
  68. // Memory allocation functions
  69. #ifndef PK_MALLOC
  70. #if PK_ENABLE_MIMALLOC
  71. #include "mimalloc.h"
  72. #define PK_MALLOC(size) mi_malloc(size)
  73. #define PK_REALLOC(ptr, size) mi_realloc(ptr, size)
  74. #define PK_FREE(ptr) mi_free(ptr)
  75. #else
  76. #ifndef __cplusplus
  77. #include <stdlib.h>
  78. #define PK_MALLOC(size) malloc(size)
  79. #define PK_REALLOC(ptr, size) realloc(ptr, size)
  80. #define PK_FREE(ptr) free(ptr)
  81. #else
  82. #include <cstdlib>
  83. #define PK_MALLOC(size) std::malloc(size)
  84. #define PK_REALLOC(ptr, size) std::realloc(ptr, size)
  85. #define PK_FREE(ptr) std::free(ptr)
  86. #endif
  87. #endif
  88. #endif