{"action":"created","comment":{"url":"https://api.github.com/repos/mono/mono/pulls/comments/48010391","id":48010391,"diff_hunk":"@@ -0,0 +1,128 @@\n+/*\n+ * handle.h: Handle to object in native code\n+ *\n+ * Authors:\n+ *  - Ludovic Henry <ludovic@xamarin.com>\n+ *\n+ * Copyright 2015 Xamarin, Inc. (www.xamarin.com)\n+ */\n+\n+#ifndef __MONO_HANDLE_H__\n+#define __MONO_HANDLE_H__\n+\n+#include <config.h>\n+#include <glib.h>\n+\n+#include \"object.h\"\n+#include \"class.h\"\n+#include \"class-internals.h\"\n+#include \"threads-types.h\"\n+\n+#include \"mono/utils/mono-threads-coop.h\"\n+\n+G_BEGIN_DECLS\n+\n+typedef struct _MonoHandleStorage MonoHandleStorage;\n+typedef MonoHandleStorage* MonoHandle;\n+\n+/*\n+ * DO NOT ACCESS DIRECTLY\n+ * USE mono_handle_obj BELOW TO ACCESS OBJ\n+ *\n+ * The field obj is not private as there is no way to do that\n+ * in C, but using a C++ template would simplify that a lot\n+ */\n+struct _MonoHandleStorage {\n+\tMonoObject *obj;\n+};\n+\n+#ifndef CHECKED_BUILD\n+\n+#define mono_handle_obj(handle) ((handle)->obj)\n+\n+#define mono_handle_assign(handle,rawptr) do { (handle)->obj = (rawptr); } while(0)\n+\n+#else\n+\n+static inline void\n+mono_handle_check_in_critical_section (const gchar* file, const gint lineno)\n+{\n+\tMonoThreadInfo *info = (MonoThreadInfo*) mono_thread_info_current_unchecked ();\n+\tif (info && !info->inside_critical_region)\n+\t\tg_error (\"Assertion at %s:%d: mono_handle_check_in_critical_section failed\", file, lineno);\n+}\n+\n+#define mono_handle_obj(handle) (mono_handle_check_in_critical_section (__FILE__, __LINE__), (handle)->obj)\n+\n+#define mono_handle_assign(handle,rawptr) do { mono_handle_check_in_critical_section (__FILE__, __LINE__); (handle)->obj = (rawptr); } while (0)\n+\n+#endif\n+\n+static inline MonoClass*\n+mono_handle_class (MonoHandle handle)\n+{\n+\treturn handle->obj->vtable->klass;\n+}\n+\n+static inline MonoDomain*\n+mono_handle_domain (MonoHandle handle)\n+{\n+\treturn handle->obj->vtable->domain;\n+}\n+\n+#define MONO_HANDLE_TYPE_DECL(type)      typedef struct { type *obj; } type ## HandleStorage ; \\\n+\ttypedef type ## HandleStorage * type ## Handle\n+#define MONO_HANDLE_TYPE(type)           type ## Handle\n+#define MONO_HANDLE_NEW(type,obj)        ((type ## Handle) mono_handle_new ((MonoObject*) (obj)))\n+#define MONO_HANDLE_ELEVATE(type,handle) ((type ## Handle) mono_handle_elevate ((MonoObject*) (handle)->obj))\n+\n+#define MONO_HANDLE_ASSIGN(handle,rawptr)\t\\\n+\tdo {\t\\\n+\t\tmono_handle_assign ((handle), (rawptr));\t\\\n+\t} while (0)\n+\n+#define MONO_HANDLE_SETREF(handle,fieldname,value)\t\\\n+\tdo {\t\\\n+\t\tgpointer __value = (value);\t\\\n+\t\tMONO_PREPARE_CRITICAL;\t\\\n+\t\tMONO_OBJECT_SETREF (mono_handle_obj ((handle)), fieldname, __value);\t\\\n+\t\tMONO_FINISH_CRITICAL;\t\\\n+\t} while (0)\n+\n+#define MONO_HANDLE_SET(handle,fieldname,value)\t\\\n+\tdo {\t\\\n+\t\tMONO_PREPARE_CRITICAL;\t\\\n+\t\tmono_handle_obj ((handle))->fieldname = (value);\t\\\n+\t\tMONO_FINISH_CRITICAL;\t\\\n+\t} while (0)\n+\n+#define MONO_HANDLE_ARRAY_SETREF(handle,index,value)\t\\\n+\tdo {\t\\\n+\t\tgpointer __value = (value);\t\\\n+\t\tMONO_PREPARE_CRITICAL;\t\\\n+\t\tmono_array_setref (mono_handle_obj ((handle)), (index), __value);\t\\\n+\t\tMONO_FINISH_CRITICAL;\t\\\n+\t} while (0)","path":"mono/metadata/handle.h","position":105,"original_position":105,"commit_id":"9d8d66f0ee9eb876e99561b09ab0591c984ce54c","original_commit_id":"9d8d66f0ee9eb876e99561b09ab0591c984ce54c","user":{"login":"ludovic-henry","id":660779,"avatar_url":"https://avatars.githubusercontent.com/u/660779?v=3","gravatar_id":"","url":"https://api.github.com/users/ludovic-henry","html_url":"https://github.com/ludovic-henry","followers_url":"https://api.github.com/users/ludovic-henry/followers","following_url":"https://api.github.com/users/ludovic-henry/following{/other_user}","gists_url":"https://api.github.com/users/ludovic-henry/gists{/gist_id}","starred_url":"https://api.github.com/users/ludovic-henry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ludovic-henry/subscriptions","organizations_url":"https://api.github.com/users/ludovic-henry/orgs","repos_url":"https://api.github.com/users/ludovic-henry/repos","events_url":"https://api.github.com/users/ludovic-henry/events{/privacy}","received_events_url":"https://api.github.com/users/ludovic-henry/received_events","type":"User","site_admin":false},"body":"We should also have:\r\n```\r\nMonoHandle __value = (MonoHandle) (value);\t\\\r\nMONO_PREPARE_CRITICAL;\t\\\r\nmono_array_setref (mono_handle_obj ((handle)), (index), mono_handle_obj (__value));\t\\\r\nMONO_FINISH_CRITICAL;\t\\\r\n```","created_at":"2015-12-18T10:00:48Z","updated_at":"2015-12-18T10:00:48Z","html_url":"https://github.com/mono/mono/pull/2314#discussion_r48010391","pull_request_url":"https://api.github.com/repos/mono/mono/pulls/2314","_links":{"self":{"href":"https://api.github.com/repos/mono/mono/pulls/comments/48010391"},"html":{"href":"https://github.com/mono/mono/pull/2314#discussion_r48010391"},"pull_request":{"href":"https://api.github.com/repos/mono/mono/pulls/2314"}}},"pull_request":{"url":"https://api.github.com/repos/mono/mono/pulls/2314","id":53192144,"html_url":"https://github.com/mono/mono/pull/2314","diff_url":"https://github.com/mono/mono/pull/2314.diff","patch_url":"https://github.com/mono/mono/pull/2314.patch","issue_url":"https://api.github.com/repos/mono/mono/issues/2314","number":2314,"state":"open","locked":false,"title":"Just the low-level bits of the handles API","user":{"login":"lambdageek","id":480437,"avatar_url":"https://avatars.githubusercontent.com/u/480437?v=3","gravatar_id":"","url":"https://api.github.com/users/lambdageek","html_url":"https://github.com/lambdageek","followers_url":"https://api.github.com/users/lambdageek/followers","following_url":"https://api.github.com/users/lambdageek/following{/other_user}","gists_url":"https://api.github.com/users/lambdageek/gists{/gist_id}","starred_url":"https://api.github.com/users/lambdageek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lambdageek/subscriptions","organizations_url":"https://api.github.com/users/lambdageek/orgs","repos_url":"https://api.github.com/users/lambdageek/repos","events_url":"https://api.github.com/users/lambdageek/events{/privacy}","received_events_url":"https://api.github.com/users/lambdageek/received_events","type":"User","site_admin":false},"body":"*Updated*: Just the lowlevel bits now:\r\n1. `MonoHandleArena` implementation, but without the `MonoInternalThread` ties.\r\n2. Changed `MonoHandle` to be an opaque typedef for `MonoHandleStorage *`, where `MonoHandleStorage` is a struct with a `MonoObject*` in it.\r\n3. Beginnings of unit test.\r\n4. No convenience APIs or example usage or anything else.\r\n\r\n*Old*:\r\nThis includes @ludovic-henry `coop-handle` branch and @kumpera `local-handles`.  Also my `MONO_ICALL_DEFINE` mega-macro.  I also fixed up the checked build asserts to give a slightly better error message (file and line number).\r\n\r\nThis compiles and passes `make -C mcs/class/corlib check` on a checked coop gc build on osx.\r\n\r\nWe should get rid of junk, put the whole thing behind some `#define` and try to use it for real.","created_at":"2015-12-09T23:04:58Z","updated_at":"2015-12-18T10:00:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a992b2e350612bc024726695e001a2157ebdb83","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mono/mono/pulls/2314/commits","review_comments_url":"https://api.github.com/repos/mono/mono/pulls/2314/comments","review_comment_url":"https://api.github.com/repos/mono/mono/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mono/mono/issues/2314/comments","statuses_url":"https://api.github.com/repos/mono/mono/statuses/9d8d66f0ee9eb876e99561b09ab0591c984ce54c","head":{"label":"lambdageek:dev/local-handles","ref":"dev/local-handles","sha":"9d8d66f0ee9eb876e99561b09ab0591c984ce54c","user":{"login":"lambdageek","id":480437,"avatar_url":"https://avatars.githubusercontent.com/u/480437?v=3","gravatar_id":"","url":"https://api.github.com/users/lambdageek","html_url":"https://github.com/lambdageek","followers_url":"https://api.github.com/users/lambdageek/followers","following_url":"https://api.github.com/users/lambdageek/following{/other_user}","gists_url":"https://api.github.com/users/lambdageek/gists{/gist_id}","starred_url":"https://api.github.com/users/lambdageek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lambdageek/subscriptions","organizations_url":"https://api.github.com/users/lambdageek/orgs","repos_url":"https://api.github.com/users/lambdageek/repos","events_url":"https://api.github.com/users/lambdageek/events{/privacy}","received_events_url":"https://api.github.com/users/lambdageek/received_events","type":"User","site_admin":false},"repo":{"id":40153659,"name":"mono","full_name":"lambdageek/mono","owner":{"login":"lambdageek","id":480437,"avatar_url":"https://avatars.githubusercontent.com/u/480437?v=3","gravatar_id":"","url":"https://api.github.com/users/lambdageek","html_url":"https://github.com/lambdageek","followers_url":"https://api.github.com/users/lambdageek/followers","following_url":"https://api.github.com/users/lambdageek/following{/other_user}","gists_url":"https://api.github.com/users/lambdageek/gists{/gist_id}","starred_url":"https://api.github.com/users/lambdageek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lambdageek/subscriptions","organizations_url":"https://api.github.com/users/lambdageek/orgs","repos_url":"https://api.github.com/users/lambdageek/repos","events_url":"https://api.github.com/users/lambdageek/events{/privacy}","received_events_url":"https://api.github.com/users/lambdageek/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lambdageek/mono","description":"Mono open source ECMA CLI, C# and .NET implementation.","fork":true,"url":"https://api.github.com/repos/lambdageek/mono","forks_url":"https://api.github.com/repos/lambdageek/mono/forks","keys_url":"https://api.github.com/repos/lambdageek/mono/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lambdageek/mono/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lambdageek/mono/teams","hooks_url":"https://api.github.com/repos/lambdageek/mono/hooks","issue_events_url":"https://api.github.com/repos/lambdageek/mono/issues/events{/number}","events_url":"https://api.github.com/repos/lambdageek/mono/events","assignees_url":"https://api.github.com/repos/lambdageek/mono/assignees{/user}","branches_url":"https://api.github.com/repos/lambdageek/mono/branches{/branch}","tags_url":"https://api.github.com/repos/lambdageek/mono/tags","blobs_url":"https://api.github.com/repos/lambdageek/mono/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lambdageek/mono/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lambdageek/mono/git/refs{/sha}","trees_url":"https://api.github.com/repos/lambdageek/mono/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lambdageek/mono/statuses/{sha}","languages_url":"https://api.github.com/repos/lambdageek/mono/languages","stargazers_url":"https://api.github.com/repos/lambdageek/mono/stargazers","contributors_url":"https://api.github.com/repos/lambdageek/mono/contributors","subscribers_url":"https://api.github.com/repos/lambdageek/mono/subscribers","subscription_url":"https://api.github.com/repos/lambdageek/mono/subscription","commits_url":"https://api.github.com/repos/lambdageek/mono/commits{/sha}","git_commits_url":"https://api.github.com/repos/lambdageek/mono/git/commits{/sha}","comments_url":"https://api.github.com/repos/lambdageek/mono/comments{/number}","issue_comment_url":"https://api.github.com/repos/lambdageek/mono/issues/comments{/number}","contents_url":"https://api.github.com/repos/lambdageek/mono/contents/{+path}","compare_url":"https://api.github.com/repos/lambdageek/mono/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lambdageek/mono/merges","archive_url":"https://api.github.com/repos/lambdageek/mono/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lambdageek/mono/downloads","issues_url":"https://api.github.com/repos/lambdageek/mono/issues{/number}","pulls_url":"https://api.github.com/repos/lambdageek/mono/pulls{/number}","milestones_url":"https://api.github.com/repos/lambdageek/mono/milestones{/number}","notifications_url":"https://api.github.com/repos/lambdageek/mono/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lambdageek/mono/labels{/name}","releases_url":"https://api.github.com/repos/lambdageek/mono/releases{/id}","created_at":"2015-08-03T23:55:25Z","updated_at":"2015-11-13T23:53:24Z","pushed_at":"2015-12-17T22:34:08Z","git_url":"git://github.com/lambdageek/mono.git","ssh_url":"git@github.com:lambdageek/mono.git","clone_url":"https://github.com/lambdageek/mono.git","svn_url":"https://github.com/lambdageek/mono","homepage":"http://www.mono-project.com/","size":445109,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":false,"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":"mono:master","ref":"master","sha":"62eca45496cc2e6d91612ee1773b398866eba984","user":{"login":"mono","id":53395,"avatar_url":"https://avatars.githubusercontent.com/u/53395?v=3","gravatar_id":"","url":"https://api.github.com/users/mono","html_url":"https://github.com/mono","followers_url":"https://api.github.com/users/mono/followers","following_url":"https://api.github.com/users/mono/following{/other_user}","gists_url":"https://api.github.com/users/mono/gists{/gist_id}","starred_url":"https://api.github.com/users/mono/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mono/subscriptions","organizations_url":"https://api.github.com/users/mono/orgs","repos_url":"https://api.github.com/users/mono/repos","events_url":"https://api.github.com/users/mono/events{/privacy}","received_events_url":"https://api.github.com/users/mono/received_events","type":"Organization","site_admin":false},"repo":{"id":791611,"name":"mono","full_name":"mono/mono","owner":{"login":"mono","id":53395,"avatar_url":"https://avatars.githubusercontent.com/u/53395?v=3","gravatar_id":"","url":"https://api.github.com/users/mono","html_url":"https://github.com/mono","followers_url":"https://api.github.com/users/mono/followers","following_url":"https://api.github.com/users/mono/following{/other_user}","gists_url":"https://api.github.com/users/mono/gists{/gist_id}","starred_url":"https://api.github.com/users/mono/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mono/subscriptions","organizations_url":"https://api.github.com/users/mono/orgs","repos_url":"https://api.github.com/users/mono/repos","events_url":"https://api.github.com/users/mono/events{/privacy}","received_events_url":"https://api.github.com/users/mono/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mono/mono","description":"Mono open source ECMA CLI, C# and .NET implementation.","fork":false,"url":"https://api.github.com/repos/mono/mono","forks_url":"https://api.github.com/repos/mono/mono/forks","keys_url":"https://api.github.com/repos/mono/mono/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mono/mono/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mono/mono/teams","hooks_url":"https://api.github.com/repos/mono/mono/hooks","issue_events_url":"https://api.github.com/repos/mono/mono/issues/events{/number}","events_url":"https://api.github.com/repos/mono/mono/events","assignees_url":"https://api.github.com/repos/mono/mono/assignees{/user}","branches_url":"https://api.github.com/repos/mono/mono/branches{/branch}","tags_url":"https://api.github.com/repos/mono/mono/tags","blobs_url":"https://api.github.com/repos/mono/mono/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mono/mono/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mono/mono/git/refs{/sha}","trees_url":"https://api.github.com/repos/mono/mono/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mono/mono/statuses/{sha}","languages_url":"https://api.github.com/repos/mono/mono/languages","stargazers_url":"https://api.github.com/repos/mono/mono/stargazers","contributors_url":"https://api.github.com/repos/mono/mono/contributors","subscribers_url":"https://api.github.com/repos/mono/mono/subscribers","subscription_url":"https://api.github.com/repos/mono/mono/subscription","commits_url":"https://api.github.com/repos/mono/mono/commits{/sha}","git_commits_url":"https://api.github.com/repos/mono/mono/git/commits{/sha}","comments_url":"https://api.github.com/repos/mono/mono/comments{/number}","issue_comment_url":"https://api.github.com/repos/mono/mono/issues/comments{/number}","contents_url":"https://api.github.com/repos/mono/mono/contents/{+path}","compare_url":"https://api.github.com/repos/mono/mono/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mono/mono/merges","archive_url":"https://api.github.com/repos/mono/mono/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mono/mono/downloads","issues_url":"https://api.github.com/repos/mono/mono/issues{/number}","pulls_url":"https://api.github.com/repos/mono/mono/pulls{/number}","milestones_url":"https://api.github.com/repos/mono/mono/milestones{/number}","notifications_url":"https://api.github.com/repos/mono/mono/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mono/mono/labels{/name}","releases_url":"https://api.github.com/repos/mono/mono/releases{/id}","created_at":"2010-07-22T18:06:36Z","updated_at":"2015-12-18T09:10:46Z","pushed_at":"2015-12-18T06:38:25Z","git_url":"git://github.com/mono/mono.git","ssh_url":"git@github.com:mono/mono.git","clone_url":"https://github.com/mono/mono.git","svn_url":"https://github.com/mono/mono","homepage":"http://www.mono-project.com/","size":481159,"stargazers_count":4128,"watchers_count":4128,"language":"C#","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":2036,"mirror_url":null,"open_issues_count":122,"forks":2036,"open_issues":122,"watchers":4128,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mono/mono/pulls/2314"},"html":{"href":"https://github.com/mono/mono/pull/2314"},"issue":{"href":"https://api.github.com/repos/mono/mono/issues/2314"},"comments":{"href":"https://api.github.com/repos/mono/mono/issues/2314/comments"},"review_comments":{"href":"https://api.github.com/repos/mono/mono/pulls/2314/comments"},"review_comment":{"href":"https://api.github.com/repos/mono/mono/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mono/mono/pulls/2314/commits"},"statuses":{"href":"https://api.github.com/repos/mono/mono/statuses/9d8d66f0ee9eb876e99561b09ab0591c984ce54c"}}}}