{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corert/pulls/comments/109806387","pull_request_review_id":30930995,"id":109806387,"diff_hunk":"@@ -1327,40 +1326,93 @@ protected override void AllocAndTransformNativeToManaged(ILCodeStream codeStream\n \n     class UnicodeStringMarshaller : Marshaller\n     {\n+        private bool ShouldBePinned\n+        {\n+            get\n+            {\n+                return MarshallerType != MarshallerType.Field\n+                    && !IsManagedByRef;\n+            }\n+        }\n+\n+        internal override bool CleanupRequired\n+        {\n+            get\n+            {\n+                return true;\n+            }\n+        }\n+\n+        internal override void EmitElementCleanup(ILCodeStream codeStream, ILEmitter emitter)\n+        {\n+            codeStream.Emit(ILOpcode.call, emitter.NewToken(\n+                                Context.GetHelperEntryPoint(\"InteropHelpers\", \"CoTaskMemFree\")));\n+        }\n+\n         protected override void AllocAndTransformManagedToNative(ILCodeStream codeStream)\n         {\n             ILEmitter emitter = _ilCodeStreams.Emitter;\n \n-            //\n-            // Unicode marshalling. Pin the string and push a pointer to the first character on the stack.\n-            //\n-            TypeDesc stringType = Context.GetWellKnownType(WellKnownType.String);\n+            if (ShouldBePinned)\n+            {\n+                //\n+                // Pin the string and push a pointer to the first character on the stack.\n+                //\n+                TypeDesc stringType = Context.GetWellKnownType(WellKnownType.String);\n \n-            ILLocalVariable vPinnedString = emitter.NewLocal(stringType, true);\n-            ILCodeLabel lNullString = emitter.NewCodeLabel();\n+                ILLocalVariable vPinnedString = emitter.NewLocal(stringType, true);\n+                ILCodeLabel lNullString = emitter.NewCodeLabel();\n \n-            LoadManagedValue(codeStream);\n-            codeStream.EmitStLoc(vPinnedString);\n-            codeStream.EmitLdLoc(vPinnedString);\n+                LoadManagedValue(codeStream);\n+                codeStream.EmitStLoc(vPinnedString);\n+                codeStream.EmitLdLoc(vPinnedString);\n \n-            codeStream.Emit(ILOpcode.conv_i);\n-            codeStream.Emit(ILOpcode.dup);\n+                codeStream.Emit(ILOpcode.conv_i);\n+                codeStream.Emit(ILOpcode.dup);\n \n-            // Marshalling a null string?\n-            codeStream.Emit(ILOpcode.brfalse, lNullString);\n+                // Marshalling a null string?\n+                codeStream.Emit(ILOpcode.brfalse, lNullString);\n \n-            codeStream.Emit(ILOpcode.call, emitter.NewToken(\n-                Context.SystemModule.\n-                    GetKnownType(\"System.Runtime.CompilerServices\", \"RuntimeHelpers\").\n-                        GetKnownMethod(\"get_OffsetToStringData\", null)));\n+                codeStream.Emit(ILOpcode.call, emitter.NewToken(\n+                    Context.SystemModule.\n+                        GetKnownType(\"System.Runtime.CompilerServices\", \"RuntimeHelpers\").\n+                            GetKnownMethod(\"get_OffsetToStringData\", null)));\n \n-            codeStream.Emit(ILOpcode.add);\n+                codeStream.Emit(ILOpcode.add);\n \n-            codeStream.EmitLabel(lNullString);\n-            StoreNativeValue(codeStream);\n+                codeStream.EmitLabel(lNullString);\n+                StoreNativeValue(codeStream);\n+            }\n+            else\n+            {\n+                var helper = Context.GetHelperEntryPoint(\"InteropHelpers\", \"StringToUnicodeBuffer\");\n+                LoadManagedValue(codeStream);\n+\n+                codeStream.Emit(ILOpcode.call, emitter.NewToken(helper));\n+\n+                StoreNativeValue(codeStream);\n+            }\n         }\n-    }\n \n+        protected override void TransformNativeToManaged(ILCodeStream codeStream)\n+        {\n+            ILEmitter emitter = _ilCodeStreams.Emitter;\n+            var helper = Context.GetHelperEntryPoint(\"InteropHelpers\", \"UnicodeBufferToString\");\n+            LoadNativeValue(codeStream);\n+            codeStream.Emit(ILOpcode.call, emitter.NewToken(helper));\n+            StoreManagedValue(codeStream);\n+        }\n+\n+        protected override void EmitCleanupManagedToNative(ILCodeStream codeStream)\n+        {\n+            if (!ShouldBePinned)","path":"src/Common/src/TypeSystem/Interop/IL/Marshaller.cs","position":112,"original_position":112,"commit_id":"63ebe43045e201e28ed02262e26f1cb97ab8dd31","original_commit_id":"63ebe43045e201e28ed02262e26f1cb97ab8dd31","user":{"login":"yizhang82","id":6903744,"avatar_url":"https://avatars2.githubusercontent.com/u/6903744?v=3","gravatar_id":"","url":"https://api.github.com/users/yizhang82","html_url":"https://github.com/yizhang82","followers_url":"https://api.github.com/users/yizhang82/followers","following_url":"https://api.github.com/users/yizhang82/following{/other_user}","gists_url":"https://api.github.com/users/yizhang82/gists{/gist_id}","starred_url":"https://api.github.com/users/yizhang82/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yizhang82/subscriptions","organizations_url":"https://api.github.com/users/yizhang82/orgs","repos_url":"https://api.github.com/users/yizhang82/repos","events_url":"https://api.github.com/users/yizhang82/events{/privacy}","received_events_url":"https://api.github.com/users/yizhang82/received_events","type":"User","site_admin":false},"body":"You should make sure ShouldCleanup returns the right value - and you wouldn't have to special case here","created_at":"2017-04-05T00:03:27Z","updated_at":"2017-04-05T00:23:34Z","html_url":"https://github.com/dotnet/corert/pull/3208#discussion_r109806387","pull_request_url":"https://api.github.com/repos/dotnet/corert/pulls/3208","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corert/pulls/comments/109806387"},"html":{"href":"https://github.com/dotnet/corert/pull/3208#discussion_r109806387"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corert/pulls/3208"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corert/pulls/3208","id":114262624,"html_url":"https://github.com/dotnet/corert/pull/3208","diff_url":"https://github.com/dotnet/corert/pull/3208.diff","patch_url":"https://github.com/dotnet/corert/pull/3208.patch","issue_url":"https://api.github.com/repos/dotnet/corert/issues/3208","number":3208,"state":"open","locked":false,"title":"Add Out and Ref support for AnsiString and UnicodeString","user":{"login":"shrah","id":15021838,"avatar_url":"https://avatars2.githubusercontent.com/u/15021838?v=3","gravatar_id":"","url":"https://api.github.com/users/shrah","html_url":"https://github.com/shrah","followers_url":"https://api.github.com/users/shrah/followers","following_url":"https://api.github.com/users/shrah/following{/other_user}","gists_url":"https://api.github.com/users/shrah/gists{/gist_id}","starred_url":"https://api.github.com/users/shrah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shrah/subscriptions","organizations_url":"https://api.github.com/users/shrah/orgs","repos_url":"https://api.github.com/users/shrah/repos","events_url":"https://api.github.com/users/shrah/events{/privacy}","received_events_url":"https://api.github.com/users/shrah/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-04-04T23:03:19Z","updated_at":"2017-04-05T00:23:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9f82d8a9d6c4e26ab2dd9f4285b11d91af7eab59","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corert/pulls/3208/commits","review_comments_url":"https://api.github.com/repos/dotnet/corert/pulls/3208/comments","review_comment_url":"https://api.github.com/repos/dotnet/corert/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corert/issues/3208/comments","statuses_url":"https://api.github.com/repos/dotnet/corert/statuses/63ebe43045e201e28ed02262e26f1cb97ab8dd31","head":{"label":"shrah:master","ref":"master","sha":"63ebe43045e201e28ed02262e26f1cb97ab8dd31","user":{"login":"shrah","id":15021838,"avatar_url":"https://avatars2.githubusercontent.com/u/15021838?v=3","gravatar_id":"","url":"https://api.github.com/users/shrah","html_url":"https://github.com/shrah","followers_url":"https://api.github.com/users/shrah/followers","following_url":"https://api.github.com/users/shrah/following{/other_user}","gists_url":"https://api.github.com/users/shrah/gists{/gist_id}","starred_url":"https://api.github.com/users/shrah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shrah/subscriptions","organizations_url":"https://api.github.com/users/shrah/orgs","repos_url":"https://api.github.com/users/shrah/repos","events_url":"https://api.github.com/users/shrah/events{/privacy}","received_events_url":"https://api.github.com/users/shrah/received_events","type":"User","site_admin":false},"repo":{"id":56826127,"name":"corert","full_name":"shrah/corert","owner":{"login":"shrah","id":15021838,"avatar_url":"https://avatars2.githubusercontent.com/u/15021838?v=3","gravatar_id":"","url":"https://api.github.com/users/shrah","html_url":"https://github.com/shrah","followers_url":"https://api.github.com/users/shrah/followers","following_url":"https://api.github.com/users/shrah/following{/other_user}","gists_url":"https://api.github.com/users/shrah/gists{/gist_id}","starred_url":"https://api.github.com/users/shrah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shrah/subscriptions","organizations_url":"https://api.github.com/users/shrah/orgs","repos_url":"https://api.github.com/users/shrah/repos","events_url":"https://api.github.com/users/shrah/events{/privacy}","received_events_url":"https://api.github.com/users/shrah/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shrah/corert","description":"This repo contains CoreRT, a .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying .NET Native compiler toolchain.","fork":true,"url":"https://api.github.com/repos/shrah/corert","forks_url":"https://api.github.com/repos/shrah/corert/forks","keys_url":"https://api.github.com/repos/shrah/corert/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shrah/corert/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shrah/corert/teams","hooks_url":"https://api.github.com/repos/shrah/corert/hooks","issue_events_url":"https://api.github.com/repos/shrah/corert/issues/events{/number}","events_url":"https://api.github.com/repos/shrah/corert/events","assignees_url":"https://api.github.com/repos/shrah/corert/assignees{/user}","branches_url":"https://api.github.com/repos/shrah/corert/branches{/branch}","tags_url":"https://api.github.com/repos/shrah/corert/tags","blobs_url":"https://api.github.com/repos/shrah/corert/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shrah/corert/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shrah/corert/git/refs{/sha}","trees_url":"https://api.github.com/repos/shrah/corert/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shrah/corert/statuses/{sha}","languages_url":"https://api.github.com/repos/shrah/corert/languages","stargazers_url":"https://api.github.com/repos/shrah/corert/stargazers","contributors_url":"https://api.github.com/repos/shrah/corert/contributors","subscribers_url":"https://api.github.com/repos/shrah/corert/subscribers","subscription_url":"https://api.github.com/repos/shrah/corert/subscription","commits_url":"https://api.github.com/repos/shrah/corert/commits{/sha}","git_commits_url":"https://api.github.com/repos/shrah/corert/git/commits{/sha}","comments_url":"https://api.github.com/repos/shrah/corert/comments{/number}","issue_comment_url":"https://api.github.com/repos/shrah/corert/issues/comments{/number}","contents_url":"https://api.github.com/repos/shrah/corert/contents/{+path}","compare_url":"https://api.github.com/repos/shrah/corert/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shrah/corert/merges","archive_url":"https://api.github.com/repos/shrah/corert/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shrah/corert/downloads","issues_url":"https://api.github.com/repos/shrah/corert/issues{/number}","pulls_url":"https://api.github.com/repos/shrah/corert/pulls{/number}","milestones_url":"https://api.github.com/repos/shrah/corert/milestones{/number}","notifications_url":"https://api.github.com/repos/shrah/corert/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shrah/corert/labels{/name}","releases_url":"https://api.github.com/repos/shrah/corert/releases{/id}","deployments_url":"https://api.github.com/repos/shrah/corert/deployments","created_at":"2016-04-22T04:26:41Z","updated_at":"2016-04-22T04:26:47Z","pushed_at":"2017-04-04T23:19:09Z","git_url":"git://github.com/shrah/corert.git","ssh_url":"git@github.com:shrah/corert.git","clone_url":"https://github.com/shrah/corert.git","svn_url":"https://github.com/shrah/corert","homepage":"http://dotnet.github.io/","size":16428,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"60318c37c1bbf31bd30b9fe317fda4a01523356d","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars3.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":42552143,"name":"corert","full_name":"dotnet/corert","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars3.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/corert","description":"This repo contains CoreRT, a .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying .NET Native compiler toolchain.","fork":false,"url":"https://api.github.com/repos/dotnet/corert","forks_url":"https://api.github.com/repos/dotnet/corert/forks","keys_url":"https://api.github.com/repos/dotnet/corert/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/corert/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/corert/teams","hooks_url":"https://api.github.com/repos/dotnet/corert/hooks","issue_events_url":"https://api.github.com/repos/dotnet/corert/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/corert/events","assignees_url":"https://api.github.com/repos/dotnet/corert/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/corert/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/corert/tags","blobs_url":"https://api.github.com/repos/dotnet/corert/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/corert/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/corert/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/corert/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/corert/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/corert/languages","stargazers_url":"https://api.github.com/repos/dotnet/corert/stargazers","contributors_url":"https://api.github.com/repos/dotnet/corert/contributors","subscribers_url":"https://api.github.com/repos/dotnet/corert/subscribers","subscription_url":"https://api.github.com/repos/dotnet/corert/subscription","commits_url":"https://api.github.com/repos/dotnet/corert/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/corert/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/corert/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/corert/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/corert/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/corert/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/corert/merges","archive_url":"https://api.github.com/repos/dotnet/corert/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/corert/downloads","issues_url":"https://api.github.com/repos/dotnet/corert/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/corert/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/corert/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/corert/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/corert/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/corert/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/corert/deployments","created_at":"2015-09-15T23:10:53Z","updated_at":"2017-04-03T23:36:53Z","pushed_at":"2017-04-04T23:25:50Z","git_url":"git://github.com/dotnet/corert.git","ssh_url":"git@github.com:dotnet/corert.git","clone_url":"https://github.com/dotnet/corert.git","svn_url":"https://github.com/dotnet/corert","homepage":"http://dot.net","size":16427,"stargazers_count":575,"watchers_count":575,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":192,"mirror_url":null,"open_issues_count":192,"forks":192,"open_issues":192,"watchers":575,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corert/pulls/3208"},"html":{"href":"https://github.com/dotnet/corert/pull/3208"},"issue":{"href":"https://api.github.com/repos/dotnet/corert/issues/3208"},"comments":{"href":"https://api.github.com/repos/dotnet/corert/issues/3208/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corert/pulls/3208/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corert/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corert/pulls/3208/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corert/statuses/63ebe43045e201e28ed02262e26f1cb97ab8dd31"}}}}
{"actor":{"display_login":"yizhang82"}}