2 * effi.h --- Header for Foreign Function Interface.
4 * Copyright (C) 2004 Evgeny Zajcev.
5 * Copyright (C) 2008 Steve Youngs.
7 This file is part of SXEmacs
9 SXEmacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 SXEmacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #ifndef _SXEMACS_EFFI_H_
23 #define _SXEMACS_EFFI_H_
25 #ifndef FFI_STACK_SIZE
26 #define FFI_STACK_SIZE 4096
27 #endif /* FFI_STACK_SIZE */
34 struct Lisp_EffiObject {
36 struct lcrecord_header header;
38 struct old_lcrecord_header header;
40 Lisp_Object type; /* type of ffi object */
41 Lisp_Object size; /* size of ffi object type */
43 Lisp_Object plist; /* properties list */
47 #define EFFI_FOT_NONE 0 /* fop is not used */
48 #define EFFI_FOT_BIND 2 /* fop is reference to foreign data */
49 #define EFFI_FOT_FUNC 3 /* fop is pointer to function */
52 * Declared as union just for the style, there no problem to
53 * always use fop.generic to access pointer.
56 void *ptr; /* pointer to foreign data */
57 void *fun; /* pointer to foreign function */
58 void *generic; /* generic storer */
61 size_t storage_size; /* size of storage */
62 char fostorage[0]; /* storage */
65 #define EFFIO_HAS_FOP(fo) ((fo)->fotype != EFFI_FOT_NONE)
67 typedef struct Lisp_EffiObject Lisp_EffiObject;
69 DECLARE_LRECORD(ffiobject, Lisp_EffiObject);
70 #define XEFFIO(x) XRECORD (x, ffiobject, Lisp_EffiObject)
72 # define XSETEFFIO(x, p) XSETRECORD (x, p, ffiobject)
74 # define wrap_effio(p) wrap_record (p, ffiobject)
76 #define EFFIOP(x) RECORDP (x, ffiobject)
77 #define CHECK_EFFIO(x) CHECK_RECORD (x, ffiobject)
78 #define CONCHECK_EFFIO(x) CONCHECK_RECORD (x, ffiobject)
80 EXFUN(Fffi_slot_offset, 2);
81 EXFUN(Fffi_size_of_type, 1);
85 #include "events/event-queue.h"
87 typedef struct ffi_job_s *ffi_job_t;
92 /* the foreign function and its args */
95 Lisp_Object *fof_args;
97 /* the sentinel and its args */
100 Lisp_Object *sntnl_args;
107 #define ffi_job(_x) (((ffi_job_t)worker_job_data(_x)))
108 #define ffi_job_sentinel(_x) (ffi_job(_x)->sntnl)
109 #define ffi_job_result(_x) (ffi_job(_x)->result)
110 #define XFFI_JOB(_x) ((ffi_job_t)(XWORKER_JOB_DATA(_x)))
111 #define FFI_JOBP(_x) \
112 (WORKER_JOBP(_x) && XWORKER_JOB_HANDLER(_x) == &ffi_job_handler)
113 #define CHECK_FFI_JOB(_x) \
116 dead_wrong_type_argument(Qffi_jobp, _x); \
118 #define CONCHECK_FFI_JOB(_x) \
121 return wrong_type_argument(Qffi_jobp, _x); \
124 #endif /* EF_USE_ASYNEQ */
126 #endif /* _SXEMACS_FFI_H_ */