emacs-module.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /* emacs-module.h - GNU Emacs module API.
  2. Copyright (C) 2015-2022 Free Software Foundation, Inc.
  3. This file is part of GNU Emacs.
  4. GNU Emacs is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or (at
  7. your option) any later version.
  8. GNU Emacs is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
  14. /*
  15. This file defines the Emacs module API. Please see the chapter
  16. `Dynamic Modules' in the GNU Emacs Lisp Reference Manual for
  17. information how to write modules and use this header file.
  18. */
  19. #ifndef EMACS_MODULE_H
  20. #define EMACS_MODULE_H
  21. #include <stddef.h>
  22. #include <stdint.h>
  23. #include <time.h>
  24. #ifndef __cplusplus
  25. #include <stdbool.h>
  26. #endif
  27. #define EMACS_MAJOR_VERSION 28
  28. #if defined __cplusplus && __cplusplus >= 201103L
  29. # define EMACS_NOEXCEPT noexcept
  30. #else
  31. # define EMACS_NOEXCEPT
  32. #endif
  33. #if defined __cplusplus && __cplusplus >= 201703L
  34. # define EMACS_NOEXCEPT_TYPEDEF noexcept
  35. #else
  36. # define EMACS_NOEXCEPT_TYPEDEF
  37. #endif
  38. #if 3 < __GNUC__ + (3 <= __GNUC_MINOR__)
  39. # define EMACS_ATTRIBUTE_NONNULL(...) \
  40. __attribute__ ((__nonnull__ (__VA_ARGS__)))
  41. #elif (defined __has_attribute \
  42. && (!defined __clang_minor__ \
  43. || 3 < __clang_major__ + (5 <= __clang_minor__)))
  44. # if __has_attribute (__nonnull__)
  45. # define EMACS_ATTRIBUTE_NONNULL(...) \
  46. __attribute__ ((__nonnull__ (__VA_ARGS__)))
  47. # endif
  48. #endif
  49. #ifndef EMACS_ATTRIBUTE_NONNULL
  50. # define EMACS_ATTRIBUTE_NONNULL(...)
  51. #endif
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /* Current environment. */
  56. typedef struct emacs_env_28 emacs_env;
  57. /* Opaque pointer representing an Emacs Lisp value.
  58. BEWARE: Do not assume NULL is a valid value! */
  59. typedef struct emacs_value_tag *emacs_value;
  60. enum { emacs_variadic_function = -2 };
  61. /* Struct passed to a module init function (emacs_module_init). */
  62. struct emacs_runtime
  63. {
  64. /* Structure size (for version checking). */
  65. ptrdiff_t size;
  66. /* Private data; users should not touch this. */
  67. struct emacs_runtime_private *private_members;
  68. /* Return an environment pointer. */
  69. emacs_env *(*get_environment) (struct emacs_runtime *runtime)
  70. EMACS_ATTRIBUTE_NONNULL (1);
  71. };
  72. /* Type aliases for function pointer types used in the module API.
  73. Note that we don't use these aliases directly in the API to be able
  74. to mark the function arguments as 'noexcept' before C++20.
  75. However, users can use them if they want. */
  76. /* Function prototype for the module Lisp functions. These must not
  77. throw C++ exceptions. */
  78. typedef emacs_value (*emacs_function) (emacs_env *env, ptrdiff_t nargs,
  79. emacs_value *args,
  80. void *data)
  81. EMACS_NOEXCEPT_TYPEDEF EMACS_ATTRIBUTE_NONNULL (1);
  82. /* Function prototype for module user-pointer and function finalizers.
  83. These must not throw C++ exceptions. */
  84. typedef void (*emacs_finalizer) (void *data) EMACS_NOEXCEPT_TYPEDEF;
  85. /* Possible Emacs function call outcomes. */
  86. enum emacs_funcall_exit
  87. {
  88. /* Function has returned normally. */
  89. emacs_funcall_exit_return = 0,
  90. /* Function has signaled an error using `signal'. */
  91. emacs_funcall_exit_signal = 1,
  92. /* Function has exit using `throw'. */
  93. emacs_funcall_exit_throw = 2
  94. };
  95. /* Possible return values for emacs_env.process_input. */
  96. enum emacs_process_input_result
  97. {
  98. /* Module code may continue */
  99. emacs_process_input_continue = 0,
  100. /* Module code should return control to Emacs as soon as possible. */
  101. emacs_process_input_quit = 1
  102. };
  103. /* Define emacs_limb_t so that it is likely to match GMP's mp_limb_t.
  104. This micro-optimization can help modules that use mpz_export and
  105. mpz_import, which operate more efficiently on mp_limb_t. It's OK
  106. (if perhaps a bit slower) if the two types do not match, and
  107. modules shouldn't rely on the two types matching. */
  108. typedef size_t emacs_limb_t;
  109. #define EMACS_LIMB_MAX SIZE_MAX
  110. struct emacs_env_25
  111. {
  112. /* Structure size (for version checking). */
  113. ptrdiff_t size;
  114. /* Private data; users should not touch this. */
  115. struct emacs_env_private *private_members;
  116. /* Memory management. */
  117. emacs_value (*make_global_ref) (emacs_env *env, emacs_value value)
  118. EMACS_ATTRIBUTE_NONNULL(1);
  119. void (*free_global_ref) (emacs_env *env, emacs_value global_value)
  120. EMACS_ATTRIBUTE_NONNULL(1);
  121. /* Non-local exit handling. */
  122. enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env)
  123. EMACS_ATTRIBUTE_NONNULL(1);
  124. void (*non_local_exit_clear) (emacs_env *env)
  125. EMACS_ATTRIBUTE_NONNULL(1);
  126. enum emacs_funcall_exit (*non_local_exit_get)
  127. (emacs_env *env, emacs_value *symbol, emacs_value *data)
  128. EMACS_ATTRIBUTE_NONNULL(1, 2, 3);
  129. void (*non_local_exit_signal) (emacs_env *env,
  130. emacs_value symbol, emacs_value data)
  131. EMACS_ATTRIBUTE_NONNULL(1);
  132. void (*non_local_exit_throw) (emacs_env *env,
  133. emacs_value tag, emacs_value value)
  134. EMACS_ATTRIBUTE_NONNULL(1);
  135. /* Function registration. */
  136. emacs_value (*make_function) (emacs_env *env,
  137. ptrdiff_t min_arity,
  138. ptrdiff_t max_arity,
  139. emacs_value (*func) (emacs_env *env,
  140. ptrdiff_t nargs,
  141. emacs_value* args,
  142. void *data)
  143. EMACS_NOEXCEPT
  144. EMACS_ATTRIBUTE_NONNULL(1),
  145. const char *docstring,
  146. void *data)
  147. EMACS_ATTRIBUTE_NONNULL(1, 4);
  148. emacs_value (*funcall) (emacs_env *env,
  149. emacs_value func,
  150. ptrdiff_t nargs,
  151. emacs_value* args)
  152. EMACS_ATTRIBUTE_NONNULL(1);
  153. emacs_value (*intern) (emacs_env *env, const char *name)
  154. EMACS_ATTRIBUTE_NONNULL(1, 2);
  155. /* Type conversion. */
  156. emacs_value (*type_of) (emacs_env *env, emacs_value arg)
  157. EMACS_ATTRIBUTE_NONNULL(1);
  158. bool (*is_not_nil) (emacs_env *env, emacs_value arg)
  159. EMACS_ATTRIBUTE_NONNULL(1);
  160. bool (*eq) (emacs_env *env, emacs_value a, emacs_value b)
  161. EMACS_ATTRIBUTE_NONNULL(1);
  162. intmax_t (*extract_integer) (emacs_env *env, emacs_value arg)
  163. EMACS_ATTRIBUTE_NONNULL(1);
  164. emacs_value (*make_integer) (emacs_env *env, intmax_t n)
  165. EMACS_ATTRIBUTE_NONNULL(1);
  166. double (*extract_float) (emacs_env *env, emacs_value arg)
  167. EMACS_ATTRIBUTE_NONNULL(1);
  168. emacs_value (*make_float) (emacs_env *env, double d)
  169. EMACS_ATTRIBUTE_NONNULL(1);
  170. /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
  171. null-terminated string.
  172. SIZE must point to the total size of the buffer. If BUFFER is
  173. NULL or if SIZE is not big enough, write the required buffer size
  174. to SIZE and return true.
  175. Note that SIZE must include the last null byte (e.g. "abc" needs
  176. a buffer of size 4).
  177. Return true if the string was successfully copied. */
  178. bool (*copy_string_contents) (emacs_env *env,
  179. emacs_value value,
  180. char *buf,
  181. ptrdiff_t *len)
  182. EMACS_ATTRIBUTE_NONNULL(1, 4);
  183. /* Create a Lisp string from a utf8 encoded string. */
  184. emacs_value (*make_string) (emacs_env *env,
  185. const char *str, ptrdiff_t len)
  186. EMACS_ATTRIBUTE_NONNULL(1, 2);
  187. /* Embedded pointer type. */
  188. emacs_value (*make_user_ptr) (emacs_env *env,
  189. void (*fin) (void *) EMACS_NOEXCEPT,
  190. void *ptr)
  191. EMACS_ATTRIBUTE_NONNULL(1);
  192. void *(*get_user_ptr) (emacs_env *env, emacs_value arg)
  193. EMACS_ATTRIBUTE_NONNULL(1);
  194. void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr)
  195. EMACS_ATTRIBUTE_NONNULL(1);
  196. void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr))
  197. (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1);
  198. void (*set_user_finalizer) (emacs_env *env, emacs_value arg,
  199. void (*fin) (void *) EMACS_NOEXCEPT)
  200. EMACS_ATTRIBUTE_NONNULL(1);
  201. /* Vector functions. */
  202. emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index)
  203. EMACS_ATTRIBUTE_NONNULL(1);
  204. void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index,
  205. emacs_value value)
  206. EMACS_ATTRIBUTE_NONNULL(1);
  207. ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector)
  208. EMACS_ATTRIBUTE_NONNULL(1);
  209. };
  210. struct emacs_env_26
  211. {
  212. /* Structure size (for version checking). */
  213. ptrdiff_t size;
  214. /* Private data; users should not touch this. */
  215. struct emacs_env_private *private_members;
  216. /* Memory management. */
  217. emacs_value (*make_global_ref) (emacs_env *env, emacs_value value)
  218. EMACS_ATTRIBUTE_NONNULL(1);
  219. void (*free_global_ref) (emacs_env *env, emacs_value global_value)
  220. EMACS_ATTRIBUTE_NONNULL(1);
  221. /* Non-local exit handling. */
  222. enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env)
  223. EMACS_ATTRIBUTE_NONNULL(1);
  224. void (*non_local_exit_clear) (emacs_env *env)
  225. EMACS_ATTRIBUTE_NONNULL(1);
  226. enum emacs_funcall_exit (*non_local_exit_get)
  227. (emacs_env *env, emacs_value *symbol, emacs_value *data)
  228. EMACS_ATTRIBUTE_NONNULL(1, 2, 3);
  229. void (*non_local_exit_signal) (emacs_env *env,
  230. emacs_value symbol, emacs_value data)
  231. EMACS_ATTRIBUTE_NONNULL(1);
  232. void (*non_local_exit_throw) (emacs_env *env,
  233. emacs_value tag, emacs_value value)
  234. EMACS_ATTRIBUTE_NONNULL(1);
  235. /* Function registration. */
  236. emacs_value (*make_function) (emacs_env *env,
  237. ptrdiff_t min_arity,
  238. ptrdiff_t max_arity,
  239. emacs_value (*func) (emacs_env *env,
  240. ptrdiff_t nargs,
  241. emacs_value* args,
  242. void *data)
  243. EMACS_NOEXCEPT
  244. EMACS_ATTRIBUTE_NONNULL(1),
  245. const char *docstring,
  246. void *data)
  247. EMACS_ATTRIBUTE_NONNULL(1, 4);
  248. emacs_value (*funcall) (emacs_env *env,
  249. emacs_value func,
  250. ptrdiff_t nargs,
  251. emacs_value* args)
  252. EMACS_ATTRIBUTE_NONNULL(1);
  253. emacs_value (*intern) (emacs_env *env, const char *name)
  254. EMACS_ATTRIBUTE_NONNULL(1, 2);
  255. /* Type conversion. */
  256. emacs_value (*type_of) (emacs_env *env, emacs_value arg)
  257. EMACS_ATTRIBUTE_NONNULL(1);
  258. bool (*is_not_nil) (emacs_env *env, emacs_value arg)
  259. EMACS_ATTRIBUTE_NONNULL(1);
  260. bool (*eq) (emacs_env *env, emacs_value a, emacs_value b)
  261. EMACS_ATTRIBUTE_NONNULL(1);
  262. intmax_t (*extract_integer) (emacs_env *env, emacs_value arg)
  263. EMACS_ATTRIBUTE_NONNULL(1);
  264. emacs_value (*make_integer) (emacs_env *env, intmax_t n)
  265. EMACS_ATTRIBUTE_NONNULL(1);
  266. double (*extract_float) (emacs_env *env, emacs_value arg)
  267. EMACS_ATTRIBUTE_NONNULL(1);
  268. emacs_value (*make_float) (emacs_env *env, double d)
  269. EMACS_ATTRIBUTE_NONNULL(1);
  270. /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
  271. null-terminated string.
  272. SIZE must point to the total size of the buffer. If BUFFER is
  273. NULL or if SIZE is not big enough, write the required buffer size
  274. to SIZE and return true.
  275. Note that SIZE must include the last null byte (e.g. "abc" needs
  276. a buffer of size 4).
  277. Return true if the string was successfully copied. */
  278. bool (*copy_string_contents) (emacs_env *env,
  279. emacs_value value,
  280. char *buf,
  281. ptrdiff_t *len)
  282. EMACS_ATTRIBUTE_NONNULL(1, 4);
  283. /* Create a Lisp string from a utf8 encoded string. */
  284. emacs_value (*make_string) (emacs_env *env,
  285. const char *str, ptrdiff_t len)
  286. EMACS_ATTRIBUTE_NONNULL(1, 2);
  287. /* Embedded pointer type. */
  288. emacs_value (*make_user_ptr) (emacs_env *env,
  289. void (*fin) (void *) EMACS_NOEXCEPT,
  290. void *ptr)
  291. EMACS_ATTRIBUTE_NONNULL(1);
  292. void *(*get_user_ptr) (emacs_env *env, emacs_value arg)
  293. EMACS_ATTRIBUTE_NONNULL(1);
  294. void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr)
  295. EMACS_ATTRIBUTE_NONNULL(1);
  296. void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr))
  297. (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1);
  298. void (*set_user_finalizer) (emacs_env *env, emacs_value arg,
  299. void (*fin) (void *) EMACS_NOEXCEPT)
  300. EMACS_ATTRIBUTE_NONNULL(1);
  301. /* Vector functions. */
  302. emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index)
  303. EMACS_ATTRIBUTE_NONNULL(1);
  304. void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index,
  305. emacs_value value)
  306. EMACS_ATTRIBUTE_NONNULL(1);
  307. ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector)
  308. EMACS_ATTRIBUTE_NONNULL(1);
  309. /* Returns whether a quit is pending. */
  310. bool (*should_quit) (emacs_env *env)
  311. EMACS_ATTRIBUTE_NONNULL(1);
  312. };
  313. struct emacs_env_27
  314. {
  315. /* Structure size (for version checking). */
  316. ptrdiff_t size;
  317. /* Private data; users should not touch this. */
  318. struct emacs_env_private *private_members;
  319. /* Memory management. */
  320. emacs_value (*make_global_ref) (emacs_env *env, emacs_value value)
  321. EMACS_ATTRIBUTE_NONNULL(1);
  322. void (*free_global_ref) (emacs_env *env, emacs_value global_value)
  323. EMACS_ATTRIBUTE_NONNULL(1);
  324. /* Non-local exit handling. */
  325. enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env)
  326. EMACS_ATTRIBUTE_NONNULL(1);
  327. void (*non_local_exit_clear) (emacs_env *env)
  328. EMACS_ATTRIBUTE_NONNULL(1);
  329. enum emacs_funcall_exit (*non_local_exit_get)
  330. (emacs_env *env, emacs_value *symbol, emacs_value *data)
  331. EMACS_ATTRIBUTE_NONNULL(1, 2, 3);
  332. void (*non_local_exit_signal) (emacs_env *env,
  333. emacs_value symbol, emacs_value data)
  334. EMACS_ATTRIBUTE_NONNULL(1);
  335. void (*non_local_exit_throw) (emacs_env *env,
  336. emacs_value tag, emacs_value value)
  337. EMACS_ATTRIBUTE_NONNULL(1);
  338. /* Function registration. */
  339. emacs_value (*make_function) (emacs_env *env,
  340. ptrdiff_t min_arity,
  341. ptrdiff_t max_arity,
  342. emacs_value (*func) (emacs_env *env,
  343. ptrdiff_t nargs,
  344. emacs_value* args,
  345. void *data)
  346. EMACS_NOEXCEPT
  347. EMACS_ATTRIBUTE_NONNULL(1),
  348. const char *docstring,
  349. void *data)
  350. EMACS_ATTRIBUTE_NONNULL(1, 4);
  351. emacs_value (*funcall) (emacs_env *env,
  352. emacs_value func,
  353. ptrdiff_t nargs,
  354. emacs_value* args)
  355. EMACS_ATTRIBUTE_NONNULL(1);
  356. emacs_value (*intern) (emacs_env *env, const char *name)
  357. EMACS_ATTRIBUTE_NONNULL(1, 2);
  358. /* Type conversion. */
  359. emacs_value (*type_of) (emacs_env *env, emacs_value arg)
  360. EMACS_ATTRIBUTE_NONNULL(1);
  361. bool (*is_not_nil) (emacs_env *env, emacs_value arg)
  362. EMACS_ATTRIBUTE_NONNULL(1);
  363. bool (*eq) (emacs_env *env, emacs_value a, emacs_value b)
  364. EMACS_ATTRIBUTE_NONNULL(1);
  365. intmax_t (*extract_integer) (emacs_env *env, emacs_value arg)
  366. EMACS_ATTRIBUTE_NONNULL(1);
  367. emacs_value (*make_integer) (emacs_env *env, intmax_t n)
  368. EMACS_ATTRIBUTE_NONNULL(1);
  369. double (*extract_float) (emacs_env *env, emacs_value arg)
  370. EMACS_ATTRIBUTE_NONNULL(1);
  371. emacs_value (*make_float) (emacs_env *env, double d)
  372. EMACS_ATTRIBUTE_NONNULL(1);
  373. /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
  374. null-terminated string.
  375. SIZE must point to the total size of the buffer. If BUFFER is
  376. NULL or if SIZE is not big enough, write the required buffer size
  377. to SIZE and return true.
  378. Note that SIZE must include the last null byte (e.g. "abc" needs
  379. a buffer of size 4).
  380. Return true if the string was successfully copied. */
  381. bool (*copy_string_contents) (emacs_env *env,
  382. emacs_value value,
  383. char *buf,
  384. ptrdiff_t *len)
  385. EMACS_ATTRIBUTE_NONNULL(1, 4);
  386. /* Create a Lisp string from a utf8 encoded string. */
  387. emacs_value (*make_string) (emacs_env *env,
  388. const char *str, ptrdiff_t len)
  389. EMACS_ATTRIBUTE_NONNULL(1, 2);
  390. /* Embedded pointer type. */
  391. emacs_value (*make_user_ptr) (emacs_env *env,
  392. void (*fin) (void *) EMACS_NOEXCEPT,
  393. void *ptr)
  394. EMACS_ATTRIBUTE_NONNULL(1);
  395. void *(*get_user_ptr) (emacs_env *env, emacs_value arg)
  396. EMACS_ATTRIBUTE_NONNULL(1);
  397. void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr)
  398. EMACS_ATTRIBUTE_NONNULL(1);
  399. void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr))
  400. (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1);
  401. void (*set_user_finalizer) (emacs_env *env, emacs_value arg,
  402. void (*fin) (void *) EMACS_NOEXCEPT)
  403. EMACS_ATTRIBUTE_NONNULL(1);
  404. /* Vector functions. */
  405. emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index)
  406. EMACS_ATTRIBUTE_NONNULL(1);
  407. void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index,
  408. emacs_value value)
  409. EMACS_ATTRIBUTE_NONNULL(1);
  410. ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector)
  411. EMACS_ATTRIBUTE_NONNULL(1);
  412. /* Returns whether a quit is pending. */
  413. bool (*should_quit) (emacs_env *env)
  414. EMACS_ATTRIBUTE_NONNULL(1);
  415. /* Processes pending input events and returns whether the module
  416. function should quit. */
  417. enum emacs_process_input_result (*process_input) (emacs_env *env)
  418. EMACS_ATTRIBUTE_NONNULL (1);
  419. struct timespec (*extract_time) (emacs_env *env, emacs_value arg)
  420. EMACS_ATTRIBUTE_NONNULL (1);
  421. emacs_value (*make_time) (emacs_env *env, struct timespec time)
  422. EMACS_ATTRIBUTE_NONNULL (1);
  423. bool (*extract_big_integer) (emacs_env *env, emacs_value arg, int *sign,
  424. ptrdiff_t *count, emacs_limb_t *magnitude)
  425. EMACS_ATTRIBUTE_NONNULL (1);
  426. emacs_value (*make_big_integer) (emacs_env *env, int sign, ptrdiff_t count,
  427. const emacs_limb_t *magnitude)
  428. EMACS_ATTRIBUTE_NONNULL (1);
  429. };
  430. struct emacs_env_28
  431. {
  432. /* Structure size (for version checking). */
  433. ptrdiff_t size;
  434. /* Private data; users should not touch this. */
  435. struct emacs_env_private *private_members;
  436. /* Memory management. */
  437. emacs_value (*make_global_ref) (emacs_env *env, emacs_value value)
  438. EMACS_ATTRIBUTE_NONNULL(1);
  439. void (*free_global_ref) (emacs_env *env, emacs_value global_value)
  440. EMACS_ATTRIBUTE_NONNULL(1);
  441. /* Non-local exit handling. */
  442. enum emacs_funcall_exit (*non_local_exit_check) (emacs_env *env)
  443. EMACS_ATTRIBUTE_NONNULL(1);
  444. void (*non_local_exit_clear) (emacs_env *env)
  445. EMACS_ATTRIBUTE_NONNULL(1);
  446. enum emacs_funcall_exit (*non_local_exit_get)
  447. (emacs_env *env, emacs_value *symbol, emacs_value *data)
  448. EMACS_ATTRIBUTE_NONNULL(1, 2, 3);
  449. void (*non_local_exit_signal) (emacs_env *env,
  450. emacs_value symbol, emacs_value data)
  451. EMACS_ATTRIBUTE_NONNULL(1);
  452. void (*non_local_exit_throw) (emacs_env *env,
  453. emacs_value tag, emacs_value value)
  454. EMACS_ATTRIBUTE_NONNULL(1);
  455. /* Function registration. */
  456. emacs_value (*make_function) (emacs_env *env,
  457. ptrdiff_t min_arity,
  458. ptrdiff_t max_arity,
  459. emacs_value (*func) (emacs_env *env,
  460. ptrdiff_t nargs,
  461. emacs_value* args,
  462. void *data)
  463. EMACS_NOEXCEPT
  464. EMACS_ATTRIBUTE_NONNULL(1),
  465. const char *docstring,
  466. void *data)
  467. EMACS_ATTRIBUTE_NONNULL(1, 4);
  468. emacs_value (*funcall) (emacs_env *env,
  469. emacs_value func,
  470. ptrdiff_t nargs,
  471. emacs_value* args)
  472. EMACS_ATTRIBUTE_NONNULL(1);
  473. emacs_value (*intern) (emacs_env *env, const char *name)
  474. EMACS_ATTRIBUTE_NONNULL(1, 2);
  475. /* Type conversion. */
  476. emacs_value (*type_of) (emacs_env *env, emacs_value arg)
  477. EMACS_ATTRIBUTE_NONNULL(1);
  478. bool (*is_not_nil) (emacs_env *env, emacs_value arg)
  479. EMACS_ATTRIBUTE_NONNULL(1);
  480. bool (*eq) (emacs_env *env, emacs_value a, emacs_value b)
  481. EMACS_ATTRIBUTE_NONNULL(1);
  482. intmax_t (*extract_integer) (emacs_env *env, emacs_value arg)
  483. EMACS_ATTRIBUTE_NONNULL(1);
  484. emacs_value (*make_integer) (emacs_env *env, intmax_t n)
  485. EMACS_ATTRIBUTE_NONNULL(1);
  486. double (*extract_float) (emacs_env *env, emacs_value arg)
  487. EMACS_ATTRIBUTE_NONNULL(1);
  488. emacs_value (*make_float) (emacs_env *env, double d)
  489. EMACS_ATTRIBUTE_NONNULL(1);
  490. /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
  491. null-terminated string.
  492. SIZE must point to the total size of the buffer. If BUFFER is
  493. NULL or if SIZE is not big enough, write the required buffer size
  494. to SIZE and return true.
  495. Note that SIZE must include the last null byte (e.g. "abc" needs
  496. a buffer of size 4).
  497. Return true if the string was successfully copied. */
  498. bool (*copy_string_contents) (emacs_env *env,
  499. emacs_value value,
  500. char *buf,
  501. ptrdiff_t *len)
  502. EMACS_ATTRIBUTE_NONNULL(1, 4);
  503. /* Create a Lisp string from a utf8 encoded string. */
  504. emacs_value (*make_string) (emacs_env *env,
  505. const char *str, ptrdiff_t len)
  506. EMACS_ATTRIBUTE_NONNULL(1, 2);
  507. /* Embedded pointer type. */
  508. emacs_value (*make_user_ptr) (emacs_env *env,
  509. void (*fin) (void *) EMACS_NOEXCEPT,
  510. void *ptr)
  511. EMACS_ATTRIBUTE_NONNULL(1);
  512. void *(*get_user_ptr) (emacs_env *env, emacs_value arg)
  513. EMACS_ATTRIBUTE_NONNULL(1);
  514. void (*set_user_ptr) (emacs_env *env, emacs_value arg, void *ptr)
  515. EMACS_ATTRIBUTE_NONNULL(1);
  516. void (*(*get_user_finalizer) (emacs_env *env, emacs_value uptr))
  517. (void *) EMACS_NOEXCEPT EMACS_ATTRIBUTE_NONNULL(1);
  518. void (*set_user_finalizer) (emacs_env *env, emacs_value arg,
  519. void (*fin) (void *) EMACS_NOEXCEPT)
  520. EMACS_ATTRIBUTE_NONNULL(1);
  521. /* Vector functions. */
  522. emacs_value (*vec_get) (emacs_env *env, emacs_value vector, ptrdiff_t index)
  523. EMACS_ATTRIBUTE_NONNULL(1);
  524. void (*vec_set) (emacs_env *env, emacs_value vector, ptrdiff_t index,
  525. emacs_value value)
  526. EMACS_ATTRIBUTE_NONNULL(1);
  527. ptrdiff_t (*vec_size) (emacs_env *env, emacs_value vector)
  528. EMACS_ATTRIBUTE_NONNULL(1);
  529. /* Returns whether a quit is pending. */
  530. bool (*should_quit) (emacs_env *env)
  531. EMACS_ATTRIBUTE_NONNULL(1);
  532. /* Processes pending input events and returns whether the module
  533. function should quit. */
  534. enum emacs_process_input_result (*process_input) (emacs_env *env)
  535. EMACS_ATTRIBUTE_NONNULL (1);
  536. struct timespec (*extract_time) (emacs_env *env, emacs_value arg)
  537. EMACS_ATTRIBUTE_NONNULL (1);
  538. emacs_value (*make_time) (emacs_env *env, struct timespec time)
  539. EMACS_ATTRIBUTE_NONNULL (1);
  540. bool (*extract_big_integer) (emacs_env *env, emacs_value arg, int *sign,
  541. ptrdiff_t *count, emacs_limb_t *magnitude)
  542. EMACS_ATTRIBUTE_NONNULL (1);
  543. emacs_value (*make_big_integer) (emacs_env *env, int sign, ptrdiff_t count,
  544. const emacs_limb_t *magnitude)
  545. EMACS_ATTRIBUTE_NONNULL (1);
  546. void (*(*EMACS_ATTRIBUTE_NONNULL (1)
  547. get_function_finalizer) (emacs_env *env,
  548. emacs_value arg)) (void *) EMACS_NOEXCEPT;
  549. void (*set_function_finalizer) (emacs_env *env, emacs_value arg,
  550. void (*fin) (void *) EMACS_NOEXCEPT)
  551. EMACS_ATTRIBUTE_NONNULL (1);
  552. int (*open_channel) (emacs_env *env, emacs_value pipe_process)
  553. EMACS_ATTRIBUTE_NONNULL (1);
  554. void (*make_interactive) (emacs_env *env, emacs_value function,
  555. emacs_value spec)
  556. EMACS_ATTRIBUTE_NONNULL (1);
  557. /* Create a unibyte Lisp string from a string. */
  558. emacs_value (*make_unibyte_string) (emacs_env *env,
  559. const char *str, ptrdiff_t len)
  560. EMACS_ATTRIBUTE_NONNULL(1, 2);
  561. };
  562. /* Every module should define a function as follows. */
  563. extern int emacs_module_init (struct emacs_runtime *runtime)
  564. EMACS_NOEXCEPT
  565. EMACS_ATTRIBUTE_NONNULL (1);
  566. #ifdef __cplusplus
  567. }
  568. #endif
  569. #endif /* EMACS_MODULE_H */