We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Use CPython allocator in NRT
NRT should optionally use the CPython memory allocation functions (when imported from CPython). This would allow Numba-allocated memory to be seen by other utilities such as `sys.getallocatedblocks()`, `sys.debugmallocstats()`, and `tracemalloc`.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `numba/runtime/nrt.py`
Content:
```
1 from __future__ import print_function, absolute_import, division
2 
3 from collections import namedtuple
4 
5 from . import atomicops
6 from llvmlite import binding as ll
7 
8 from numba.utils import finalize as _finalize
9 from . import _nrt_python as _nrt
10 
11 _nrt_mstats = namedtuple("nrt_mstats", ["alloc", "free", "mi_alloc", "mi_free"])
12 
13 
14 class _Runtime(object):
15     def __init__(self):
16         self._init = False
17 
18     def initialize(self, ctx):
19         """Initializes the NRT
20 
21         Must be called before any actual call to the NRT API.
22         Safe to be called multiple times.
23         """
24         if self._init:
25             # Already initialized
26             return
27 
28         # Register globals into the system
29         for py_name in _nrt.c_helpers:
30             c_name = "NRT_" + py_name
31             c_address = _nrt.c_helpers[py_name]
32             ll.add_symbol(c_name, c_address)
33 
34         # Compile atomic operations
35         self._library = atomicops.compile_nrt_functions(ctx)
36 
37         self._ptr_inc = self._library.get_pointer_to_function("nrt_atomic_add")
38         self._ptr_dec = self._library.get_pointer_to_function("nrt_atomic_sub")
39         self._ptr_cas = self._library.get_pointer_to_function("nrt_atomic_cas")
40 
41         # Install atomic ops to NRT
42         _nrt.memsys_set_atomic_inc_dec(self._ptr_inc, self._ptr_dec)
43         _nrt.memsys_set_atomic_cas(self._ptr_cas)
44 
45         self._init = True
46 
47     @staticmethod
48     def shutdown():
49         """
50         Shutdown the NRT
51         Safe to be called without calling Runtime.initialize first
52         """
53         _nrt.memsys_shutdown()
54 
55     @property
56     def library(self):
57         """
58         Return the Library object containing the various NRT functions.
59         """
60         return self._library
61 
62     def meminfo_new(self, data, pyobj):
63         """
64         Returns a MemInfo object that tracks memory at `data` owned by `pyobj`.
65         MemInfo will acquire a reference on `pyobj`.
66         The release of MemInfo will release a reference on `pyobj`.
67         """
68         mi = _nrt.meminfo_new(data, pyobj)
69         return MemInfo(mi)
70 
71     def meminfo_alloc(self, size, safe=False):
72         """
73         Allocate a new memory of `size` bytes and returns a MemInfo object
74         that tracks the allocation.  When there is no more reference to the
75         MemInfo object, the underlying memory will be deallocated.
76 
77         If `safe` flag is True, the memory is allocated using the `safe` scheme.
78         This is used for debugging and testing purposes.
79         See `NRT_MemInfo_alloc_safe()` in "nrt.h" for details.
80         """
81         if safe:
82             mi = _nrt.meminfo_alloc_safe(size)
83         else:
84             mi = _nrt.meminfo_alloc(size)
85         return MemInfo(mi)
86 
87     def get_allocation_stats(self):
88         """
89         Returns a namedtuple of (alloc, free, mi_alloc, mi_free) for count of
90         each memory operations.
91         """
92         return _nrt_mstats(alloc=_nrt.memsys_get_stats_alloc(),
93                            free=_nrt.memsys_get_stats_free(),
94                            mi_alloc=_nrt.memsys_get_stats_mi_alloc(),
95                            mi_free=_nrt.memsys_get_stats_mi_free())
96 
97 
98 # Alias to _nrt_python._MemInfo
99 MemInfo = _nrt._MemInfo
100 
101 # Create uninitialized runtime
102 rtsys = _Runtime()
103 
104 # Install finalizer
105 _finalize(rtsys, _Runtime.shutdown)
106 
107 # Avoid future use of the class
108 del _Runtime
109
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/numba/runtime/nrt.py b/numba/runtime/nrt.py
--- a/numba/runtime/nrt.py
+++ b/numba/runtime/nrt.py
@@ -98,7 +98,8 @@
 # Alias to _nrt_python._MemInfo
 MemInfo = _nrt._MemInfo
 
-# Create uninitialized runtime
+# Create runtime
+_nrt.memsys_use_cpython_allocator()
 rtsys = _Runtime()
 
 # Install finalizer

{"golden_diff": "diff --git a/numba/runtime/nrt.py b/numba/runtime/nrt.py\n--- a/numba/runtime/nrt.py\n+++ b/numba/runtime/nrt.py\n@@ -98,7 +98,8 @@\n # Alias to _nrt_python._MemInfo\n MemInfo = _nrt._MemInfo\n \n-# Create uninitialized runtime\n+# Create runtime\n+_nrt.memsys_use_cpython_allocator()\n rtsys = _Runtime()\n \n # Install finalizer\n", "issue": "Use CPython allocator in NRT\nNRT should optionally use the CPython memory allocation functions (when imported from CPython). This would allow Numba-allocated memory to be seen by other utilities such as `sys.getallocatedblocks()`, `sys.debugmallocstats()`, and `tracemalloc`.\n\n", "before_files": [{"content": "from __future__ import print_function, absolute_import, division\n\nfrom collections import namedtuple\n\nfrom . import atomicops\nfrom llvmlite import binding as ll\n\nfrom numba.utils import finalize as _finalize\nfrom . import _nrt_python as _nrt\n\n_nrt_mstats = namedtuple(\"nrt_mstats\", [\"alloc\", \"free\", \"mi_alloc\", \"mi_free\"])\n\n\nclass _Runtime(object):\n    def __init__(self):\n        self._init = False\n\n    def initialize(self, ctx):\n        \"\"\"Initializes the NRT\n\n        Must be called before any actual call to the NRT API.\n        Safe to be called multiple times.\n        \"\"\"\n        if self._init:\n            # Already initialized\n            return\n\n        # Register globals into the system\n        for py_name in _nrt.c_helpers:\n            c_name = \"NRT_\" + py_name\n            c_address = _nrt.c_helpers[py_name]\n            ll.add_symbol(c_name, c_address)\n\n        # Compile atomic operations\n        self._library = atomicops.compile_nrt_functions(ctx)\n\n        self._ptr_inc = self._library.get_pointer_to_function(\"nrt_atomic_add\")\n        self._ptr_dec = self._library.get_pointer_to_function(\"nrt_atomic_sub\")\n        self._ptr_cas = self._library.get_pointer_to_function(\"nrt_atomic_cas\")\n\n        # Install atomic ops to NRT\n        _nrt.memsys_set_atomic_inc_dec(self._ptr_inc, self._ptr_dec)\n        _nrt.memsys_set_atomic_cas(self._ptr_cas)\n\n        self._init = True\n\n    @staticmethod\n    def shutdown():\n        \"\"\"\n        Shutdown the NRT\n        Safe to be called without calling Runtime.initialize first\n        \"\"\"\n        _nrt.memsys_shutdown()\n\n    @property\n    def library(self):\n        \"\"\"\n        Return the Library object containing the various NRT functions.\n        \"\"\"\n        return self._library\n\n    def meminfo_new(self, data, pyobj):\n        \"\"\"\n        Returns a MemInfo object that tracks memory at `data` owned by `pyobj`.\n        MemInfo will acquire a reference on `pyobj`.\n        The release of MemInfo will release a reference on `pyobj`.\n        \"\"\"\n        mi = _nrt.meminfo_new(data, pyobj)\n        return MemInfo(mi)\n\n    def meminfo_alloc(self, size, safe=False):\n        \"\"\"\n        Allocate a new memory of `size` bytes and returns a MemInfo object\n        that tracks the allocation.  When there is no more reference to the\n        MemInfo object, the underlying memory will be deallocated.\n\n        If `safe` flag is True, the memory is allocated using the `safe` scheme.\n        This is used for debugging and testing purposes.\n        See `NRT_MemInfo_alloc_safe()` in \"nrt.h\" for details.\n        \"\"\"\n        if safe:\n            mi = _nrt.meminfo_alloc_safe(size)\n        else:\n            mi = _nrt.meminfo_alloc(size)\n        return MemInfo(mi)\n\n    def get_allocation_stats(self):\n        \"\"\"\n        Returns a namedtuple of (alloc, free, mi_alloc, mi_free) for count of\n        each memory operations.\n        \"\"\"\n        return _nrt_mstats(alloc=_nrt.memsys_get_stats_alloc(),\n                           free=_nrt.memsys_get_stats_free(),\n                           mi_alloc=_nrt.memsys_get_stats_mi_alloc(),\n                           mi_free=_nrt.memsys_get_stats_mi_free())\n\n\n# Alias to _nrt_python._MemInfo\nMemInfo = _nrt._MemInfo\n\n# Create uninitialized runtime\nrtsys = _Runtime()\n\n# Install finalizer\n_finalize(rtsys, _Runtime.shutdown)\n\n# Avoid future use of the class\ndel _Runtime\n", "path": "numba/runtime/nrt.py"}], "after_files": [{"content": "from __future__ import print_function, absolute_import, division\n\nfrom collections import namedtuple\n\nfrom . import atomicops\nfrom llvmlite import binding as ll\n\nfrom numba.utils import finalize as _finalize\nfrom . import _nrt_python as _nrt\n\n_nrt_mstats = namedtuple(\"nrt_mstats\", [\"alloc\", \"free\", \"mi_alloc\", \"mi_free\"])\n\n\nclass _Runtime(object):\n    def __init__(self):\n        self._init = False\n\n    def initialize(self, ctx):\n        \"\"\"Initializes the NRT\n\n        Must be called before any actual call to the NRT API.\n        Safe to be called multiple times.\n        \"\"\"\n        if self._init:\n            # Already initialized\n            return\n\n        # Register globals into the system\n        for py_name in _nrt.c_helpers:\n            c_name = \"NRT_\" + py_name\n            c_address = _nrt.c_helpers[py_name]\n            ll.add_symbol(c_name, c_address)\n\n        # Compile atomic operations\n        self._library = atomicops.compile_nrt_functions(ctx)\n\n        self._ptr_inc = self._library.get_pointer_to_function(\"nrt_atomic_add\")\n        self._ptr_dec = self._library.get_pointer_to_function(\"nrt_atomic_sub\")\n        self._ptr_cas = self._library.get_pointer_to_function(\"nrt_atomic_cas\")\n\n        # Install atomic ops to NRT\n        _nrt.memsys_set_atomic_inc_dec(self._ptr_inc, self._ptr_dec)\n        _nrt.memsys_set_atomic_cas(self._ptr_cas)\n\n        self._init = True\n\n    @staticmethod\n    def shutdown():\n        \"\"\"\n        Shutdown the NRT\n        Safe to be called without calling Runtime.initialize first\n        \"\"\"\n        _nrt.memsys_shutdown()\n\n    @property\n    def library(self):\n        \"\"\"\n        Return the Library object containing the various NRT functions.\n        \"\"\"\n        return self._library\n\n    def meminfo_new(self, data, pyobj):\n        \"\"\"\n        Returns a MemInfo object that tracks memory at `data` owned by `pyobj`.\n        MemInfo will acquire a reference on `pyobj`.\n        The release of MemInfo will release a reference on `pyobj`.\n        \"\"\"\n        mi = _nrt.meminfo_new(data, pyobj)\n        return MemInfo(mi)\n\n    def meminfo_alloc(self, size, safe=False):\n        \"\"\"\n        Allocate a new memory of `size` bytes and returns a MemInfo object\n        that tracks the allocation.  When there is no more reference to the\n        MemInfo object, the underlying memory will be deallocated.\n\n        If `safe` flag is True, the memory is allocated using the `safe` scheme.\n        This is used for debugging and testing purposes.\n        See `NRT_MemInfo_alloc_safe()` in \"nrt.h\" for details.\n        \"\"\"\n        if safe:\n            mi = _nrt.meminfo_alloc_safe(size)\n        else:\n            mi = _nrt.meminfo_alloc(size)\n        return MemInfo(mi)\n\n    def get_allocation_stats(self):\n        \"\"\"\n        Returns a namedtuple of (alloc, free, mi_alloc, mi_free) for count of\n        each memory operations.\n        \"\"\"\n        return _nrt_mstats(alloc=_nrt.memsys_get_stats_alloc(),\n                           free=_nrt.memsys_get_stats_free(),\n                           mi_alloc=_nrt.memsys_get_stats_mi_alloc(),\n                           mi_free=_nrt.memsys_get_stats_mi_free())\n\n\n# Alias to _nrt_python._MemInfo\nMemInfo = _nrt._MemInfo\n\n# Create runtime\n_nrt.memsys_use_cpython_allocator()\nrtsys = _Runtime()\n\n# Install finalizer\n_finalize(rtsys, _Runtime.shutdown)\n\n# Avoid future use of the class\ndel _Runtime\n", "path": "numba/runtime/nrt.py"}]}