Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #31 rSharp_create_domain need an argument for library location … #65

Conversation

Ian-Du
Copy link
Contributor

@Ian-Du Ian-Du commented Mar 4, 2024

Fixes #31 rSharp_create_domain need an argument for library location
Fixes #30 Statically link nethost in Windows
Update code to allow the path for the library to be passed from R to the C++ code.

@PavelBal
Copy link
Member

PavelBal commented Mar 4, 2024

What about

const string_t dotnetlib_path = STR("./ClrFacade.dll");

This path also must be constructured from the provided path.

@PavelBal PavelBal requested a review from rwmcintosh March 4, 2024 15:21
src/rSharp.cpp Outdated
delete[] wideStringPath;
}

char_t* MergeLibPath(char** libPath, char* additionalPath)
Copy link
Member

Choose a reason for hiding this comment

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

Make both arguments into wchar_t instead of char. This method will only concatenate the stuff, not widen the characters and concatenate.

src/rSharp.cpp Outdated
void rSharp_create_domain(char ** libPath)
{
char_t* wideStringPath = MergeLibPath(libPath, "/RSharp.runtimeconfig.json");
dotnetlib_path = MergeLibPath(libPath, "/ClrFacade.dll");
Copy link
Member

Choose a reason for hiding this comment

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

both constant strings on this line and the line above could be STR("the string in here") because then you don't have to allocate memory for the widening conversion. They will be compiled as wchar_t

Copy link
Member

@rwmcintosh rwmcintosh Mar 4, 2024

Choose a reason for hiding this comment

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

Also, move this below the blocking test for nullptr. We don't need to do any string concatenation if the assembly pointer is already initialized.

src/rSharp.h Outdated
@@ -144,6 +144,7 @@ extern "C" {
RSharpGenericValue ConvertToRSharpGenericValue(SEXP s);
RSharpGenericValue** sexp_to_parameters(SEXP args);
SEXP ConvertToSEXP(RSharpGenericValue& value);
char_t* MergeLibPath(char** libPath, char* additionalPath);
Copy link
Member

Choose a reason for hiding this comment

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

There is lots of cleanup required in this file. In general, we should not expose the prototypes for functions that are not 'public'.

Put this prototype in the rSharp.c file toward the top.

src/rSharp.cpp Outdated

char_t* MergeLibPath(char** libPath, char* additionalPath)
{
size_t libPathLen = strlen(*libPath);
Copy link
Member

Choose a reason for hiding this comment

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

This is another one of those situations where there's lots of cleanup to do, but let's start eliminating abbreviations from variable and function/method names.

Copy link
Member

Choose a reason for hiding this comment

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

It's much more clear for me to read libararyPathLength or library_path_length

src/rSharp.cpp Outdated
mbstowcs_s(nullptr, wideStringPath, length + 1, combinedPath, length);

delete[] combinedPath;
return wideStringPath;
Copy link
Member

Choose a reason for hiding this comment

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

That's a good name 👍

@rwmcintosh rwmcintosh merged commit 54767f4 into develop Mar 5, 2024
@PavelBal PavelBal deleted the 31-rsharp_create_domain-need-an-argument-for-library-location branch March 6, 2024 13:24
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.

rSharp_create_domain need an argument for library location Statically link nethost in Windows
3 participants