SCM Repository
Annotation of /sml/trunk/src/runtime/c-libs/c-libraries.c
Parent Directory
|
Revision Log
Revision 589 - (view) (download) (as text)
1 : | monnier | 249 | /* c-libraries.c |
2 : | * | ||
3 : | * COPYRIGHT (c) 1994 AT&T Bell Laboratories. | ||
4 : | * | ||
5 : | * This is the home of the CLibrary table, C library initialization code, | ||
6 : | * and C function lookup code. It is part of the run-time proper (not part | ||
7 : | * of libcfuns.a). | ||
8 : | */ | ||
9 : | |||
10 : | #ifdef OPSYS_UNIX | ||
11 : | # include "ml-unixdep.h" /* for the HAS_POSIX_LIBRARIES option flag */ | ||
12 : | #endif | ||
13 : | #include "ml-base.h" | ||
14 : | #include "ml-values.h" | ||
15 : | #include "c-library.h" | ||
16 : | |||
17 : | #define C_LIBRARY(lib) extern c_library_t lib; | ||
18 : | #include "clib-list.h" | ||
19 : | #undef C_LIBRARY | ||
20 : | |||
21 : | PVT c_library_t *CLibs[] = { | ||
22 : | #define C_LIBRARY(lib) &lib, | ||
23 : | # include "clib-list.h" | ||
24 : | #undef C_LIBRARY | ||
25 : | NIL(c_library_t *) | ||
26 : | }; | ||
27 : | |||
28 : | /* InitCFunList: | ||
29 : | * Initialize the list of C functions callable from ML. | ||
30 : | */ | ||
31 : | void InitCFunList () | ||
32 : | { | ||
33 : | int i, j, libNameLen; | ||
34 : | char *nameBuf; | ||
35 : | |||
36 : | for (i = 0; CLibs[i] != NIL(c_library_t *); i++) { | ||
37 : | c_library_t *clib = CLibs[i]; | ||
38 : | cfunc_binding_t *cfuns = CLibs[i]->cfuns; | ||
39 : | |||
40 : | if (clib->initFn != NIL(clib_init_fn_t)) { | ||
41 : | /* call the libraries initialization function */ | ||
42 : | (*(clib->initFn)) (0, 0/** argc, argv **/); | ||
43 : | } | ||
44 : | |||
45 : | /* register the C functions in the C symbol table */ | ||
46 : | libNameLen = strlen(clib->libName) + 2; /* incl "." and "\0" */ | ||
47 : | for (j = 0; cfuns[j].name != NIL(char *); j++) { | ||
48 : | nameBuf = NEW_VEC(char, strlen(cfuns[j].name) + libNameLen); | ||
49 : | sprintf (nameBuf, "%s.%s", clib->libName, cfuns[j].name); | ||
50 : | #ifdef INDIRECT_CFUNC | ||
51 : | RecordCSymbol (nameBuf, PTR_CtoML(&(cfuns[j]))); | ||
52 : | #else | ||
53 : | RecordCSymbol (nameBuf, PTR_CtoML(cfuns[j].cfunc)); | ||
54 : | #endif | ||
55 : | } | ||
56 : | } | ||
57 : | |||
58 : | } /* end of InitCFunList */ | ||
59 : | |||
60 : | /* BindCFun: | ||
61 : | * | ||
62 : | * Search the C function table for the given function; return ML_unit, if | ||
63 : | * not found. | ||
64 : | * NOTE: eventually, we will raise an exception when the function isn't found. | ||
65 : | */ | ||
66 : | ml_val_t BindCFun (char *moduleName, char *funName) | ||
67 : | { | ||
68 : | int i, j; | ||
69 : | |||
70 : | /* SayDebug("BIND: %s.%s\n", moduleName, funName); */ | ||
71 : | for (i = 0; CLibs[i] != NIL(c_library_t *); i++) { | ||
72 : | if (strcmp(CLibs[i]->libName, moduleName) == 0) { | ||
73 : | cfunc_binding_t *cfuns = CLibs[i]->cfuns; | ||
74 : | for (j = 0; cfuns[j].name != NIL(char *); j++) { | ||
75 : | if (strcmp(cfuns[j].name, funName) == 0) | ||
76 : | #ifdef INDIRECT_CFUNC | ||
77 : | return PTR_CtoML(&(cfuns[j])); | ||
78 : | #else | ||
79 : | return PTR_CtoML(cfuns[j].cfunc); | ||
80 : | #endif | ||
81 : | } | ||
82 : | /* here, we didn't find the library so we return ML_unit */ | ||
83 : | return ML_unit; | ||
84 : | } | ||
85 : | } | ||
86 : | |||
87 : | /* here, we didn't find the library so we return ML_unit */ | ||
88 : | return ML_unit; | ||
89 : | |||
90 : | } /* end of BindCFun */ | ||
91 : |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |