Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
d7143bc3
Commit
d7143bc3
authored
24 years ago
by
Fredrik Hübinette (Hubbe)
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/module_support.c
+61
-1
61 additions, 1 deletion
src/module_support.c
src/module_support.h
+15
-1
15 additions, 1 deletion
src/module_support.h
with
76 additions
and
2 deletions
src/module_support.c
+
61
−
1
View file @
d7143bc3
...
@@ -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.3
8
2000/12/
01 08:09:50
hubbe Exp $"
);
RCSID
(
"$Id: module_support.c,v 1.3
9
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
;
}
This diff is collapsed.
Click to expand it.
src/module_support.h
+
15
−
1
View file @
d7143bc3
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
\*/
\*/
/*
/*
* $Id: module_support.h,v 1.
7
2000/
07/28 17:16:5
5 hubbe Exp $
* $Id: module_support.h,v 1.
8
2000/
12/13 21:35:0
5 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment