This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys-library.h
65 lines (55 loc) · 2.22 KB
/
sys-library.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
//
// File: %sys-library.h
// Summary: "Definitions for LIBRARY! (DLL, .so, .dynlib)"
// Project: "Rebol 3 Interpreter and Run-time (Ren-C branch)"
// Homepage: https://github.com/metaeducation/ren-c/
//
//=////////////////////////////////////////////////////////////////////////=//
//
// Copyright 2014 Atronix Engineering, Inc.
// Copyright 2014-2017 Ren-C Open Source Contributors
// REBOL is a trademark of REBOL Technologies
//
// See README.md and CREDITS.md for more information.
//
// Licensed under the Lesser GPL, Version 3.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.gnu.org/licenses/lgpl-3.0.html
//
//=////////////////////////////////////////////////////////////////////////=//
//
// A library represents a loaded .DLL or .so file. This contains native
// code, which can be executed through extensions. The type is also used to
// load and execute non-Rebol-aware C code by the FFI extension.
//
// File descriptor in singular->link.fd
// Meta information in singular->misc.meta
//
typedef Raw_Array REBLIB;
extern REBTYP *EG_Library_Type;
inline static bool IS_LIBRARY(Cell(const*) v) { // Note: QUOTED! doesn't count
return IS_CUSTOM(v) and CELL_CUSTOM_TYPE(v) == EG_Library_Type;
}
inline static void *LIB_FD(REBLIB *lib)
{ return lib->link.fd; } // (F)ile (D)escriptor
inline static bool IS_LIB_CLOSED(REBLIB *lib)
{ return lib->link.fd == nullptr; }
inline static REBLIB *VAL_LIBRARY(noquote(Cell(const*)) v) {
assert(CELL_CUSTOM_TYPE(v) == EG_Library_Type);
return ARR(VAL_NODE1(v));
}
inline static void *VAL_LIBRARY_FD(noquote(Cell(const*)) v) {
assert(CELL_CUSTOM_TYPE(v) == EG_Library_Type);
return LIB_FD(VAL_LIBRARY(v));
}
// !!! These functions are currently statically linked to by the FFI extension
// which should probably be finding a way to do this through the libRebol API
// instead. That could avoid the static linking--but it would require the
// library to give back HANDLE! or otherwise pointers that could be used to
// call the C functions.
//
extern void *Open_Library(const REBVAL *path);
extern void Close_Library(void *dll);
extern CFUNC *Find_Function(void *dll, const char *funcname);