{"action":"created","comment":{"url":"https://api.github.com/repos/pythonnet/pythonnet/pulls/comments/340458192","pull_request_review_id":308997375,"id":340458192,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDM0MDQ1ODE5Mg==","diff_hunk":"@@ -0,0 +1,228 @@\n+using System;\n+using System.Collections.Generic;\n+using System.Linq;\n+using System.Runtime.InteropServices;\n+using System.Text;\n+\n+namespace Python.Runtime\n+{\n+    public class PyBuffer : IDisposable\n+    {\n+        private PyObject _exporter;\n+        private IntPtr _handle;\n+        private Runtime.Py_buffer _view;\n+        private GCHandle _gchandle;\n+\n+        internal PyBuffer(PyObject exporter, int flags)\n+        {\n+            int size = Marshal.SizeOf(typeof(Runtime.Py_buffer));\n+            byte[] rawData = new byte[size];\n+            _gchandle = GCHandle.Alloc(rawData, GCHandleType.Pinned);\n+            _handle = _gchandle.AddrOfPinnedObject();\n+\n+            if (Runtime.PyObject_GetBuffer(exporter.Handle, _handle, flags) < 0)\n+            {\n+                _gchandle.Free();\n+                throw new PythonException();\n+            }\n+\n+            _exporter = exporter;\n+            _view = (Runtime.Py_buffer)Marshal.PtrToStructure(_handle, typeof(Runtime.Py_buffer));\n+\n+            if (_view.shape != IntPtr.Zero)\n+            {\n+                Shape = new long[_view.ndim];\n+                Marshal.Copy(_view.shape, Shape, 0, (int)_view.len * sizeof(long));","path":"src/runtime/pybuffer.cs","position":35,"original_position":35,"commit_id":"26c8da244b275bf34b0e122c6633eb121d16d26c","original_commit_id":"26c8da244b275bf34b0e122c6633eb121d16d26c","user":{"login":"filmor","id":30848,"node_id":"MDQ6VXNlcjMwODQ4","avatar_url":"https://avatars3.githubusercontent.com/u/30848?v=4","gravatar_id":"","url":"https://api.github.com/users/filmor","html_url":"https://github.com/filmor","followers_url":"https://api.github.com/users/filmor/followers","following_url":"https://api.github.com/users/filmor/following{/other_user}","gists_url":"https://api.github.com/users/filmor/gists{/gist_id}","starred_url":"https://api.github.com/users/filmor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/filmor/subscriptions","organizations_url":"https://api.github.com/users/filmor/orgs","repos_url":"https://api.github.com/users/filmor/repos","events_url":"https://api.github.com/users/filmor/events{/privacy}","received_events_url":"https://api.github.com/users/filmor/received_events","type":"User","site_admin":false},"body":"This is the same issue as noted below, on 32bit Windows (and actually also on 32bit Linux) this will fail, it might actually segfault.","created_at":"2019-10-30T07:18:50Z","updated_at":"2019-10-30T07:21:50Z","html_url":"https://github.com/pythonnet/pythonnet/pull/980#discussion_r340458192","pull_request_url":"https://api.github.com/repos/pythonnet/pythonnet/pulls/980","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/pythonnet/pythonnet/pulls/comments/340458192"},"html":{"href":"https://github.com/pythonnet/pythonnet/pull/980#discussion_r340458192"},"pull_request":{"href":"https://api.github.com/repos/pythonnet/pythonnet/pulls/980"}}},"pull_request":{"url":"https://api.github.com/repos/pythonnet/pythonnet/pulls/980","id":332887226,"node_id":"MDExOlB1bGxSZXF1ZXN0MzMyODg3MjI2","html_url":"https://github.com/pythonnet/pythonnet/pull/980","diff_url":"https://github.com/pythonnet/pythonnet/pull/980.diff","patch_url":"https://github.com/pythonnet/pythonnet/pull/980.patch","issue_url":"https://api.github.com/repos/pythonnet/pythonnet/issues/980","number":980,"state":"open","locked":false,"title":"Add python buffer api support","user":{"login":"SnGmng","id":38666407,"node_id":"MDQ6VXNlcjM4NjY2NDA3","avatar_url":"https://avatars0.githubusercontent.com/u/38666407?v=4","gravatar_id":"","url":"https://api.github.com/users/SnGmng","html_url":"https://github.com/SnGmng","followers_url":"https://api.github.com/users/SnGmng/followers","following_url":"https://api.github.com/users/SnGmng/following{/other_user}","gists_url":"https://api.github.com/users/SnGmng/gists{/gist_id}","starred_url":"https://api.github.com/users/SnGmng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SnGmng/subscriptions","organizations_url":"https://api.github.com/users/SnGmng/orgs","repos_url":"https://api.github.com/users/SnGmng/repos","events_url":"https://api.github.com/users/SnGmng/events{/privacy}","received_events_url":"https://api.github.com/users/SnGmng/received_events","type":"User","site_admin":false},"body":"### What does this implement/fix? Explain your changes.\r\n\r\nPassing data like images from managed to python will be easyer than ever!\r\nI implemented the python buffer api which makes copying big chunks of data directly into the python object buffer possible!\r\n\r\nYou can copy strings to python object:\r\n\r\n    PyObject array = scope.Eval(\"bytearray(3)\");\r\n    byte[] managedArr = new UTF8Encoding().GetBytes(new char[] { 'a', 'b', 'c' });\r\n\r\n    PyBuffer buf = array.GetBuffer(out bool success, 0);\r\n    if (success)\r\n    {\r\n        buf.WriteToBuffer(managedArr, 0, managedArr.Length);\r\n        buf.Release();\r\n    }\r\n\r\nOr copy images to python byte arrays:\r\n\r\n    byte[] imageArr = LoadImage();\r\n    PyObject array = scope.Eval(\"bytearray(\" + managedArr.Length + \")\");\r\n\r\n    PyBuffer buf = array.GetBuffer(out bool success, 0);\r\n    if (success)\r\n    {\r\n        buf.WriteToBuffer(managedArr, 0, managedArr.Length);\r\n        buf.Release();\r\n    }\r\n\r\n### Does this close any currently open issues?\r\n\r\nNo\r\n\r\n### Any other comments?\r\n\r\n...\r\n\r\n### Checklist\r\n\r\nCheck all those that are applicable and complete.\r\n\r\n-   [ ] Make sure to include one or more tests for your change\r\n-   [x] If an enhancement PR, please create docs and at best an example\r\n-   [x] Add yourself to [`AUTHORS`](../blob/master/AUTHORS.md)\r\n-   [ ] Updated the [`CHANGELOG`](../blob/master/CHANGELOG.md)\r\n","created_at":"2019-10-27T19:50:45Z","updated_at":"2019-10-30T07:21:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e570086bb88a10b7a015acfcce70d68818acaa79","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/pythonnet/pythonnet/pulls/980/commits","review_comments_url":"https://api.github.com/repos/pythonnet/pythonnet/pulls/980/comments","review_comment_url":"https://api.github.com/repos/pythonnet/pythonnet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pythonnet/pythonnet/issues/980/comments","statuses_url":"https://api.github.com/repos/pythonnet/pythonnet/statuses/26c8da244b275bf34b0e122c6633eb121d16d26c","head":{"label":"SnGmng:pybuffer2","ref":"pybuffer2","sha":"26c8da244b275bf34b0e122c6633eb121d16d26c","user":{"login":"SnGmng","id":38666407,"node_id":"MDQ6VXNlcjM4NjY2NDA3","avatar_url":"https://avatars0.githubusercontent.com/u/38666407?v=4","gravatar_id":"","url":"https://api.github.com/users/SnGmng","html_url":"https://github.com/SnGmng","followers_url":"https://api.github.com/users/SnGmng/followers","following_url":"https://api.github.com/users/SnGmng/following{/other_user}","gists_url":"https://api.github.com/users/SnGmng/gists{/gist_id}","starred_url":"https://api.github.com/users/SnGmng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SnGmng/subscriptions","organizations_url":"https://api.github.com/users/SnGmng/orgs","repos_url":"https://api.github.com/users/SnGmng/repos","events_url":"https://api.github.com/users/SnGmng/events{/privacy}","received_events_url":"https://api.github.com/users/SnGmng/received_events","type":"User","site_admin":false},"repo":{"id":216073250,"node_id":"MDEwOlJlcG9zaXRvcnkyMTYwNzMyNTA=","name":"pythonnet","full_name":"SnGmng/pythonnet","private":false,"owner":{"login":"SnGmng","id":38666407,"node_id":"MDQ6VXNlcjM4NjY2NDA3","avatar_url":"https://avatars0.githubusercontent.com/u/38666407?v=4","gravatar_id":"","url":"https://api.github.com/users/SnGmng","html_url":"https://github.com/SnGmng","followers_url":"https://api.github.com/users/SnGmng/followers","following_url":"https://api.github.com/users/SnGmng/following{/other_user}","gists_url":"https://api.github.com/users/SnGmng/gists{/gist_id}","starred_url":"https://api.github.com/users/SnGmng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SnGmng/subscriptions","organizations_url":"https://api.github.com/users/SnGmng/orgs","repos_url":"https://api.github.com/users/SnGmng/repos","events_url":"https://api.github.com/users/SnGmng/events{/privacy}","received_events_url":"https://api.github.com/users/SnGmng/received_events","type":"User","site_admin":false},"html_url":"https://github.com/SnGmng/pythonnet","description":"Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers.","fork":true,"url":"https://api.github.com/repos/SnGmng/pythonnet","forks_url":"https://api.github.com/repos/SnGmng/pythonnet/forks","keys_url":"https://api.github.com/repos/SnGmng/pythonnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SnGmng/pythonnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SnGmng/pythonnet/teams","hooks_url":"https://api.github.com/repos/SnGmng/pythonnet/hooks","issue_events_url":"https://api.github.com/repos/SnGmng/pythonnet/issues/events{/number}","events_url":"https://api.github.com/repos/SnGmng/pythonnet/events","assignees_url":"https://api.github.com/repos/SnGmng/pythonnet/assignees{/user}","branches_url":"https://api.github.com/repos/SnGmng/pythonnet/branches{/branch}","tags_url":"https://api.github.com/repos/SnGmng/pythonnet/tags","blobs_url":"https://api.github.com/repos/SnGmng/pythonnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SnGmng/pythonnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SnGmng/pythonnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/SnGmng/pythonnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SnGmng/pythonnet/statuses/{sha}","languages_url":"https://api.github.com/repos/SnGmng/pythonnet/languages","stargazers_url":"https://api.github.com/repos/SnGmng/pythonnet/stargazers","contributors_url":"https://api.github.com/repos/SnGmng/pythonnet/contributors","subscribers_url":"https://api.github.com/repos/SnGmng/pythonnet/subscribers","subscription_url":"https://api.github.com/repos/SnGmng/pythonnet/subscription","commits_url":"https://api.github.com/repos/SnGmng/pythonnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/SnGmng/pythonnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/SnGmng/pythonnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/SnGmng/pythonnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/SnGmng/pythonnet/contents/{+path}","compare_url":"https://api.github.com/repos/SnGmng/pythonnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SnGmng/pythonnet/merges","archive_url":"https://api.github.com/repos/SnGmng/pythonnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SnGmng/pythonnet/downloads","issues_url":"https://api.github.com/repos/SnGmng/pythonnet/issues{/number}","pulls_url":"https://api.github.com/repos/SnGmng/pythonnet/pulls{/number}","milestones_url":"https://api.github.com/repos/SnGmng/pythonnet/milestones{/number}","notifications_url":"https://api.github.com/repos/SnGmng/pythonnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SnGmng/pythonnet/labels{/name}","releases_url":"https://api.github.com/repos/SnGmng/pythonnet/releases{/id}","deployments_url":"https://api.github.com/repos/SnGmng/pythonnet/deployments","created_at":"2019-10-18T17:17:01Z","updated_at":"2019-10-18T17:45:46Z","pushed_at":"2019-10-29T22:21:36Z","git_url":"git://github.com/SnGmng/pythonnet.git","ssh_url":"git@github.com:SnGmng/pythonnet.git","clone_url":"https://github.com/SnGmng/pythonnet.git","svn_url":"https://github.com/SnGmng/pythonnet","homepage":"http://pythonnet.github.io","size":8102,"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,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pythonnet:master","ref":"master","sha":"146353855b6ed2414f3c5fd1b4bf231c2a985da8","user":{"login":"pythonnet","id":6050430,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwNTA0MzA=","avatar_url":"https://avatars2.githubusercontent.com/u/6050430?v=4","gravatar_id":"","url":"https://api.github.com/users/pythonnet","html_url":"https://github.com/pythonnet","followers_url":"https://api.github.com/users/pythonnet/followers","following_url":"https://api.github.com/users/pythonnet/following{/other_user}","gists_url":"https://api.github.com/users/pythonnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pythonnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pythonnet/subscriptions","organizations_url":"https://api.github.com/users/pythonnet/orgs","repos_url":"https://api.github.com/users/pythonnet/repos","events_url":"https://api.github.com/users/pythonnet/events{/privacy}","received_events_url":"https://api.github.com/users/pythonnet/received_events","type":"Organization","site_admin":false},"repo":{"id":14748123,"node_id":"MDEwOlJlcG9zaXRvcnkxNDc0ODEyMw==","name":"pythonnet","full_name":"pythonnet/pythonnet","private":false,"owner":{"login":"pythonnet","id":6050430,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwNTA0MzA=","avatar_url":"https://avatars2.githubusercontent.com/u/6050430?v=4","gravatar_id":"","url":"https://api.github.com/users/pythonnet","html_url":"https://github.com/pythonnet","followers_url":"https://api.github.com/users/pythonnet/followers","following_url":"https://api.github.com/users/pythonnet/following{/other_user}","gists_url":"https://api.github.com/users/pythonnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pythonnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pythonnet/subscriptions","organizations_url":"https://api.github.com/users/pythonnet/orgs","repos_url":"https://api.github.com/users/pythonnet/repos","events_url":"https://api.github.com/users/pythonnet/events{/privacy}","received_events_url":"https://api.github.com/users/pythonnet/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/pythonnet/pythonnet","description":"Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers.","fork":false,"url":"https://api.github.com/repos/pythonnet/pythonnet","forks_url":"https://api.github.com/repos/pythonnet/pythonnet/forks","keys_url":"https://api.github.com/repos/pythonnet/pythonnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pythonnet/pythonnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pythonnet/pythonnet/teams","hooks_url":"https://api.github.com/repos/pythonnet/pythonnet/hooks","issue_events_url":"https://api.github.com/repos/pythonnet/pythonnet/issues/events{/number}","events_url":"https://api.github.com/repos/pythonnet/pythonnet/events","assignees_url":"https://api.github.com/repos/pythonnet/pythonnet/assignees{/user}","branches_url":"https://api.github.com/repos/pythonnet/pythonnet/branches{/branch}","tags_url":"https://api.github.com/repos/pythonnet/pythonnet/tags","blobs_url":"https://api.github.com/repos/pythonnet/pythonnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pythonnet/pythonnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pythonnet/pythonnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/pythonnet/pythonnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pythonnet/pythonnet/statuses/{sha}","languages_url":"https://api.github.com/repos/pythonnet/pythonnet/languages","stargazers_url":"https://api.github.com/repos/pythonnet/pythonnet/stargazers","contributors_url":"https://api.github.com/repos/pythonnet/pythonnet/contributors","subscribers_url":"https://api.github.com/repos/pythonnet/pythonnet/subscribers","subscription_url":"https://api.github.com/repos/pythonnet/pythonnet/subscription","commits_url":"https://api.github.com/repos/pythonnet/pythonnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/pythonnet/pythonnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/pythonnet/pythonnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/pythonnet/pythonnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/pythonnet/pythonnet/contents/{+path}","compare_url":"https://api.github.com/repos/pythonnet/pythonnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pythonnet/pythonnet/merges","archive_url":"https://api.github.com/repos/pythonnet/pythonnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pythonnet/pythonnet/downloads","issues_url":"https://api.github.com/repos/pythonnet/pythonnet/issues{/number}","pulls_url":"https://api.github.com/repos/pythonnet/pythonnet/pulls{/number}","milestones_url":"https://api.github.com/repos/pythonnet/pythonnet/milestones{/number}","notifications_url":"https://api.github.com/repos/pythonnet/pythonnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pythonnet/pythonnet/labels{/name}","releases_url":"https://api.github.com/repos/pythonnet/pythonnet/releases{/id}","deployments_url":"https://api.github.com/repos/pythonnet/pythonnet/deployments","created_at":"2013-11-27T13:42:20Z","updated_at":"2019-10-25T10:47:34Z","pushed_at":"2019-10-29T22:21:38Z","git_url":"git://github.com/pythonnet/pythonnet.git","ssh_url":"git@github.com:pythonnet/pythonnet.git","clone_url":"https://github.com/pythonnet/pythonnet.git","svn_url":"https://github.com/pythonnet/pythonnet","homepage":"http://pythonnet.github.io","size":6827,"stargazers_count":1802,"watchers_count":1802,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":338,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":218,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":338,"open_issues":218,"watchers":1802,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pythonnet/pythonnet/pulls/980"},"html":{"href":"https://github.com/pythonnet/pythonnet/pull/980"},"issue":{"href":"https://api.github.com/repos/pythonnet/pythonnet/issues/980"},"comments":{"href":"https://api.github.com/repos/pythonnet/pythonnet/issues/980/comments"},"review_comments":{"href":"https://api.github.com/repos/pythonnet/pythonnet/pulls/980/comments"},"review_comment":{"href":"https://api.github.com/repos/pythonnet/pythonnet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pythonnet/pythonnet/pulls/980/commits"},"statuses":{"href":"https://api.github.com/repos/pythonnet/pythonnet/statuses/26c8da244b275bf34b0e122c6633eb121d16d26c"}},"author_association":"NONE"}}
{"actor":{"display_login":"filmor"}}