search for: mkchar

Displaying 20 results from an estimated 105 matches for "mkchar".

2004 Jun 14
5
mkChar can be interrupted
Hi, As was discussed earlier in another thread and as documented in R-exts .Call() should not be interruptible by Ctrl-C. However the following code, which spends most of its time inside mkChar, turned out to be interruptible on RH-7.3 R-1.8.1 gcc-2.96: #include <Rinternals.h> #include <R.h> SEXP foo0(const SEXP nSexp) { int i, n; SEXP resSexp; if (!isInteger(nSexp)) error("wrong arg type\n"); n = asInteger(nSexp); resSexp = PROTECT(allocVector(S...
2005 Apr 12
5
How allocate STRSXP outside of gc
Hi, I am trying to figure a way to allocate a string SEXP so that gc() won't ever collect it. Here is a little bit of a background. Suppose I want to write a .Call-callable function that upon each call returns the same value, say mkChar("foo"): SEXP getFoo() { return mkChar("foo"); } The above implementation doesn't take advantage of the fact that mkChar("foo") could be pre-computed only once, and then the function would return the pre-computed value. So the question is how to create this p...
2013 Jun 27
3
Read a text file into R with .Call()
...ant to read a text file into R with .Call(). So I define some NEW_CHARACTER() to store the chracters read and use SET_STRING_ELT to fill the elements. e.g. PROTECT(qNames = NEW_CHARACTER(10000)); char *foo; // This foo holds the string I want. while(foo = readLine(FN)){ SET_STRING_ELT(qNames, i, mkChar(foo))); } In this way, I can get the desired character from qNames. The only problem is that "mkChar" will make every foo string into a global CHARSXP cache. When I have a huge amount of file to read, the CHARSXP cache use too much memory. I do not know whether there is any other way to...
2019 Aug 02
4
Infrequent but steady NULL-pointer caused segfault in as.POSIXlt.POSIXct (R 3.4.4)
...quot;%H%M") 7: format(Sys.time(), format = "%H%M") ? ? I looked into the dumped core with gdb, and found something very strange: gdb /usr/lib64/R/bin/exec/R ~/core.30387 (gdb) bt 5 #0 0x00007f1dca844ff1 in __strlen_sse2_pminub () from /lib64/libc.so.6 #1 0x00007f1dcb20e8f9 in Rf_mkChar (name=0x0) at envir.c:3725 #2 0x00007f1dcb1dc225 in do_asPOSIXlt (call=<optimized out>, op=<optimized out>, args=<optimized out>, env=<optimized out>) at datetime.c:705 #3 0x00007f1dcb22197f in bcEval (body=body at entry=0x4064b28, rho=rho at entry=0xc449d38, useCache=...
2008 Oct 28
2
A question about the API mkchar()
Hi guys, I've got a question about the API mkchar(). I have met some difficulty in parsing utf-8 string to mkchar() in R-2.7.0. I was intending to parse an utf-8 string str_jan (some Japanese characters such as?, whose utf-8 code is E381B5) to R API SEXP mkChar(const char *name) , we only need to create the SEXP using the string that we parsed....
1998 Sep 22
1
"Segmentation Fault - core dumped" in R 0.62.3
I am occasional getting "Segmentation Fault - core dumped" in R 0.62.3 (I think more often then I did in 0.62.2). I have not been able to do this in any reliably reproducible way yet, but thought I would mention the problem in case some else can isolate it. Paul Gilbert -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read
2019 Aug 04
1
Infrequent but steady NULL-pointer caused segfault in as.POSIXlt.POSIXct (R 3.4.4)
...? > > > > I looked into the dumped core with gdb, and found something very strange: > > > > gdb /usr/lib64/R/bin/exec/R ~/core.30387 > > (gdb) bt 5 > > #0 0x00007f1dca844ff1 in __strlen_sse2_pminub () from /lib64/libc.so.6 > > #1 0x00007f1dcb20e8f9 in Rf_mkChar (name=0x0) at envir.c:3725 > > #2 0x00007f1dcb1dc225 in do_asPOSIXlt (call=<optimized out>, > > op=<optimized out>, args=<optimized out>, > > env=<optimized out>) at datetime.c:705 > > #3 0x00007f1dcb22197f in bcEval (body=body at entry=0x4064b...
2003 Sep 05
1
Problem with S4 slots in C code (PR#4073)
...5)); PROTECT(d1 = allocVector(INTSXP, 1)); INTEGER(d1)[0] = 1; SET_VECTOR_ELT(dimnames, 0, d1); PROTECT(d2 = allocVector(INTSXP, 1)); INTEGER(d2)[0] = 2000; SET_VECTOR_ELT(dimnames, 1, d2); PROTECT(d3 = allocVector(STRSXP, 1)); SET_STRING_ELT(d3, 0, mkChar("combined")); SET_VECTOR_ELT(dimnames, 2, d3); PROTECT(d4 = allocVector(STRSXP, 1)); SET_STRING_ELT(d4, 0, mkChar("all")); SET_VECTOR_ELT(dimnames, 3, d4); PROTECT(d5 = allocVector(STRSXP, 1)); SET_STRING_ELT(d5, 0, mkChar("all"));...
2004 Jun 08
5
fast mkChar
Hi, To speed up reading of large (few million lines) CSV files I am writing custom read functions (in C). By timing various approaches I figured out that one of the bottlenecks in reading character fields is the mkChar() function which on each call incurs a lot of garbage-collection-related overhead. I wonder if there is a "vectorized" version of mkChar, say mkChar2(char **, int length) that converts an array of C strings to a string vector, which somehow amortizes the gc overhead over the entire arra...
2004 Jun 30
2
Slow IO: was [R] naive question
...ads from a connection char-by-char as opposed to the buffered read. Reading each char requires a call to scanchar() which then calls Rconn_fgetc() (with some non-trivial overhead). Rconn_fgetc() on its part is defined somewhere else (not in scan.c) and therefore the call can not be inlined, etc. B) mkChar, which is used very extensively, is too slow. There are ways to minimize the number of calls to mkChar, but I won't expand on it in this message. I brought this up because it seems that many people believe that the slowness is inherent and is a tradeoff for something else. I don't think th...
2019 Aug 02
0
Infrequent but steady NULL-pointer caused segfault in as.POSIXlt.POSIXct (R 3.4.4)
..., format = "%H%M") > ? ? > > I looked into the dumped core with gdb, and found something very strange: > > gdb /usr/lib64/R/bin/exec/R ~/core.30387 > (gdb) bt 5 > #0 0x00007f1dca844ff1 in __strlen_sse2_pminub () from /lib64/libc.so.6 > #1 0x00007f1dcb20e8f9 in Rf_mkChar (name=0x0) at envir.c:3725 > #2 0x00007f1dcb1dc225 in do_asPOSIXlt (call=<optimized out>, > op=<optimized out>, args=<optimized out>, > env=<optimized out>) at datetime.c:705 > #3 0x00007f1dcb22197f in bcEval (body=body at entry=0x4064b28, > rho=rho at...
2006 Nov 17
1
Manipulating R lists in C
...olumeStr, priceStr, typeValStr; SEXP priceList; // create main list of vectors (unspecific items ) PROTECT( priceList = allocVector( VECSXP, 3 ) ); // for each item create a label and attach value PROTECT( typeValStr = allocVector( STRSXP, 1 ) ); SET_STRING_ELT( typeValStr, 0, mkChar( getPriceDataTypeAsString( p.getData().getType() ).c_str() ) ); SET_STRING_ELT( priceList, 0, typeValStr) ; SEXP priceSXP; PROTECT( priceSXP = allocVector( REALSXP, 1) ); REAL(priceSXP)[0] = p.getData().getPrice(); SET_VECTOR_ELT( priceList, 1, priceSXP); SEXP volumeSXP; PROT...
2016 May 12
3
Suggestion: mkString(NULL) should be NA
I would like to propose that Rf_mkString(NULL) and Rf_mkChar(NULL) return NA rather than segfault. Case: the mkString() and mkChar() functions are convenient to wrap strings returned by e.g. external C libraries into an R vector. However sometimes a library returns NULL instead of a string when the result is unavailable. In some C libraries this can happen...
2009 Jun 26
1
bug in Rf_PrintValue ?
...E", the segfault does not occur. /* bug.c */ #include <stdio.h> #include <Rinternals.h> #include <Rembedded.h> int main(int argc, char **argv) { char *x = "foo"; char *y = "coverage"; SEXP x_r, y_r; Rf_initEmbeddedR(argc, argv); PROTECT( x_r = mkChar( x ) ); Rf_PrintValue( x_r ); printf( "OK\n" ); PROTECT( y_r = mkChar( y ) ); Rf_PrintValue( y_r ); printf( "OK\n" ); UNPROTECT( 2 ); return 0; } I compile this code with: % env -i PATH=/bin:/usr/bin ./myR/bin/R CMD LINK gcc -g -I./R-2.9.0/src/include -L./myR/l...
2008 Apr 14
1
clean-up actions after non-local exits
...ample, do people deal with a situation where their C (C++) function opens a file and then receives a signal or longjump-s on error(), how do they make sure the file is eventually closed? Thanks, Vadim On Mon, 14 Jun 2004, Vadim Ogranovich wrote: > This is disappointing. How on Earth can mkChar know when it is safe or > not to make a long jump? For example if I just opened a file how am I > supposed to close it after the long jump? I am not even talking about > C++ where long jumps are simply devastating... (and this is the language > I am coding in :-( ) > > Ok. A pract...
2014 Jun 26
1
using 2D array of SEXP for creating dataframe
...istnames[2] = {"int","string"}; int i,j; //============================= PROTECT(df = allocVector(VECSXP,2)); *PROTECT(valueVector[0] = allocVector(REALSXP,3));* *PROTECT(valueVector[1] = allocVector(VECSXP,3));* PROTECT(lsnm = allocVector(STRSXP,2)); SET_STRING_ELT(lsnm,0,mkChar("int")); SET_STRING_ELT(lsnm,1,mkChar("string")); SEXP rawvec,headr; unsigned char str[24]="abcdef"; for ( i = 0 ; i < 3; i++ ) { *SET_STRING_ELT(valueVector[1],i,mkChar(ab[i]));* *REAL(valueVector[0])[i] = sn[i];* } It works , data frame is being created and ex...
2014 Mar 06
1
Create dataframe in C from table and return to R
...uot;vv","gy"}; int sn[3] ={99,89,12}; char *listnames[2] = {"int","string"}; int i; PROTECT(df = allocVector(VECSXP,2)); PROTECT(dfint = allocVector(INTSXP,3)); PROTECT(dfStr = allocVector(STRSXP,3)); PROTECT(lsnm = allocVector(STRSXP,2)); SET_STRING_ELT(lsnm,0,mkChar("int")); SET_STRING_ELT(lsnm,1,mkChar("string")); for ( i = 0 ; i < 3; i++ ) { SET_STRING_ELT(dfStr,i,mkChar(ab[i])); INTEGER(dfint)[i] = sn[i]; } SET_VECTOR_ELT(df,0,dfint); SET_VECTOR_ELT(df,1,dfStr); setAttrib(df,R_NamesSymbol,lsnm); //PROTECT(dfm=LCONS(dfm,list3(dfm,R_Mi...
2015 Dec 07
2
inconsistency in POSIXlt
The documentation for the POSIXlt class states '"POSIXlt" objects will often have an attribute "tzone", a character vector of length 3 giving the time zone name from the TZ environment variable and the names of the base time zone and the alternate (daylight-saving) time zone. Sometimes this may just be of length one, giving the time zone
2004 Mar 17
1
best methods for strings and structures?
...min_prism_dbh; double baf; unsigned long max_sample_size; unsigned long use_precip_in_hg; }; with an internal function and I'm building the return object using the following code: PROTECT( ret_val = allocVector( VECSXP, 13 ) ); SET_STRING_ELT( ret_val, 0, mkChar( cfg_rec.coeffs_filename) ); SET_STRING_ELT( ret_val, 1, mkChar( cfg_rec.species_filename) ); SET_VECTOR_ELT( ret_val, 2, ScalarInteger( cfg_rec.use_random_error ) ); SET_VECTOR_ELT( ret_val, 3, ScalarInteger( cfg_rec.random_seed ) ); SET_VECTOR_ELT( ret_val, 4, ScalarInteger( cfg_rec.e...
2001 Dec 03
0
Segfault in foreign:read.xport (PR#1192)
...c = strchr(tmpchar, ' '); 592 *c = '\0'; 593 SET_STRING_ELT(VECTOR_ELT(data, k), j, 594 (c == tmpchar) ? R_BlankString : 595 mkChar(tmpchar)); 596 } (gdb) print tmpchar $1 = 0xb63674 "0502" (gdb) print c $2 = 0x0 According to the solaris man pages, strchr returns NULL if there is no match. Changing lines 591 and 592 to add an appropriate test for null seems to fix the problem: 590...