Skip to content

Commit

Permalink
Merge pull request #116 from paleolimbot/more-c
Browse files Browse the repository at this point in the history
Drop cpp11 dependency
  • Loading branch information
paleolimbot authored Dec 16, 2021
2 parents 21fbc04 + 7c84901 commit 8161e8b
Show file tree
Hide file tree
Showing 19 changed files with 564 additions and 211 deletions.
3 changes: 1 addition & 2 deletions .covrignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
inst/include/wk
src/cpp11.cpp
src/fast_float/fast_float.h
src/internal/fast_float/fast_float.h
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
LinkingTo: cpp11
SystemRequirements: C++11
Suggests:
testthat (>= 3.0.0),
Expand Down
9 changes: 0 additions & 9 deletions R/cpp11.R

This file was deleted.

10 changes: 9 additions & 1 deletion R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ wk_format <- function(handleable, precision = 7, trim = TRUE, max_coords = 6, ..
#' @rdname wk_format
#' @export
wkt_format_handler <- function(precision = 7, trim = TRUE, max_coords = 6) {
new_wk_handler(wk_cpp_wkt_formatter(precision, trim, max_coords), "wk_wkt_formatter")
new_wk_handler(
.Call(
wk_c_wkt_formatter,
as.integer(precision)[1],
as.logical(trim)[1],
as.integer(max_coords)[1]
),
"wk_wkt_formatter"
)
}
16 changes: 3 additions & 13 deletions R/handle-wkt.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,24 @@ wk_handle.wk_wkt <- function(handleable, handler, ...) {
handler <- as_wk_handler(handler)
.Call(
wk_c_read_wkt,
list(
handleable,
4096L,
TRUE
),
list(handleable, TRUE),
handler
)
}

#' Test handlers for handling of unknown size vectors
#'
#' @inheritParams wk_handle
#' @param wkt_parser_buffer_size Buffer size to use for the parser. Useful
#' for testing the parser.
#' @export
#'
#' @examples
#' handle_wkt_without_vector_size(wkt(), wk_vector_meta_handler())
#'
handle_wkt_without_vector_size <- function(handleable, handler, wkt_parser_buffer_size = 4096) {
handle_wkt_without_vector_size <- function(handleable, handler) {
handler <- as_wk_handler(handler)
.Call(
wk_c_read_wkt,
list(
handleable,
as.integer(wkt_parser_buffer_size)[1],
FALSE
),
list(handleable, FALSE),
handler
)
}
9 changes: 8 additions & 1 deletion R/wkt-writer.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@
#' @rdname wk_writer
#' @export
wkt_writer <- function(precision = 16L, trim = TRUE) {
new_wk_handler(wk_cpp_wkt_writer(precision, trim), "wk_wkt_writer")
new_wk_handler(
.Call(
wk_c_wkt_writer,
as.integer(precision)[1],
as.logical(trim)[1]
),
"wk_wkt_writer"
)
}
56 changes: 56 additions & 0 deletions data-raw/make_callentries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@


library(tidyverse)

src_files <- list.files("src", "\\.(c|cpp)$", full.names = TRUE)
src_sources <- src_files %>% set_names() %>% map_chr(readr::read_file)

defs <- tibble(
def = src_sources %>%
str_extract_all(regex("SEXP wk_c_[^\\)]+\\)\\s+", multiline = TRUE)) %>%
unlist() %>%
str_replace_all("\\s+", " ") %>%
str_trim(),
name = def %>% str_extract("wk_c_[^\\(]+"),
return_type = "SEXP",
args = def %>%
str_remove("SEXP wk_c_[^\\(]+\\(") %>%
str_remove("\\)$") %>%
str_split("\\s*,\\s*") %>%
map(~{if(identical(.x, "")) character(0) else .x}),
n_args = map(args, length)
)

call_headers <- paste0(
"extern ", defs$def, ";",
collapse = "\n"
)
call_entries <- paste0(
' {"', defs$name, '", (DL_FUNC) &', defs$name, ', ', defs$n_args, "},",
collapse = "\n"
)

header <- glue::glue('
/* generated by data-raw/make_callentries.R */
{call_headers}
static const R_CallMethodDef CallEntries[] = {{
{call_entries}
{{NULL, NULL, 0}}
}};
/* end generated by data-raw/make_callentries.R */
')

# rewrite relevant portion of init.c
init <- read_file("src/init.c")
pattern <- regex(
"\n/\\* generated by data-raw/make_callentries\\.R \\*/.*?/\\* end generated by data-raw/make_callentries\\.R \\*/",
multiline = TRUE,
dotall = TRUE
)

stopifnot(str_detect(init, pattern))
init %>%
str_replace(pattern, header) %>%
write_file("src/init.c")
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "cpp11/external_pointer.hpp"
#include "wk-v1.h"
#include "wk-v1-handler.hpp"
#include "wk-v1-handler-cpp11.hpp"

class WKIdentityFilter: public WKVoidHandler {
public:
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 1 addition & 8 deletions man/handle_wkt_without_vector_size.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 0 additions & 91 deletions src/cpp11.cpp

This file was deleted.

Loading

0 comments on commit 8161e8b

Please sign in to comment.