Skip to content

Conversation

@jpobst
Copy link
Contributor

@jpobst jpobst commented Oct 18, 2019

If a method parameter contains a dollar sign, we sometimes escape it properly and sometimes we do not:

public unsafe global::Okio.ByteString Of (byte[] _this_toByteString_, int offset, int byteCount)
{
  ...
    if ($this$toByteString != null) {
        JNIEnv.CopyArray (native__this_toByteString_, $this$toByteString);
        JNIEnv.DeleteLocalRef (native__this_toByteString_);
}

That contains both _this_toByteString_ and $this$toByteString.

This PR ensures all instances use the same opt.GetSafeIdentifier (string) escaping method.

string[] result = new string [4];
result [0] = String.Format ("if ({0} != null) {{", var_name);
result [1] = String.Format ("\tJNIEnv.CopyArray ({0}, {1});", native_name, var_name);
result [0] = String.Format ("if ({0} != null) {{", opt.GetSafeIdentifier (var_name));
Copy link
Contributor

Choose a reason for hiding this comment

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

Presumably the caller of PostCall() is also using opt.GetSafeIdentifier() -- something somewhere else must be, because this code is just the error checking code! -- so would it instead be better if we called opt.GetSafeIdentifier() once and passed that value around to all the methods that needed it, instead of duplicating opt.GetSafeIdentifier() invocations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that is a much trickier and dangerous change to get correct. For example the previous line is:

string native_name = opt.GetSafeIdentifier (TypeNameUtilities.GetNativeName (var_name));

If we're passing in a var_name that has already been mangled then getting the native name from it will probably need to be reworked, etc.

@jpobst jpobst modified the milestone: d16-5 Oct 31, 2019
@jonpryor jonpryor merged commit f5d29c3 into master Oct 31, 2019
@jonpryor jonpryor deleted the escape-parameter-names branch October 31, 2019 20:06
jonpryor pushed a commit that referenced this pull request Nov 8, 2019
…506)

If a method parameter contains a dollar sign, `generator` sometimes
escapes it properly and sometimes it does not:

	public unsafe global::Okio.ByteString Of (byte[] _this_toByteString_, int offset, int byteCount)
	{
	    // ...
	    if ($this$toByteString != null) {
	        JNIEnv.CopyArray (native__this_toByteString_, $this$toByteString);
	        JNIEnv.DeleteLocalRef (native__this_toByteString_);
	}

That contains both `_this_toByteString_` and `$this$toByteString`.

Ensures all instances use the same `opt.GetSafeIdentifier(string)`
escaping method so that `$` doesn't remain within generated sources.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants