annotate R/rdc/demo/malloc.R @ 9:8a45a05ff64e

- go binding cleanup, not enforcing relative paths anymore, readme update
author cslag
date Sat, 26 Mar 2016 01:09:51 +0100
parents 0cfcc391201f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 # File: rdc/demo/malloc.R
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 # Description: sample demo to get malloc/free functions
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 if( .Platform$OS.type == "windows" ) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 .windir <- paste(Sys.getenv("windir")[[1]],"\\system32\\",sep="")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 .libC <- paste(.windir,"msvcrt",sep="")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 } else {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 sysname <- Sys.info()[["sysname"]]
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 if (sysname == "Darwin")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 .libC <- "/usr/lib/libc.dylib"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 } else {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 .libC <- "/lib/libc.so.6"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 dyn.load(.libC)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 bind <- function(name, signature)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 address <- getNativeSymbolInfo(name)$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 assign(name, function(...) rdcCall(address,signature,...), parent.frame() )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 bind("malloc","i)p")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 bind("free","p)v")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27