Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Julien Lopez
QueryR
Commits
99f4127a
Commit
99f4127a
authored
8 years ago
by
Mick Jordan
Browse files
Options
Downloads
Patches
Plain Diff
embedded test: switch back to explicit functions from dlopen/dlsym
parent
d6c0c388
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.test.native/embedded/src/main.c
+20
-49
20 additions, 49 deletions
com.oracle.truffle.r.test.native/embedded/src/main.c
with
20 additions
and
49 deletions
com.oracle.truffle.r.test.native/embedded/src/main.c
+
20
−
49
View file @
99f4127a
...
...
@@ -50,19 +50,15 @@
// A simple test program for FastR embedded mode.
// compile with "gcc -I include main.c -ldl
#include
<stdio.h>
#include
<dlfcn.h>
#include
<sys/utsname.h>
#include
<string.h>
#define R_INTERFACE_PTRS 1
#include
<Rinterface.h>
#include
<Rembedded.h>
typedef
int
(
*
Rf_initEmbeddedRFunc
)(
int
,
char
**
);
typedef
void
(
*
Rf_endEmbeddedRFunc
)(
int
);
typedef
void
(
*
Rf_mainloopFunc
)(
void
);
typedef
void
(
*
R_DefParamsFunc
)(
Rstart
);
typedef
void
(
*
R_SetParamsFunc
)(
Rstart
);
void
(
*
ptr_stdR_CleanUp
)(
SA_TYPE
,
int
,
int
);
void
(
*
ptr_stdR_Suicide
)(
const
char
*
);
...
...
@@ -91,47 +87,22 @@ void testR_WriteConsole(const char *buf, int len) {
}
int
main
(
int
argc
,
char
**
argv
)
{
struct
utsname
utsname
;
uname
(
&
utsname
);
char
*
r_home
=
getenv
(
"R_HOME"
);
if
(
r_home
==
NULL
)
{
printf
(
"R_HOME must be set
\n
"
);
exit
(
1
);
}
char
libr_path
[
256
];
strcpy
(
libr_path
,
r_home
);
if
(
strcmp
(
utsname
.
sysname
,
"Linux"
)
==
0
)
{
strcat
(
libr_path
,
"lib/libR.so"
);
}
else
if
(
strcmp
(
utsname
.
sysname
,
"Darwin"
)
==
0
)
{
strcat
(
libr_path
,
"lib/libR.dylib"
);
}
void
*
handle
=
dlopen
(
libr_path
,
RTLD_LAZY
|
RTLD_GLOBAL
);
if
(
handle
==
NULL
)
{
printf
(
"failed to open libR: %s
\n
"
,
dlerror
());
exit
(
1
);
}
Rf_initEmbeddedRFunc
init
=
(
Rf_initEmbeddedRFunc
)
dlsym
(
handle
,
"Rf_initEmbeddedR"
);
Rf_mainloopFunc
mainloop
=
(
Rf_mainloopFunc
)
dlsym
(
handle
,
"run_Rmainloop"
);
Rf_endEmbeddedRFunc
end
=
(
Rf_endEmbeddedRFunc
)
dlsym
(
handle
,
"Rf_endEmbeddedR"
);
if
(
init
==
NULL
||
mainloop
==
NULL
||
end
==
NULL
)
{
printf
(
"failed to find R embedded functions
\n
"
);
exit
(
1
);
}
(
*
init
)(
argc
,
argv
);
structRstart
rp
;
Rstart
Rp
=
&
rp
;
R_DefParamsFunc
defp
=
(
R_DefParamsFunc
)
dlsym
(
handle
,
"R_DefParams"
);
(
*
defp
)(
Rp
);
Rp
->
SaveAction
=
SA_SAVEASK
;
R_SetParamsFunc
setp
=
(
R_SetParamsFunc
)
dlsym
(
handle
,
"R_SetParams"
);
(
*
setp
)(
Rp
);
ptr_stdR_CleanUp
=
ptr_R_CleanUp
;
ptr_R_CleanUp
=
&
testR_CleanUp
;
ptr_R_Suicide
=
&
testR_Suicide
;
ptr_R_ReadConsole
=
&
testR_ReadConsole
;
ptr_R_WriteConsole
=
&
testR_WriteConsole
;
(
*
mainloop
)();
(
*
end
)(
0
);
char
*
r_home
=
getenv
(
"R_HOME"
);
if
(
r_home
==
NULL
)
{
printf
(
"R_HOME must be set
\n
"
);
exit
(
1
);
}
Rf_initialize_R
(
argc
,
argv
);
structRstart
rp
;
Rstart
Rp
=
&
rp
;
R_DefParams
(
Rp
);
Rp
->
SaveAction
=
SA_SAVEASK
;
R_SetParams
(
Rp
);
ptr_stdR_CleanUp
=
ptr_R_CleanUp
;
ptr_R_CleanUp
=
&
testR_CleanUp
;
ptr_R_Suicide
=
&
testR_Suicide
;
ptr_R_ReadConsole
=
&
testR_ReadConsole
;
ptr_R_WriteConsole
=
&
testR_WriteConsole
;
Rf_mainloop
();
Rf_endEmbeddedR
(
0
);
}
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