- Notifications
You must be signed in to change notification settings - Fork83
Use cpp11#405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Use cpp11#405
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| const xmlChar* uri = (xmlChar*)Rf_translateCharUTF8(STRING_ELT(x_sxp, i)); | ||
| SET_STRING_ELT(out, i,Xml2String(xmlBuildURI(uri, base_uri)).asRString()); | ||
| const xmlChar* uri = (xmlChar*)Rf_translateCharUTF8(x_sxp[i]); | ||
| out[i] =Xml2String(xmlBuildURI(uri, base_uri)).asRString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I guess the slow down due to cpp11 protection probably doesn't matter so much here (https://cpp11.r-lib.org/articles/FAQ.html#ok-but-i-really-want-to-call-cpp11unwind_protect-manually).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yea if it isn't critical then I'd probably leave as is
| for (int i =0; i < n; ++i) { | ||
| const xmlChar* uri = (xmlChar*)Rf_translateCharUTF8(STRING_ELT(x_sxp, i)); | ||
| SET_STRING_ELT(out, i,Xml2String(xmlBuildURI(uri, base_uri)).asRString()); | ||
| const xmlChar* uri = (xmlChar*)Rf_translateCharUTF8(x_sxp[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Probably we can somehow leave away theRf_translateCharUTF8() due to using cpp11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Hmm, I don'tthink cpp11 attempts to convert to UTF8 in this case
- When
x_sxpis created ascpp11::strings, it just wraps the character vector SEXP with no translation on the elements - When
x_sxp[i]runs, it extracts the CHARSXP and turns it into ar_string, but that just calls this very simple constructorhttps://github.com/r-lib/cpp11/blob/500f642b4ea132ec8c168fc70a28e81e9510ece3/inst/include/cpp11/r_string.hpp#L17C10-L17C10 - On the way into
Rf_translateCharUTF8()ther_stringis automatically changed back to a SEXP by this operator, which also doesn't translatehttps://github.com/r-lib/cpp11/blob/500f642b4ea132ec8c168fc70a28e81e9510ece3/inst/include/cpp11/r_string.hpp#L22
It looks like if we went through an intermediatestd::string it would translate, but what you currently have seems ok
https://github.com/r-lib/cpp11/blob/500f642b4ea132ec8c168fc70a28e81e9510ece3/inst/include/cpp11/r_string.hpp#L29
src/xml2_url.cpp Outdated
| if (Rf_xlength(base_sxp) >1) { | ||
| Rf_error("Base URL must be length 1"); | ||
| const xmlChar*to_xml_chr(cpp11::strings x,constchar* arg) { | ||
| if (x.size() >1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Might make more sense to check this in R.
src/connection.h Outdated
| SEXPread_bin(SEXPcon,size_tbytes=64*1024); | ||
| SEXPwrite_bin(SEXPdata,SEXPcon); | ||
| inlineSEXPR_GetConnection(SEXPcon) {returncon; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I removedR_GetConnection() as it seemed unnecessary.
src/connection.h Outdated
| inlineSEXPR_GetConnection(SEXPcon) {returncon; } | ||
| inlinesize_tR_ReadConnection(SEXPcon,void*buf,size_tn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
R_ReadConnection() wasn't used anywhere.
src/connection.h Outdated
| } | ||
| cpp11::sexpwrite_bin(cpp11::sexpdata,cpp11::sexpcon); | ||
| inlinesize_tR_WriteConnection(SEXPcon,void*buf,size_tn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This usesmemcpy() and I wasn't sure how to do this properly with cpp11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I don't think there is an alternative tomemcpy(), but you could allocate a cpp11raws and then dopayload.sexp() to get access to the SEXP you can callRAW() on. I don't think that is too awful, and at least lets cpp11 manage the memory
src/connection.h Outdated
| } | ||
| cpp11::sexpwrite_bin(cpp11::sexpdata,cpp11::sexpcon); | ||
| inlinesize_tR_WriteConnection(SEXPcon,void*buf,size_tn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I don't think there is an alternative tomemcpy(), but you could allocate a cpp11raws and then dopayload.sexp() to get access to the SEXP you can callRAW() on. I don't think that is too awful, and at least lets cpp11 manage the memory
src/xml2_namespace.cpp Outdated
| extern"C" SEXPunique_ns(SEXP ns) { | ||
| [[cpp11::register]] | ||
| cpp11::sexpunique_ns(SEXP ns) { | ||
| BEGIN_CPP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
And in the other places below. Do we need this macro at all anymore? I assume if you go through cpp11 everywhere it will wrap it in try/catch for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@DavisVaughan If you could merge#400 then I could also finish xml2_node.cpp and I think then it should be safe to remove the macros.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
| for (int i =0; i < n; ++i) { | ||
| const xmlChar* uri = (xmlChar*)Rf_translateCharUTF8(STRING_ELT(x_sxp, i)); | ||
| SET_STRING_ELT(out, i,Xml2String(xmlBuildURI(uri, base_uri)).asRString()); | ||
| const xmlChar* uri = (xmlChar*)Rf_translateCharUTF8(x_sxp[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Hmm, I don'tthink cpp11 attempts to convert to UTF8 in this case
- When
x_sxpis created ascpp11::strings, it just wraps the character vector SEXP with no translation on the elements - When
x_sxp[i]runs, it extracts the CHARSXP and turns it into ar_string, but that just calls this very simple constructorhttps://github.com/r-lib/cpp11/blob/500f642b4ea132ec8c168fc70a28e81e9510ece3/inst/include/cpp11/r_string.hpp#L17C10-L17C10 - On the way into
Rf_translateCharUTF8()ther_stringis automatically changed back to a SEXP by this operator, which also doesn't translatehttps://github.com/r-lib/cpp11/blob/500f642b4ea132ec8c168fc70a28e81e9510ece3/inst/include/cpp11/r_string.hpp#L22
It looks like if we went through an intermediatestd::string it would translate, but what you currently have seems ok
https://github.com/r-lib/cpp11/blob/500f642b4ea132ec8c168fc70a28e81e9510ece3/inst/include/cpp11/r_string.hpp#L29
| const xmlChar* uri = (xmlChar*)Rf_translateCharUTF8(STRING_ELT(x_sxp, i)); | ||
| SET_STRING_ELT(out, i,Xml2String(xmlBuildURI(uri, base_uri)).asRString()); | ||
| const xmlChar* uri = (xmlChar*)Rf_translateCharUTF8(x_sxp[i]); | ||
| out[i] =Xml2String(xmlBuildURI(uri, base_uri)).asRString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yea if it isn't critical then I'd probably leave as is
Uh oh!
There was an error while loading.Please reload this page.
src/xml2_url.cpp Outdated
| SET_STRING_ELT(scheme, i,Rf_mkChar(uri->scheme ==NULL ?"" : uri->scheme)); | ||
| SET_STRING_ELT(server, i,Rf_mkChar(uri->server ==NULL ?"" : uri->server)); | ||
| INTEGER(port)[i] = uri->port ==0 ? NA_INTEGER : uri->port; | ||
| SET_STRING_ELT(user, i,Rf_mkChar(uri->user ==NULL ?"" : uri->user)); | ||
| SET_STRING_ELT(path, i,Rf_mkChar(uri->path ==NULL ?"" : uri->path)); | ||
| SET_STRING_ELT(fragment, i,Rf_mkChar(uri->fragment ==NULL ?"" : uri->fragment)); | ||
| scheme[i] =uri->scheme ==NULL ?"" : uri->scheme; | ||
| server[i] =uri->server ==NULL ?"" : uri->server; | ||
| port[i] = uri->port ==0 ? NA_INTEGER : uri->port; | ||
| user[i] =uri->user ==NULL ?"" : uri->user; | ||
| path[i] =uri->path ==NULL ?"" : uri->path; | ||
| fragment[i] =uri->fragment ==NULL ?"" : uri->fragment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This one might get significantly slower, but again it doesn'tseem like it is used all that often? I couldn't really say
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I also think it shouldn't be used that often.
#Conflicts:#R/xml2-package.R#src/init.c
mgirlich commentedNov 3, 2023
@DavisVaughan I now also migrated |
DavisVaughan commentedNov 3, 2023
Is it one or two functions in particular? |
mgirlich commentedNov 3, 2023
I haven't looked into this in more detail but only checked |
8f62602 to9c3fc65Compare463c7e9 toece90bbCompare88024a3 tof9c5fe3Compare
Uh oh!
There was an error while loading.Please reload this page.
memcpy()?xml2_node.cppcan be tackled afterReplace S3 dispatch by C implementation #400 is merged.