annotate R/rdc/demo/malloc.R @ 37:8c8f848131c6

- version bump - better doc - made calling convention mode reset by default, as only way to specify convention used is via signature string
author Tassilo Philipp
date Mon, 13 Apr 2020 20:08:54 +0200
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