{"action":"created","comment":{"url":"https://api.github.com/repos/numba/numba/pulls/comments/28889563","id":28889563,"diff_hunk":"@@ -0,0 +1,539 @@\n+#include \"_pymodule.h\"\n+#include \"nrt.h\"\n+\n+#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\n+#include <numpy/ndarrayobject.h>\n+#include <numpy/arrayscalars.h>\n+\n+#include \"_arraystruct.h\"\n+\n+/* For Numpy 1.6 */\n+#ifndef NPY_ARRAY_BEHAVED\n+    #define NPY_ARRAY_BEHAVED NPY_BEHAVED\n+#endif\n+\n+\n+static\n+PyObject*\n+memsys_shutdown(PyObject *self, PyObject *args) {\n+    if (!PyArg_ParseTuple(args, \"\")) {\n+        return NULL;\n+    }\n+    NRT_MemSys_shutdown();\n+    Py_RETURN_NONE;\n+}\n+\n+static\n+PyObject*\n+memsys_set_atomic_inc_dec(PyObject *self, PyObject *args) {\n+    unsigned PY_LONG_LONG addr_inc, addr_dec;\n+    if (!PyArg_ParseTuple(args, \"KK\", &addr_inc, &addr_dec)) {\n+        return NULL;\n+    }\n+    NRT_MemSys_set_atomic_inc_dec((void*)addr_inc, (void*)addr_dec);\n+    Py_RETURN_NONE;\n+}\n+\n+static\n+PyObject*\n+memsys_set_atomic_cas(PyObject *self, PyObject *args) {\n+    unsigned PY_LONG_LONG addr_cas;\n+    if (!PyArg_ParseTuple(args, \"K\", &addr_cas)) {\n+        return NULL;\n+    }\n+    NRT_MemSys_set_atomic_cas((void*)addr_cas);\n+    Py_RETURN_NONE;\n+}\n+\n+static\n+PyObject*\n+memsys_process_defer_dtor(PyObject *self, PyObject *args) {\n+    if (!PyArg_ParseTuple(args, \"\")) {\n+        return NULL;\n+    }\n+    NRT_MemSys_process_defer_dtor();\n+    Py_RETURN_NONE;\n+}\n+\n+\n+static\n+void pyobject_dtor(void *ptr, void* info) {\n+    PyGILState_STATE gstate;\n+    PyObject *ownerobj = info;\n+\n+    gstate = PyGILState_Ensure();   /* ensure the GIL */\n+    Py_DECREF(ownerobj);            /* release the python object */\n+    PyGILState_Release(gstate);     /* release the GIL */\n+}\n+\n+\n+static\n+MemInfo* meminfo_new_from_pyobject(void *data, PyObject *ownerobj) {\n+    size_t dummy_size = 0;\n+    Py_INCREF(ownerobj);\n+    return NRT_MemInfo_new(data, dummy_size, pyobject_dtor, ownerobj);\n+}\n+\n+\n+/*\n+ * Create a new MemInfo with a owner PyObject\n+ */\n+static\n+PyObject*\n+meminfo_new(PyObject *self, PyObject *args) {\n+    unsigned PY_LONG_LONG addr_data;\n+    PyObject* ownerobj;\n+    MemInfo *mi;\n+    if (!PyArg_ParseTuple(args, \"KO\", &addr_data, &ownerobj)) {\n+        return NULL;\n+    }\n+    mi = meminfo_new_from_pyobject((void*)addr_data, ownerobj);\n+    return PyLong_FromVoidPtr(mi);\n+}\n+\n+/*\n+ * Create a new MemInfo with a new NRT allocation\n+ */\n+static\n+PyObject*\n+meminfo_alloc(PyObject *self, PyObject *args) {\n+    MemInfo *mi;\n+    Py_ssize_t size;\n+    if (!PyArg_ParseTuple(args, \"K\", &size)) {\n+        return NULL;\n+    }\n+    mi = NRT_MemInfo_alloc(size);\n+    return PyLong_FromVoidPtr(mi);\n+}\n+\n+/*\n+ * Like meminfo_alloc but set memory to zero after allocation and before\n+ * deallocation.\n+ */\n+static\n+PyObject*\n+meminfo_alloc_safe(PyObject *self, PyObject *args) {\n+    MemInfo *mi;\n+    Py_ssize_t size;\n+    if (!PyArg_ParseTuple(args, \"K\", &size)) {\n+        return NULL;\n+    }\n+    mi = NRT_MemInfo_alloc_safe(size);\n+    return PyLong_FromVoidPtr(mi);\n+}\n+\n+typedef struct {\n+    PyObject_HEAD\n+    MemInfo *meminfo;\n+    int      defer;\n+} MemInfoObject;\n+\n+static\n+int MemInfo_init(MemInfoObject *self, PyObject *args, PyObject *kwds) {\n+    static char *keywords[] = {\"ptr\", NULL};\n+    unsigned PY_LONG_LONG raw_ptr;\n+    if (!PyArg_ParseTupleAndKeywords(args, kwds, \"K\", keywords, &raw_ptr)) {\n+        return -1;\n+    }\n+    self->meminfo = (MemInfo*)raw_ptr;\n+    self->defer = 0;\n+    NRT_MemInfo_acquire(self->meminfo);\n+    return 0;\n+}\n+\n+int MemInfo_getbuffer(PyObject *exporter, Py_buffer *view, int flags) {\n+    Py_ssize_t len;\n+    void *buf;\n+    int readonly = 0;\n+\n+    MemInfoObject *miobj = (MemInfoObject*)exporter;\n+    MemInfo *mi = miobj->meminfo;\n+\n+    buf = NRT_MemInfo_data(mi);\n+    len = NRT_MemInfo_size(mi);\n+    return PyBuffer_FillInfo(view, exporter, buf, len, readonly, flags);\n+}\n+\n+Py_ssize_t MemInfo_rdwrbufferproc(PyObject *self, Py_ssize_t segment,\n+                                  void **ptrptr)\n+{\n+    MemInfoObject *mio = (MemInfoObject *)self;\n+    MemInfo *mi = mio->meminfo;\n+    if (segment != 0) {\n+        PyErr_SetString(PyExc_TypeError, \"MemInfo only has 1 segment\");\n+        return -1;\n+    }\n+    *ptrptr = NRT_MemInfo_data(mi);\n+    return NRT_MemInfo_size(mi);\n+}\n+\n+Py_ssize_t MemInfo_segcountproc(PyObject *self, Py_ssize_t *lenp) {\n+    MemInfoObject *mio = (MemInfoObject *)self;\n+    MemInfo *mi = mio->meminfo;\n+    if (lenp) {\n+        *lenp = NRT_MemInfo_size(mi);\n+    }\n+    return 1;\n+}\n+\n+#if (PY_MAJOR_VERSION < 3)\n+static PyBufferProcs MemInfo_bufferProcs = {MemInfo_rdwrbufferproc,","path":"numba/runtime/_nrt_python.c","position":180,"original_position":180,"commit_id":"eccef3d051ae34ac6831d80fefa80f1724d02368","original_commit_id":"eccef3d051ae34ac6831d80fefa80f1724d02368","user":{"login":"pitrou","id":1721820,"avatar_url":"https://avatars.githubusercontent.com/u/1721820?v=3","gravatar_id":"","url":"https://api.github.com/users/pitrou","html_url":"https://github.com/pitrou","followers_url":"https://api.github.com/users/pitrou/followers","following_url":"https://api.github.com/users/pitrou/following{/other_user}","gists_url":"https://api.github.com/users/pitrou/gists{/gist_id}","starred_url":"https://api.github.com/users/pitrou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pitrou/subscriptions","organizations_url":"https://api.github.com/users/pitrou/orgs","repos_url":"https://api.github.com/users/pitrou/repos","events_url":"https://api.github.com/users/pitrou/events{/privacy}","received_events_url":"https://api.github.com/users/pitrou/received_events","type":"User","site_admin":false},"body":"Instead of that, you can implement the new buffer protocol on Python 2. Enable the Py_TPFLAGS_HAVE_NEWBUFFER and see here for an example:\r\nhttps://hg.python.org/cpython/file/4bf210f59ac6/Objects/bytearrayobject.c#l2800","created_at":"2015-04-22T16:26:37Z","updated_at":"2015-04-22T16:26:37Z","html_url":"https://github.com/numba/numba/pull/1077#discussion_r28889563","pull_request_url":"https://api.github.com/repos/numba/numba/pulls/1077","_links":{"self":{"href":"https://api.github.com/repos/numba/numba/pulls/comments/28889563"},"html":{"href":"https://github.com/numba/numba/pull/1077#discussion_r28889563"},"pull_request":{"href":"https://api.github.com/repos/numba/numba/pulls/1077"}}},"pull_request":{"url":"https://api.github.com/repos/numba/numba/pulls/1077","id":32996971,"html_url":"https://github.com/numba/numba/pull/1077","diff_url":"https://github.com/numba/numba/pull/1077.diff","patch_url":"https://github.com/numba/numba/pull/1077.patch","issue_url":"https://api.github.com/repos/numba/numba/issues/1077","number":1077,"state":"open","locked":false,"title":"Memory management for array allocation in nopython","user":{"login":"sklam","id":1929845,"avatar_url":"https://avatars.githubusercontent.com/u/1929845?v=3","gravatar_id":"","url":"https://api.github.com/users/sklam","html_url":"https://github.com/sklam","followers_url":"https://api.github.com/users/sklam/followers","following_url":"https://api.github.com/users/sklam/following{/other_user}","gists_url":"https://api.github.com/users/sklam/gists{/gist_id}","starred_url":"https://api.github.com/users/sklam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sklam/subscriptions","organizations_url":"https://api.github.com/users/sklam/orgs","repos_url":"https://api.github.com/users/sklam/repos","events_url":"https://api.github.com/users/sklam/events{/privacy}","received_events_url":"https://api.github.com/users/sklam/received_events","type":"User","site_admin":false},"body":"* Introduces a *numba runtime* or NRT\r\n* New option to jit, njit ``nrt=True`` to enable NRT.\r\n* support ``np.empty()`` in nopython+nrt\r\n* return array, return slices of array in nopython+nrt\r\n* return any array in nopython+nrt\r\n","created_at":"2015-04-09T21:13:35Z","updated_at":"2015-04-22T16:26:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"65d3e6218e443de57817da27fbe661298adf6a96","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/numba/numba/pulls/1077/commits","review_comments_url":"https://api.github.com/repos/numba/numba/pulls/1077/comments","review_comment_url":"https://api.github.com/repos/numba/numba/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numba/numba/issues/1077/comments","statuses_url":"https://api.github.com/repos/numba/numba/statuses/eccef3d051ae34ac6831d80fefa80f1724d02368","head":{"label":"sklam:numba_runtime","ref":"numba_runtime","sha":"eccef3d051ae34ac6831d80fefa80f1724d02368","user":{"login":"sklam","id":1929845,"avatar_url":"https://avatars.githubusercontent.com/u/1929845?v=3","gravatar_id":"","url":"https://api.github.com/users/sklam","html_url":"https://github.com/sklam","followers_url":"https://api.github.com/users/sklam/followers","following_url":"https://api.github.com/users/sklam/following{/other_user}","gists_url":"https://api.github.com/users/sklam/gists{/gist_id}","starred_url":"https://api.github.com/users/sklam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sklam/subscriptions","organizations_url":"https://api.github.com/users/sklam/orgs","repos_url":"https://api.github.com/users/sklam/repos","events_url":"https://api.github.com/users/sklam/events{/privacy}","received_events_url":"https://api.github.com/users/sklam/received_events","type":"User","site_admin":false},"repo":{"id":4992750,"name":"numba","full_name":"sklam/numba","owner":{"login":"sklam","id":1929845,"avatar_url":"https://avatars.githubusercontent.com/u/1929845?v=3","gravatar_id":"","url":"https://api.github.com/users/sklam","html_url":"https://github.com/sklam","followers_url":"https://api.github.com/users/sklam/followers","following_url":"https://api.github.com/users/sklam/following{/other_user}","gists_url":"https://api.github.com/users/sklam/gists{/gist_id}","starred_url":"https://api.github.com/users/sklam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sklam/subscriptions","organizations_url":"https://api.github.com/users/sklam/orgs","repos_url":"https://api.github.com/users/sklam/repos","events_url":"https://api.github.com/users/sklam/events{/privacy}","received_events_url":"https://api.github.com/users/sklam/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sklam/numba","description":"NumPy aware dynamic Python compiler using LLVM","fork":true,"url":"https://api.github.com/repos/sklam/numba","forks_url":"https://api.github.com/repos/sklam/numba/forks","keys_url":"https://api.github.com/repos/sklam/numba/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sklam/numba/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sklam/numba/teams","hooks_url":"https://api.github.com/repos/sklam/numba/hooks","issue_events_url":"https://api.github.com/repos/sklam/numba/issues/events{/number}","events_url":"https://api.github.com/repos/sklam/numba/events","assignees_url":"https://api.github.com/repos/sklam/numba/assignees{/user}","branches_url":"https://api.github.com/repos/sklam/numba/branches{/branch}","tags_url":"https://api.github.com/repos/sklam/numba/tags","blobs_url":"https://api.github.com/repos/sklam/numba/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sklam/numba/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sklam/numba/git/refs{/sha}","trees_url":"https://api.github.com/repos/sklam/numba/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sklam/numba/statuses/{sha}","languages_url":"https://api.github.com/repos/sklam/numba/languages","stargazers_url":"https://api.github.com/repos/sklam/numba/stargazers","contributors_url":"https://api.github.com/repos/sklam/numba/contributors","subscribers_url":"https://api.github.com/repos/sklam/numba/subscribers","subscription_url":"https://api.github.com/repos/sklam/numba/subscription","commits_url":"https://api.github.com/repos/sklam/numba/commits{/sha}","git_commits_url":"https://api.github.com/repos/sklam/numba/git/commits{/sha}","comments_url":"https://api.github.com/repos/sklam/numba/comments{/number}","issue_comment_url":"https://api.github.com/repos/sklam/numba/issues/comments{/number}","contents_url":"https://api.github.com/repos/sklam/numba/contents/{+path}","compare_url":"https://api.github.com/repos/sklam/numba/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sklam/numba/merges","archive_url":"https://api.github.com/repos/sklam/numba/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sklam/numba/downloads","issues_url":"https://api.github.com/repos/sklam/numba/issues{/number}","pulls_url":"https://api.github.com/repos/sklam/numba/pulls{/number}","milestones_url":"https://api.github.com/repos/sklam/numba/milestones{/number}","notifications_url":"https://api.github.com/repos/sklam/numba/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sklam/numba/labels{/name}","releases_url":"https://api.github.com/repos/sklam/numba/releases{/id}","created_at":"2012-07-11T17:49:38Z","updated_at":"2015-04-21T17:10:09Z","pushed_at":"2015-04-22T16:14:48Z","git_url":"git://github.com/sklam/numba.git","ssh_url":"git@github.com:sklam/numba.git","clone_url":"https://github.com/sklam/numba.git","svn_url":"https://github.com/sklam/numba","homepage":"","size":23561,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"numba:master","ref":"master","sha":"808fcf4ab188bcea069cb9b2b5456dc782e1bf52","user":{"login":"numba","id":1628082,"avatar_url":"https://avatars.githubusercontent.com/u/1628082?v=3","gravatar_id":"","url":"https://api.github.com/users/numba","html_url":"https://github.com/numba","followers_url":"https://api.github.com/users/numba/followers","following_url":"https://api.github.com/users/numba/following{/other_user}","gists_url":"https://api.github.com/users/numba/gists{/gist_id}","starred_url":"https://api.github.com/users/numba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numba/subscriptions","organizations_url":"https://api.github.com/users/numba/orgs","repos_url":"https://api.github.com/users/numba/repos","events_url":"https://api.github.com/users/numba/events{/privacy}","received_events_url":"https://api.github.com/users/numba/received_events","type":"Organization","site_admin":false},"repo":{"id":3659275,"name":"numba","full_name":"numba/numba","owner":{"login":"numba","id":1628082,"avatar_url":"https://avatars.githubusercontent.com/u/1628082?v=3","gravatar_id":"","url":"https://api.github.com/users/numba","html_url":"https://github.com/numba","followers_url":"https://api.github.com/users/numba/followers","following_url":"https://api.github.com/users/numba/following{/other_user}","gists_url":"https://api.github.com/users/numba/gists{/gist_id}","starred_url":"https://api.github.com/users/numba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numba/subscriptions","organizations_url":"https://api.github.com/users/numba/orgs","repos_url":"https://api.github.com/users/numba/repos","events_url":"https://api.github.com/users/numba/events{/privacy}","received_events_url":"https://api.github.com/users/numba/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numba/numba","description":"NumPy aware dynamic Python compiler using LLVM","fork":false,"url":"https://api.github.com/repos/numba/numba","forks_url":"https://api.github.com/repos/numba/numba/forks","keys_url":"https://api.github.com/repos/numba/numba/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numba/numba/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numba/numba/teams","hooks_url":"https://api.github.com/repos/numba/numba/hooks","issue_events_url":"https://api.github.com/repos/numba/numba/issues/events{/number}","events_url":"https://api.github.com/repos/numba/numba/events","assignees_url":"https://api.github.com/repos/numba/numba/assignees{/user}","branches_url":"https://api.github.com/repos/numba/numba/branches{/branch}","tags_url":"https://api.github.com/repos/numba/numba/tags","blobs_url":"https://api.github.com/repos/numba/numba/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numba/numba/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numba/numba/git/refs{/sha}","trees_url":"https://api.github.com/repos/numba/numba/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numba/numba/statuses/{sha}","languages_url":"https://api.github.com/repos/numba/numba/languages","stargazers_url":"https://api.github.com/repos/numba/numba/stargazers","contributors_url":"https://api.github.com/repos/numba/numba/contributors","subscribers_url":"https://api.github.com/repos/numba/numba/subscribers","subscription_url":"https://api.github.com/repos/numba/numba/subscription","commits_url":"https://api.github.com/repos/numba/numba/commits{/sha}","git_commits_url":"https://api.github.com/repos/numba/numba/git/commits{/sha}","comments_url":"https://api.github.com/repos/numba/numba/comments{/number}","issue_comment_url":"https://api.github.com/repos/numba/numba/issues/comments{/number}","contents_url":"https://api.github.com/repos/numba/numba/contents/{+path}","compare_url":"https://api.github.com/repos/numba/numba/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numba/numba/merges","archive_url":"https://api.github.com/repos/numba/numba/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numba/numba/downloads","issues_url":"https://api.github.com/repos/numba/numba/issues{/number}","pulls_url":"https://api.github.com/repos/numba/numba/pulls{/number}","milestones_url":"https://api.github.com/repos/numba/numba/milestones{/number}","notifications_url":"https://api.github.com/repos/numba/numba/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numba/numba/labels{/name}","releases_url":"https://api.github.com/repos/numba/numba/releases{/id}","created_at":"2012-03-08T11:12:43Z","updated_at":"2015-04-22T14:50:56Z","pushed_at":"2015-04-22T15:28:08Z","git_url":"git://github.com/numba/numba.git","ssh_url":"git@github.com:numba/numba.git","clone_url":"https://github.com/numba/numba.git","svn_url":"https://github.com/numba/numba","homepage":"","size":33862,"stargazers_count":1433,"watchers_count":1433,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":149,"mirror_url":null,"open_issues_count":151,"forks":149,"open_issues":151,"watchers":1433,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numba/numba/pulls/1077"},"html":{"href":"https://github.com/numba/numba/pull/1077"},"issue":{"href":"https://api.github.com/repos/numba/numba/issues/1077"},"comments":{"href":"https://api.github.com/repos/numba/numba/issues/1077/comments"},"review_comments":{"href":"https://api.github.com/repos/numba/numba/pulls/1077/comments"},"review_comment":{"href":"https://api.github.com/repos/numba/numba/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numba/numba/pulls/1077/commits"},"statuses":{"href":"https://api.github.com/repos/numba/numba/statuses/eccef3d051ae34ac6831d80fefa80f1724d02368"}}}}