Skip to content
Snippets Groups Projects
Commit d7143bc3 authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

a way to export and import symbols across modules..

Rev: src/module_support.c:1.39
Rev: src/module_support.h:1.8
parent 4ee922db
No related branches found
No related tags found
No related merge requests found
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#include "stralloc.h" #include "stralloc.h"
#include "pike_types.h" #include "pike_types.h"
#include "pike_error.h" #include "pike_error.h"
#include "mapping.h"
#include "object.h"
RCSID("$Id: module_support.c,v 1.38 2000/12/01 08:09:50 hubbe Exp $"); RCSID("$Id: module_support.c,v 1.39 2000/12/13 21:35:05 hubbe Exp $");
/* Checks that args_to_check arguments are OK. /* Checks that args_to_check arguments are OK.
* Returns 1 if everything worked ok, zero otherwise. * Returns 1 if everything worked ok, zero otherwise.
...@@ -363,3 +365,61 @@ PMOD_EXPORT void get_all_args(char *fname, INT32 args, char *format, ... ) ...@@ -363,3 +365,61 @@ PMOD_EXPORT void get_all_args(char *fname, INT32 args, char *format, ... )
} }
} }
} }
/* NOTA BENE:
* The code below assumes that dynamic modules are not
* unloaded from memory...
*/
static struct mapping *exported_symbols;
static struct program *function_encapsulation_program;
PMOD_EXPORT void pike_module_export_symbol(char *name,
int len,
void *ptr)
{
struct pike_string *str=make_shared_binary_string(name,len);
struct svalue s;
if(!exported_symbols) exported_symbols=allocate_mapping(10);
s.u.refs=(INT32 *)ptr;
s.type=T_INT;
s.subtype=4711;
mapping_string_insert(exported_symbols, str, &s);
}
PMOD_EXPORT void *pike_module_import_symbol(char *name,
int len,
char *module,
int module_len)
{
struct svalue *s;
struct pike_string *str=make_shared_binary_string(name,len);
if(exported_symbols)
{
s=low_mapping_string_lookup(exported_symbols, str);
if(s && s->type == T_INT && s->subtype == 4711)
{
free_string(str);
return s->u.refs;
}
}
/* Load the module */
push_string(make_shared_binary_string(module,module_len));
SAFE_APPLY_MASTER("resolv",1);
pop_stack();
if(exported_symbols)
{
s=low_mapping_string_lookup(exported_symbols, str);
if(s && s->type == T_INT && s->subtype == 4711)
{
free_string(str);
return s->u.refs;
}
}
free_string(str);
return 0;
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
\*/ \*/
/* /*
* $Id: module_support.h,v 1.7 2000/07/28 17:16:55 hubbe Exp $ * $Id: module_support.h,v 1.8 2000/12/13 21:35:05 hubbe Exp $
*/ */
#ifndef MODULE_SUPPORT_H #ifndef MODULE_SUPPORT_H
#include <stdarg.h> #include <stdarg.h>
...@@ -24,6 +24,13 @@ struct expect_result { ...@@ -24,6 +24,13 @@ struct expect_result {
TYPE_T got; /* What type did we actually receive */ TYPE_T got; /* What type did we actually receive */
}; };
/* This should be used in module_init */
#define PIKE_MODULE_EXPORT(MOD, SYM) \
pike_module_export_symbol(#MOD "." #SYM, CONSTANT_STRLEN(#MOD "." #SYM), SYM)
#define PIKE_MODULE_IMPORT(MOD, SYM) \
pike_module_import_symbol(#MOD "." #SYM, CONSTANT_STRLEN(#MOD "." #SYM), #MOD, CONSTANT_STRLEN(#MOD))
/* Prototypes begin here */ /* Prototypes begin here */
PMOD_EXPORT int check_args(int args, ...); PMOD_EXPORT int check_args(int args, ...);
...@@ -36,6 +43,13 @@ PMOD_EXPORT int get_args(struct svalue *s, ...@@ -36,6 +43,13 @@ PMOD_EXPORT int get_args(struct svalue *s,
INT32 num_args, INT32 num_args,
char *fmt, ...); char *fmt, ...);
PMOD_EXPORT void get_all_args(char *fname, INT32 args, char *format, ... ); PMOD_EXPORT void get_all_args(char *fname, INT32 args, char *format, ... );
PMOD_EXPORT void pike_module_export_symbol(char *str,
int len,
void *ptr);
PMOD_EXPORT void *pike_module_import_symbol(char *str,
int len,
char *module,
int module_len);
/* Prototypes end here */ /* Prototypes end here */
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment