Debian Codegraph @

tools/symbols.R

raw
1 # Note: we can only lookup symbols that are available in the installed version of libcurl
2 # Therefore you should only update the symbol table using the latest version of libcurl.
3 # On Mac: 'brew install curl' will install to /usr/local/opt/curl
4
5 # Function to read a symbol
6 library(inline)
7 getsymbol <- function(name){
8 tryCatch({
9 fun = cfunction(
10 cppargs="-I/opt/homebrew/opt/curl/include",
11 includes = '#include <curl/curl.h>',
12 body = paste("return ScalarInteger((int)", name, ");")
13 )
14 val = fun()
15 rm(fun); gc();
16 cat("Found:", name, "=", val, "\n")
17 return(val)
18 }, error = function(e){NA_integer_})
19 }
20
21 # The symbols-in-versions file is included with libcurl
22 txt <- scan("tools/symbols-in-versions", character(), sep = "\n", skip = 13)
23 lines <- strsplit(txt, "[ ]+")
24 symbols <- as.data.frame(t(vapply(lines, `[`, character(4), 1:4)), stringsAsFactors = FALSE)
25 names(symbols) <- c("name", "introduced", "deprecated", "removed")
26
27 # Get current version
28 avail <- is.na(symbols$removed)
29
30 # Lookup all symbol values from curl.h (takes a while)
31 symbols$value <- NA_integer_;
32 available_symbols <- symbols$name[avail]
33 symbols$value[avail] <- vapply(available_symbols, getsymbol, integer(1))
34
35 # Compute type for options
36 type_name <- c("integer", "string", "function", "number")
37 type <- cut(symbols$value, c(-Inf, 0, 10000, 20000, 30000, 40000, Inf),
38 labels = FALSE, right = FALSE)
39 type[is.na(type)] <- 1
40
41 symbols$type <- c("unknown", "integer", "string", "function", "number", "unknown")[type]
42
43 option <- grepl("CURLOPT", symbols$name)
44 symbols$type[!option] <- NA
45
46 # Save as lazy data
47 curl_symbol_data <- symbols[order(symbols$name), ]
48 row.names(curl_symbol_data) = NULL
49 save(curl_symbol_data = curl_symbol_data, file = 'R/sysdata.rda', version = 2)
50 #usethis::use_data(curl_symbol_data, overwrite = TRUE)