-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathemacs-module-helpers.h
92 lines (72 loc) · 2.8 KB
/
emacs-module-helpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* From https://github.com/jkitchin/emacs-modules */
#include "emacs-module.h"
#ifndef EMACS_MODULE_HELPERS_H_
#define EMACS_MODULE_HELPERS_H_
#ifdef __cplusplus
extern "C"
{
#endif
// from dbg.h in Learn C the Hard Way
#include <errno.h>
#include <stdio.h>
#include <string.h>
#ifdef NDEBEG
#define debug(M, ...)
#else
#define debug(M, ...) \
fprintf(stderr, "DEBUG %s:%d ", M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#endif
#define clean_errno() (errno == 0 ? "None" : strerror(errno))
#define log_err(M, ...) \
fprintf(stderr, "[ERROR] (%s:%d errno: %s) " M "\n", __FILE__, __LINE__, \
clean_errno(), ##__VA_ARGS__)
#define log_warn(M, ...) \
fprintf(stderr, "[WARN] (%s:%d errno: %s) " M "\n", __FILE__, __LINE__, \
clean_errno(), ##__VA_ARGS__)
#define log_info(M, ...) \
fprintf(stderr, "[INFO] (%s:%d errno: %s) " M "\n", __FILE__, __LINE__, \
clean_errno(), ##__VA_ARGS__)
#define check(A, M, ...) \
if (!(A)) { \
log_err(M, ##VA_ARGS__); \
errno = 0; \
goto error; \
}
#define sentinel(M, ...) \
{ \
log_err(M, ##VA_ARGS__); \
errno = 0; \
goto error; \
}
#define check_mem(A) check((A), "Out of memory")
#define check_debug(A, M, ...) \
if (!(A)) { \
debug(M, ##__VA_ARGS__); \
errno = 0; \
goto error; \
}
/* Emacs symbols. */
extern emacs_value Qt;
extern emacs_value Qnil;
void defconsti(emacs_env* env, const char* name, int value,
const char* doc);
void defconsts(emacs_env* env, const char* name, const char* value,
const char* doc);
void defconst(emacs_env* env, const char* name, double value,
const char* doc);
double extract_double(emacs_env* env, emacs_value arg);
int extract_integer(emacs_env* env, emacs_value arg);
char* copy_string_contents(emacs_env* env, emacs_value arg, size_t* len);
emacs_value intern(emacs_env* env, const char* feature);
void bind_function(emacs_env* env, const char* name, emacs_value Sfun);
// I could not figure out how to define this as a function, so we use this
// define instead.
#define DEFUN(lsym, csym, amin, amax, doc, data) \
bind_function(env, lsym, \
env->make_function(env, amin, amax, csym, doc, data))
void provide(emacs_env* env, const char* feature);
void require(emacs_env* env, const char* feature);
#ifdef __cplusplus
}
#endif
#endif // EMACS_MODULE_HELPERS_H_