Skip to content

use ucrtbase.dll with R 4.2.0 or newer - #11207

Merged
kevinushey merged 4 commits into
mainfrom
bugfix/win32-runtime-library-ucrt
May 13, 2022
Merged

kevinushey merged 4 commits into
mainfrom
bugfix/win32-runtime-library-ucrt

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

Addresses #11206.

Approach

Newer versions of R will set errno in ucrtbase.dll, so read it from there instead of msvcrt.dll.

Automated Tests

N/A

QA Notes

Given a file with the contents:

AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH
AAAAAAAAAAHHHHHHHHHHHHHHHHHHHH

(Screaming is an important part of the test procedure)

  • Open a file test.R, and paste these contents in,
  • Try to save the file,
  • Try File -> Open with Encoding -> UTF-8, and confirm the file contents did not change,
  • Try file -> Open with Encoding -> ISO-8859-1, and confirm the file contents did not change.

Run this test with both R 4.2.0 and R 3.6.3, just to confirm we did indeed fix the issue with R 4.2.0, and didn't break anything for R 3.6.3.

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

@kevinushey
kevinushey requested a review from jgutman May 13, 2022 17:24
Comment thread src/cpp/session/SessionMain.cpp Outdated
#ifdef _WIN32
// initialize runtime library
Version rVersion(getDLLVersion());
bool isUcrt = rVersion >= Version("4.2.0");

@jgutman jgutman May 13, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will r >= 4.2 on windows always be ucrt? Aren't there some exceptions based on windows version? I recall Tomas K saying something to that effect

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so, but we should probably have a better check for this. The note at https://cran.r-project.org/bin/windows/base/ says:

This build requires UCRT, which is part of Windows since Windows 10 and Windows Server 2016. On older systems, UCRT has to be installed manually from here.

Let me see if there's a better place for me to figure this out.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to clarify that to use
UTF-8 as the native encoding in R 4.2, if you are using long-term
support Windows servers, you need Windows Server 2022 (Windows Server
2016 is not enough). If you run R 4.2 on Windows Server 2016, it will
still use the Windows default encoding (as R 4.1 and older).

More precisely, as "R for Windows FAQ" says,

For UTF-8 to be the native encoding, you need R at least 4.2 and at least
Windows 10 (version 1903) on desktop systems, Windows Server 2022 on
long-term support server systems or Windows Server 1903 from the semi-annual
channel.

Comment thread src/cpp/session/SessionMain.cpp Outdated
{
// on Windows, check if we're using UCRT
std::string crt;
Error error = rstudio::r::exec::evaluateString("R.version$crt", &crt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this seems less error prone than just checking the R version

@kevinushey
kevinushey merged commit 7720859 into main May 13, 2022
@kevinushey
kevinushey deleted the bugfix/win32-runtime-library-ucrt branch May 13, 2022 18:09
kevinushey added a commit that referenced this pull request May 13, 2022
* use ucrtbase.dll with R 4.2.0 or newer

* ask R whether UCRT is being used

* log errors

* ignore errors when reading R.version
kevinushey added a commit that referenced this pull request May 16, 2022
* use ucrtbase.dll with R 4.2.0 or newer (#11207)

* use ucrtbase.dll with R 4.2.0 or newer

* ask R whether UCRT is being used

* log errors

* ignore errors when reading R.version

* update NEWS

* bring back accidentally deleted title
matheustavaresdev added a commit that referenced this pull request May 17, 2022
…on-auto-select

* 'main' of github.com:rstudio/rstudio: (40 commits)
  update to Electron 18.2.3
  ensure new instance is created when opening remote session file
  Update NEWS.md
  Fix flags not being passed through constructor in R version selectors
  remove unnecessary package
  install gpg1 for signing
  skip adding compiler definitions
  find jdk on my Intel Mac
  produce builds for fedora36
  use ucrtbase.dll with R 4.2.0 or newer (#11207)
  Outline uses quarto style labels, `#| label: <name>` (#11192)
  Allow fallback unknown text file types to open in Desktop same as in server
  update embedded libclang to 13.0.1 (#11186)
  Addresses handling of native pipe args with no placeholder (#11194)
  New project fails earlier when directory already exist (#11191)
  remove unused gwt class replacements (#11193)
  update Electron NEWS
  make message box API aware of this option
  whitespace tweak
  naming tweaks from PR feedback
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants