ffi_accel.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. From 6c0fa674b91057fe27da23802c969adcb8f55385 Mon Sep 17 00:00:00 2001
  2. From: Pierre-Yves Rollo <dev@pyrollo.com>
  3. Date: Tue, 25 Jun 2019 10:59:30 +0200
  4. Subject: [PATCH] Add FFI pointer and size retrieval and sanity check functions
  5. diff --git a/src/mapnode.cpp b/src/mapnode.cpp
  6. index 9761a661..41a7e71b 100644
  7. --- a/src/mapnode.cpp
  8. +++ b/src/mapnode.cpp
  9. @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
  10. #include "util/numeric.h"
  11. #include <string>
  12. #include <sstream>
  13. +#include <cstddef>
  14. static const Rotation wallmounted_to_rot[] = {
  15. ROTATE_0, ROTATE_180, ROTATE_90, ROTATE_270
  16. @@ -44,6 +45,21 @@ static const u8 rot_to_wallmounted[] = {
  17. MapNode
  18. */
  19. +extern "C" {
  20. +
  21. +#ifdef WIN32
  22. +__declspec(dllexport)
  23. +#endif
  24. +int get_mapnode_version(void)
  25. +{
  26. + if (sizeof(MapNode) == 4 && offsetof(MapNode, param0) == 0
  27. + && offsetof(MapNode, param1) == 2 && offsetof(MapNode, param2) == 3)
  28. + return 1;
  29. + return 0;
  30. +}
  31. +
  32. +} // extern "C"
  33. +
  34. void MapNode::getColor(const ContentFeatures &f, video::SColor *color) const
  35. {
  36. if (f.palette) {
  37. diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp
  38. index e38d319f..11363e39 100644
  39. --- a/src/script/lua_api/l_noise.cpp
  40. +++ b/src/script/lua_api/l_noise.cpp
  41. @@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
  42. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  43. */
  44. +#include "config.h"
  45. #include "lua_api/l_noise.h"
  46. #include "lua_api/l_internal.h"
  47. #include "common/c_converter.h"
  48. @@ -401,6 +402,58 @@ luaL_Reg LuaPerlinNoiseMap::methods[] = {
  49. {0,0}
  50. };
  51. +extern "C" {
  52. +
  53. +#ifdef WIN32
  54. +__declspec(dllexport)
  55. +#endif
  56. +size_t PerlinNoiseMap_get_area(void **pnmp)
  57. +{
  58. + NO_MAP_LOCK_REQUIRED;
  59. +
  60. + if (pnmp == nullptr)
  61. + throw ModError("Nil pointer in C call");
  62. +
  63. + LuaPerlinNoiseMap *o = *(LuaPerlinNoiseMap **)pnmp;
  64. +
  65. + Noise *n = o->getNoise();
  66. +
  67. + return n->sx * n->sy;
  68. +}
  69. +
  70. +#ifdef WIN32
  71. +__declspec(dllexport)
  72. +#endif
  73. +size_t PerlinNoiseMap_get_volume(void **pnmp)
  74. +{
  75. + NO_MAP_LOCK_REQUIRED;
  76. +
  77. + if (pnmp == nullptr)
  78. + throw ModError("Nil pointer in C call");
  79. +
  80. + LuaPerlinNoiseMap *o = *(LuaPerlinNoiseMap **)pnmp;
  81. +
  82. + Noise *n = o->getNoise();
  83. +
  84. + return n->sx * n->sy * n->sz;
  85. +}
  86. +
  87. +#ifdef WIN32
  88. +__declspec(dllexport)
  89. +#endif
  90. +void PerlinNoiseMap_get_pointer(void **pnmp, void **ptr)
  91. +{
  92. + NO_MAP_LOCK_REQUIRED;
  93. +
  94. + if (pnmp == nullptr || ptr == nullptr)
  95. + throw ModError("Nil pointer in C call");
  96. +
  97. + LuaPerlinNoiseMap *o = *(LuaPerlinNoiseMap **)pnmp;
  98. + *ptr = o->getNoise();
  99. +}
  100. +
  101. +} // extern "C"
  102. +
  103. ///////////////////////////////////////
  104. /*
  105. LuaPseudoRandom
  106. diff --git a/src/script/lua_api/l_noise.h b/src/script/lua_api/l_noise.h
  107. index 9f50dfd3..49a7ec6e 100644
  108. --- a/src/script/lua_api/l_noise.h
  109. +++ b/src/script/lua_api/l_noise.h
  110. @@ -91,6 +91,8 @@ class LuaPerlinNoiseMap : public ModApiBase
  111. static LuaPerlinNoiseMap *checkobject(lua_State *L, int narg);
  112. static void Register(lua_State *L);
  113. +
  114. + Noise *getNoise() const { return noise; }
  115. };
  116. /*
  117. diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp
  118. index c92983bd..574883fa 100644
  119. --- a/src/script/lua_api/l_vmanip.cpp
  120. +++ b/src/script/lua_api/l_vmanip.cpp
  121. @@ -30,6 +30,32 @@ with this program; if not, write to the Free Software Foundation, Inc.,
  122. #include "mapgen/mapgen.h"
  123. #include "voxelalgorithms.h"
  124. +extern "C" {
  125. +
  126. +#ifdef WIN32
  127. +__declspec(dllexport)
  128. +#endif
  129. +void VoxelManip_get_pointer(void **lvmp, void **ptr)
  130. +{
  131. + if (lvmp == nullptr || ptr == nullptr)
  132. + throw ModError("Nil pointer in C call");
  133. +
  134. + *ptr = (*(LuaVoxelManip **)lvmp)->vm->m_data;
  135. +}
  136. +
  137. +#ifdef WIN32
  138. +__declspec(dllexport)
  139. +#endif
  140. +s32 VoxelManip_get_volume(void **lvmp)
  141. +{
  142. + if (lvmp == nullptr)
  143. + throw ModError("Nil pointer in C call");
  144. +
  145. + return (*(LuaVoxelManip **)lvmp)->vm->m_area.getVolume();
  146. +}
  147. +
  148. +} // extern "C"
  149. +
  150. // garbage collector
  151. int LuaVoxelManip::gc_object(lua_State *L)
  152. {
  153. --
  154. 2.20.1