Skip to content

Commit

Permalink
seg fault on info
Browse files Browse the repository at this point in the history
  • Loading branch information
duncantl committed May 17, 2019
1 parent 421e55c commit 831f70e
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 5 deletions.
56 changes: 56 additions & 0 deletions Rqpdf/DebuggingSegFault
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[sampleDocs-168]>R -d lldb
(lldb) target create "/Users/duncan/R-devel/build/bin/exec/R"
Current executable set to '/Users/duncan/R-devel/build/bin/exec/R' (x86_64).
(lldb) Rr
Process 37260 launched: '/Users/duncan/R-devel/build/bin/exec/R' (x86_64)

R Under development (unstable) (2018-11-10 r75583) -- "Unsuffered Consequences"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.7.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

PID = 37260
Time = 2019-05-17 07:26:44
Dir = /Users/duncan/DSI/Workshops/RCInterface/Rqpdf/inst/sampleDocs
getwd()
1> getwd()
[1] "/Users/duncan/DSI/Workshops/RCInterface/Rqpdf/inst/sampleDocs"
[26:47] 2> library(Rqpdf)
[26:49] 3> pdfInfo("rplot.pdf", "Author")
error: R debug map object file '/Users/duncan/R-devel/build/src/main/devices.o' has changed (actual time is 2019-04-06 07:38:53.000000000, debug map time is 2018-11-11 05:29:55.000000000) since this executable was linked, file will be ignored
Process 37260 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x00007fff70ca1232 libsystem_c.dylib`strlen + 18
libsystem_c.dylib`strlen:
-> 0x7fff70ca1232 <+18>: pcmpeqb (%rdi), %xmm0
0x7fff70ca1236 <+22>: pmovmskb %xmm0, %esi
0x7fff70ca123a <+26>: andq $0xf, %rcx
0x7fff70ca123e <+30>: orq $-0x1, %rax
Target 0: (R) stopped.
(lldb) up
R was compiled with optimization - stepping may behave oddly; variables may not be available.
frame #1: 0x000000010009c8de R`Rf_mkChar(name=0x0000000000000000) at envir.c:3763 [opt]
3760
3761 SEXP mkChar(const char *name)
3762 {
-> 3763 size_t len = strlen(name);
^
3764 if (len > INT_MAX)
3765 error("R character strings are limited to 2^31-1 bytes");
3766 return mkCharLenCE(name, (int) len, CE_NATIVE);
(lldb) print name
(const char *) $0 = 0x0000000000000000
(lldb) q
11 changes: 11 additions & 0 deletions Rqpdf/R/info.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

pdfInfo =
function(file, key)
{
file = path.expand(file)
if(!file.exists(file))
stop("no such file ", file)

.Call("R_get_pdf_info_val", file, as.character(key))
}

11 changes: 10 additions & 1 deletion Rqpdf/R/version.R.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
libqpdfVersion = @QPDF_VERSION@
libqpdfVersion = "@QPDF_VERSION@"


version =
function(runTime = TRUE)
{
if(runTime)
.Call("R_qpdf_version_rt")
else
libqpdfVersion
}
8 changes: 4 additions & 4 deletions Rqpdf/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ AC_INIT(src)
AC_PATH_PROG(PKG_CONFIG, pkg-config)

if test -z "$PKG_CONFIG" ; then
echo "Cannot find pkg-config
exit 1
echo "Cannot find pkg-config"
exit 1
fi

AC_SUBST(PKG_CONFIG)

QPDF_VERSION=`$PKG_CONFIG --modversion libqpdf`

QPDF_VERSION=`${PKG_CONFIG} --modversion libqpdf`
echo "QPDF Version = $QPDF_VERSION"
AC_SUBST(QPDF_VERSION)

AC_OUTPUT(src/Makevars R/version.R)
20 changes: 20 additions & 0 deletions Rqpdf/src/info.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <qpdf/qpdf-c.h>
#include <Rdefines.h>

// Get the key from the Info dictionary

SEXP
R_get_pdf_info_val(SEXP r_filename, SEXP r_key)
{
qpdf_data tmp = qpdf_init();
QPDF_ERROR_CODE err = qpdf_read(tmp, CHAR(STRING_ELT(r_filename, 0)), NULL);
if(err != QPDF_SUCCESS) {
PROBLEM "failed to read %s", CHAR(STRING_ELT(r_filename, 0))
ERROR;
}

char const * ans = qpdf_get_info_key(tmp, CHAR(STRING_ELT(r_key, 0)));
SEXP rans = ScalarString(mkChar(ans));
qpdf_cleanup(&tmp);
return(rans);
}

0 comments on commit 831f70e

Please sign in to comment.