{"action":"opened","number":706,"pull_request":{"url":"https://api.github.com/repos/ocaml/ocaml/pulls/706","id":78305993,"html_url":"https://github.com/ocaml/ocaml/pull/706","diff_url":"https://github.com/ocaml/ocaml/pull/706.diff","patch_url":"https://github.com/ocaml/ocaml/pull/706.patch","issue_url":"https://api.github.com/repos/ocaml/ocaml/issues/706","number":706,"state":"open","locked":false,"title":"Allow to lookup and load cmi files from memory or other sources","user":{"login":"diml","id":1251584,"avatar_url":"https://avatars.githubusercontent.com/u/1251584?v=3","gravatar_id":"","url":"https://api.github.com/users/diml","html_url":"https://github.com/diml","followers_url":"https://api.github.com/users/diml/followers","following_url":"https://api.github.com/users/diml/following{/other_user}","gists_url":"https://api.github.com/users/diml/gists{/gist_id}","starred_url":"https://api.github.com/users/diml/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diml/subscriptions","organizations_url":"https://api.github.com/users/diml/orgs","repos_url":"https://api.github.com/users/diml/repos","events_url":"https://api.github.com/users/diml/events{/privacy}","received_events_url":"https://api.github.com/users/diml/received_events","type":"User","site_admin":false},"body":"This patch adds a hook in the `Env` module for looking up and loading cmi files.\r\n\r\n## API\r\n\r\n```ocaml\r\nmodule Persistent_signature : sig\r\n  type t =\r\n    { filename : string; (** Name of the file containing the signature. *)\r\n      cmi : Cmi_format.cmi_infos }\r\n\r\n  (** Function used to load a persistent signature. The default is to look for\r\n      the .cmi file in the load path. This function can be overridden to load\r\n      it from memory, for instance to build a self-contained toplevel. *)\r\n  val load : (unit_name:string -> t option) ref\r\nend\r\n```\r\n\r\n## Motivation\r\n\r\nUsing this one can easily embed cmi files in an executable to create a self-contained toplevel. A test doing exactly this is added to the testsuite. This is something that I wanted to do on several occasions.\r\n\r\nIt's already possible to do something similar by playing with `LD_PRELOAD`, this patch just makes it easier and more portable.\r\n\r\n## Changes\r\n\r\nThis patch moves the lookup in the load path and reading of the cmi file from `Env.find_pers_struct` to the initial value of the `load` function. The only suspicious change is that before this patch `add_import` was called between the lookup and `read_cmi` by `find_pers_struct` while it's now called after `read_cmi`. I did this change as otherwise the user would have to manually call `add_import` in the hook, which doesn't seem right.\r\n\r\nAs far as I can see, only `check_pers_struct` catches and handles `Cmi_format.Error` exceptions raised by `find_pers_struct`. Moreover `add_import` is always called before `check_pers_struct` (line 524). In other cases the exception just leaks to the driver so this path shouldn't _drop_ imports by mistake.\r\n\r\n\r\n\r\n","created_at":"2016-07-21T12:20:24Z","updated_at":"2016-07-21T12:20:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2d33ad8280e1ba03e0062a19b4074e1f06336980","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ocaml/ocaml/pulls/706/commits","review_comments_url":"https://api.github.com/repos/ocaml/ocaml/pulls/706/comments","review_comment_url":"https://api.github.com/repos/ocaml/ocaml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ocaml/ocaml/issues/706/comments","statuses_url":"https://api.github.com/repos/ocaml/ocaml/statuses/b5cfe9fdd13587080850ef8d329a3938b3692d74","head":{"label":"diml:Env.Persistent_signature.load","ref":"Env.Persistent_signature.load","sha":"b5cfe9fdd13587080850ef8d329a3938b3692d74","user":{"login":"diml","id":1251584,"avatar_url":"https://avatars.githubusercontent.com/u/1251584?v=3","gravatar_id":"","url":"https://api.github.com/users/diml","html_url":"https://github.com/diml","followers_url":"https://api.github.com/users/diml/followers","following_url":"https://api.github.com/users/diml/following{/other_user}","gists_url":"https://api.github.com/users/diml/gists{/gist_id}","starred_url":"https://api.github.com/users/diml/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diml/subscriptions","organizations_url":"https://api.github.com/users/diml/orgs","repos_url":"https://api.github.com/users/diml/repos","events_url":"https://api.github.com/users/diml/events{/privacy}","received_events_url":"https://api.github.com/users/diml/received_events","type":"User","site_admin":false},"repo":{"id":17478091,"name":"ocaml","full_name":"diml/ocaml","owner":{"login":"diml","id":1251584,"avatar_url":"https://avatars.githubusercontent.com/u/1251584?v=3","gravatar_id":"","url":"https://api.github.com/users/diml","html_url":"https://github.com/diml","followers_url":"https://api.github.com/users/diml/followers","following_url":"https://api.github.com/users/diml/following{/other_user}","gists_url":"https://api.github.com/users/diml/gists{/gist_id}","starred_url":"https://api.github.com/users/diml/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diml/subscriptions","organizations_url":"https://api.github.com/users/diml/orgs","repos_url":"https://api.github.com/users/diml/repos","events_url":"https://api.github.com/users/diml/events{/privacy}","received_events_url":"https://api.github.com/users/diml/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/diml/ocaml","description":"Read-only mirror of INRIA SVN","fork":true,"url":"https://api.github.com/repos/diml/ocaml","forks_url":"https://api.github.com/repos/diml/ocaml/forks","keys_url":"https://api.github.com/repos/diml/ocaml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/diml/ocaml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/diml/ocaml/teams","hooks_url":"https://api.github.com/repos/diml/ocaml/hooks","issue_events_url":"https://api.github.com/repos/diml/ocaml/issues/events{/number}","events_url":"https://api.github.com/repos/diml/ocaml/events","assignees_url":"https://api.github.com/repos/diml/ocaml/assignees{/user}","branches_url":"https://api.github.com/repos/diml/ocaml/branches{/branch}","tags_url":"https://api.github.com/repos/diml/ocaml/tags","blobs_url":"https://api.github.com/repos/diml/ocaml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/diml/ocaml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/diml/ocaml/git/refs{/sha}","trees_url":"https://api.github.com/repos/diml/ocaml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/diml/ocaml/statuses/{sha}","languages_url":"https://api.github.com/repos/diml/ocaml/languages","stargazers_url":"https://api.github.com/repos/diml/ocaml/stargazers","contributors_url":"https://api.github.com/repos/diml/ocaml/contributors","subscribers_url":"https://api.github.com/repos/diml/ocaml/subscribers","subscription_url":"https://api.github.com/repos/diml/ocaml/subscription","commits_url":"https://api.github.com/repos/diml/ocaml/commits{/sha}","git_commits_url":"https://api.github.com/repos/diml/ocaml/git/commits{/sha}","comments_url":"https://api.github.com/repos/diml/ocaml/comments{/number}","issue_comment_url":"https://api.github.com/repos/diml/ocaml/issues/comments{/number}","contents_url":"https://api.github.com/repos/diml/ocaml/contents/{+path}","compare_url":"https://api.github.com/repos/diml/ocaml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/diml/ocaml/merges","archive_url":"https://api.github.com/repos/diml/ocaml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/diml/ocaml/downloads","issues_url":"https://api.github.com/repos/diml/ocaml/issues{/number}","pulls_url":"https://api.github.com/repos/diml/ocaml/pulls{/number}","milestones_url":"https://api.github.com/repos/diml/ocaml/milestones{/number}","notifications_url":"https://api.github.com/repos/diml/ocaml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/diml/ocaml/labels{/name}","releases_url":"https://api.github.com/repos/diml/ocaml/releases{/id}","deployments_url":"https://api.github.com/repos/diml/ocaml/deployments","created_at":"2014-03-06T13:13:44Z","updated_at":"2015-09-08T14:07:01Z","pushed_at":"2016-07-21T11:53:53Z","git_url":"git://github.com/diml/ocaml.git","ssh_url":"git@github.com:diml/ocaml.git","clone_url":"https://github.com/diml/ocaml.git","svn_url":"https://github.com/diml/ocaml","homepage":null,"size":163485,"stargazers_count":0,"watchers_count":0,"language":"OCaml","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"trunk"}},"base":{"label":"ocaml:trunk","ref":"trunk","sha":"e82191fea3890426e4499668041c14694fef8dd2","user":{"login":"ocaml","id":1841483,"avatar_url":"https://avatars.githubusercontent.com/u/1841483?v=3","gravatar_id":"","url":"https://api.github.com/users/ocaml","html_url":"https://github.com/ocaml","followers_url":"https://api.github.com/users/ocaml/followers","following_url":"https://api.github.com/users/ocaml/following{/other_user}","gists_url":"https://api.github.com/users/ocaml/gists{/gist_id}","starred_url":"https://api.github.com/users/ocaml/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ocaml/subscriptions","organizations_url":"https://api.github.com/users/ocaml/orgs","repos_url":"https://api.github.com/users/ocaml/repos","events_url":"https://api.github.com/users/ocaml/events{/privacy}","received_events_url":"https://api.github.com/users/ocaml/received_events","type":"Organization","site_admin":false},"repo":{"id":6786166,"name":"ocaml","full_name":"ocaml/ocaml","owner":{"login":"ocaml","id":1841483,"avatar_url":"https://avatars.githubusercontent.com/u/1841483?v=3","gravatar_id":"","url":"https://api.github.com/users/ocaml","html_url":"https://github.com/ocaml","followers_url":"https://api.github.com/users/ocaml/followers","following_url":"https://api.github.com/users/ocaml/following{/other_user}","gists_url":"https://api.github.com/users/ocaml/gists{/gist_id}","starred_url":"https://api.github.com/users/ocaml/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ocaml/subscriptions","organizations_url":"https://api.github.com/users/ocaml/orgs","repos_url":"https://api.github.com/users/ocaml/repos","events_url":"https://api.github.com/users/ocaml/events{/privacy}","received_events_url":"https://api.github.com/users/ocaml/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ocaml/ocaml","description":"The core OCaml system: compilers, runtime system, base libraries","fork":false,"url":"https://api.github.com/repos/ocaml/ocaml","forks_url":"https://api.github.com/repos/ocaml/ocaml/forks","keys_url":"https://api.github.com/repos/ocaml/ocaml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ocaml/ocaml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ocaml/ocaml/teams","hooks_url":"https://api.github.com/repos/ocaml/ocaml/hooks","issue_events_url":"https://api.github.com/repos/ocaml/ocaml/issues/events{/number}","events_url":"https://api.github.com/repos/ocaml/ocaml/events","assignees_url":"https://api.github.com/repos/ocaml/ocaml/assignees{/user}","branches_url":"https://api.github.com/repos/ocaml/ocaml/branches{/branch}","tags_url":"https://api.github.com/repos/ocaml/ocaml/tags","blobs_url":"https://api.github.com/repos/ocaml/ocaml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ocaml/ocaml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ocaml/ocaml/git/refs{/sha}","trees_url":"https://api.github.com/repos/ocaml/ocaml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ocaml/ocaml/statuses/{sha}","languages_url":"https://api.github.com/repos/ocaml/ocaml/languages","stargazers_url":"https://api.github.com/repos/ocaml/ocaml/stargazers","contributors_url":"https://api.github.com/repos/ocaml/ocaml/contributors","subscribers_url":"https://api.github.com/repos/ocaml/ocaml/subscribers","subscription_url":"https://api.github.com/repos/ocaml/ocaml/subscription","commits_url":"https://api.github.com/repos/ocaml/ocaml/commits{/sha}","git_commits_url":"https://api.github.com/repos/ocaml/ocaml/git/commits{/sha}","comments_url":"https://api.github.com/repos/ocaml/ocaml/comments{/number}","issue_comment_url":"https://api.github.com/repos/ocaml/ocaml/issues/comments{/number}","contents_url":"https://api.github.com/repos/ocaml/ocaml/contents/{+path}","compare_url":"https://api.github.com/repos/ocaml/ocaml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ocaml/ocaml/merges","archive_url":"https://api.github.com/repos/ocaml/ocaml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ocaml/ocaml/downloads","issues_url":"https://api.github.com/repos/ocaml/ocaml/issues{/number}","pulls_url":"https://api.github.com/repos/ocaml/ocaml/pulls{/number}","milestones_url":"https://api.github.com/repos/ocaml/ocaml/milestones{/number}","notifications_url":"https://api.github.com/repos/ocaml/ocaml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ocaml/ocaml/labels{/name}","releases_url":"https://api.github.com/repos/ocaml/ocaml/releases{/id}","deployments_url":"https://api.github.com/repos/ocaml/ocaml/deployments","created_at":"2012-11-20T22:18:22Z","updated_at":"2016-07-21T03:44:08Z","pushed_at":"2016-07-21T12:20:24Z","git_url":"git://github.com/ocaml/ocaml.git","ssh_url":"git@github.com:ocaml/ocaml.git","clone_url":"https://github.com/ocaml/ocaml.git","svn_url":"https://github.com/ocaml/ocaml","homepage":"","size":244078,"stargazers_count":859,"watchers_count":859,"language":"OCaml","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":264,"mirror_url":null,"open_issues_count":108,"forks":264,"open_issues":108,"watchers":859,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/ocaml/ocaml/pulls/706"},"html":{"href":"https://github.com/ocaml/ocaml/pull/706"},"issue":{"href":"https://api.github.com/repos/ocaml/ocaml/issues/706"},"comments":{"href":"https://api.github.com/repos/ocaml/ocaml/issues/706/comments"},"review_comments":{"href":"https://api.github.com/repos/ocaml/ocaml/pulls/706/comments"},"review_comment":{"href":"https://api.github.com/repos/ocaml/ocaml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ocaml/ocaml/pulls/706/commits"},"statuses":{"href":"https://api.github.com/repos/ocaml/ocaml/statuses/b5cfe9fdd13587080850ef8d329a3938b3692d74"}},"merged":false,"mergeable":true,"mergeable_state":"clean","merged_by":null,"comments":0,"review_comments":0,"commits":2,"additions":97,"deletions":8,"changed_files":10}}
{"actor":{"display_login":"diml"}}