We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Numba UnicodeEncodeError after importing unicode_literals 
Taking example below from numba documentation with the only addition of `unicode_literals` import and the doc string that contains unicode characters:

```
from __future__ import unicode_literals
from numba import jit
from numpy import arange

# jit decorator tells Numba to compile this function.
# The argument types will be inferred by Numba when function is called.
@jit
def sum2d(arr):
    """ – """
    M, N = arr.shape
    result = 0.0
    for i in range(M):
        for j in range(N):
            result += arr[i,j]
    return result

a = arange(9).reshape(3,3)
print(sum2d(a))
```

Gives an error below. The error appears only after `unicode_literals` is imported:

```
raise patched_exception
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 1: ordinal not in range(128)

D:\Anaconda\envs\py2k\lib\site-packages\numba\compiler.py:257: UnicodeEncodeError
```

`python = 2.7.11`
`numba = 0.25.0`


--- 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/targets/cpu.py`
Content:
```
1 from __future__ import print_function, absolute_import
2 
3 import sys
4 
5 import llvmlite.llvmpy.core as lc
6 import llvmlite.binding as ll
7 
8 from numba import _dynfunc, config
9 from numba.callwrapper import PyCallWrapper
10 from .base import BaseContext, PYOBJECT
11 from numba import utils, cgutils, types
12 from numba.utils import cached_property
13 from numba.targets import callconv, codegen, externals, intrinsics, listobj, setobj
14 from .options import TargetOptions
15 from numba.runtime import rtsys
16 
17 # Keep those structures in sync with _dynfunc.c.
18 
19 class ClosureBody(cgutils.Structure):
20     _fields = [('env', types.pyobject)]
21 
22 
23 class EnvBody(cgutils.Structure):
24     _fields = [
25         ('globals', types.pyobject),
26         ('consts', types.pyobject),
27     ]
28 
29 
30 class CPUContext(BaseContext):
31     """
32     Changes BaseContext calling convention
33     """
34     # Overrides
35     def create_module(self, name):
36         return self._internal_codegen._create_empty_module(name)
37 
38     def init(self):
39         self.is32bit = (utils.MACHINE_BITS == 32)
40         self._internal_codegen = codegen.JITCPUCodegen("numba.exec")
41 
42         # Map external C functions.
43         externals.c_math_functions.install(self)
44         externals.c_numpy_functions.install(self)
45 
46         # Initialize NRT runtime
47         rtsys.initialize(self)
48 
49     def load_additional_registries(self):
50         # Add target specific implementations
51         from . import (cffiimpl, cmathimpl, mathimpl, npyimpl, operatorimpl,
52                        printimpl, randomimpl)
53         self.install_registry(cmathimpl.registry)
54         self.install_registry(cffiimpl.registry)
55         self.install_registry(mathimpl.registry)
56         self.install_registry(npyimpl.registry)
57         self.install_registry(operatorimpl.registry)
58         self.install_registry(printimpl.registry)
59         self.install_registry(randomimpl.registry)
60         # Initialize PRNG state
61         randomimpl.random_init()
62 
63     @property
64     def target_data(self):
65         return self._internal_codegen.target_data
66 
67     def with_aot_codegen(self, name, **aot_options):
68         aot_codegen = codegen.AOTCPUCodegen(name, **aot_options)
69         return self.subtarget(_internal_codegen=aot_codegen,
70                               aot_mode=True)
71 
72     def codegen(self):
73         return self._internal_codegen
74 
75     @cached_property
76     def call_conv(self):
77         return callconv.CPUCallConv(self)
78 
79     def get_env_from_closure(self, builder, clo):
80         """
81         From the pointer *clo* to a _dynfunc.Closure, get a pointer
82         to the enclosed _dynfunc.Environment.
83         """
84         with cgutils.if_unlikely(builder, cgutils.is_null(builder, clo)):
85             self.debug_print(builder, "Fatal error: missing _dynfunc.Closure")
86             builder.unreachable()
87 
88         clo_body_ptr = cgutils.pointer_add(
89             builder, clo, _dynfunc._impl_info['offsetof_closure_body'])
90         clo_body = ClosureBody(self, builder, ref=clo_body_ptr, cast_ref=True)
91         return clo_body.env
92 
93     def get_env_body(self, builder, envptr):
94         """
95         From the given *envptr* (a pointer to a _dynfunc.Environment object),
96         get a EnvBody allowing structured access to environment fields.
97         """
98         body_ptr = cgutils.pointer_add(
99             builder, envptr, _dynfunc._impl_info['offsetof_env_body'])
100         return EnvBody(self, builder, ref=body_ptr, cast_ref=True)
101 
102     def get_generator_state(self, builder, genptr, return_type):
103         """
104         From the given *genptr* (a pointer to a _dynfunc.Generator object),
105         get a pointer to its state area.
106         """
107         return cgutils.pointer_add(
108             builder, genptr, _dynfunc._impl_info['offsetof_generator_state'],
109             return_type=return_type)
110 
111     def build_list(self, builder, list_type, items):
112         """
113         Build a list from the Numba *list_type* and its initial *items*.
114         """
115         return listobj.build_list(self, builder, list_type, items)
116 
117     def build_set(self, builder, set_type, items):
118         """
119         Build a set from the Numba *set_type* and its initial *items*.
120         """
121         return setobj.build_set(self, builder, set_type, items)
122 
123     def post_lowering(self, mod, library):
124         if self.is32bit:
125             # 32-bit machine needs to replace all 64-bit div/rem to avoid
126             # calls to compiler-rt
127             intrinsics.fix_divmod(mod)
128 
129         library.add_linking_library(rtsys.library)
130 
131     def create_cpython_wrapper(self, library, fndesc, env, call_helper,
132                                release_gil=False):
133         wrapper_module = self.create_module("wrapper")
134         fnty = self.call_conv.get_function_type(fndesc.restype, fndesc.argtypes)
135         wrapper_callee = wrapper_module.add_function(fnty, fndesc.llvm_func_name)
136         builder = PyCallWrapper(self, wrapper_module, wrapper_callee,
137                                 fndesc, env, call_helper=call_helper,
138                                 release_gil=release_gil)
139         builder.build()
140         library.add_ir_module(wrapper_module)
141 
142     def get_executable(self, library, fndesc, env):
143         """
144         Returns
145         -------
146         (cfunc, fnptr)
147 
148         - cfunc
149             callable function (Can be None)
150         - fnptr
151             callable function address
152         - env
153             an execution environment (from _dynfunc)
154         """
155         # Code generation
156         baseptr = library.get_pointer_to_function(fndesc.llvm_func_name)
157         fnptr = library.get_pointer_to_function(fndesc.llvm_cpython_wrapper_name)
158 
159         cfunc = _dynfunc.make_function(fndesc.lookup_module(),
160                                        fndesc.qualname.split('.')[-1],
161                                        fndesc.doc, fnptr, env,
162                                        # objects to keepalive with the function
163                                        (library,)
164                                        )
165 
166         return cfunc
167 
168     def calc_array_sizeof(self, ndim):
169         '''
170         Calculate the size of an array struct on the CPU target
171         '''
172         aryty = types.Array(types.int32, ndim, 'A')
173         return self.get_abi_sizeof(self.get_value_type(aryty))
174 
175 
176 # ----------------------------------------------------------------------------
177 # TargetOptions
178 
179 class CPUTargetOptions(TargetOptions):
180     OPTIONS = {
181         "nopython": bool,
182         "nogil": bool,
183         "forceobj": bool,
184         "looplift": bool,
185         "boundcheck": bool,
186         "_nrt": bool,
187         "no_rewrites": bool,
188     }
189 
190 
191 # ----------------------------------------------------------------------------
192 # Internal
193 
194 def remove_refct_calls(func):
195     """
196     Remove redundant incref/decref within on a per block basis
197     """
198     for bb in func.basic_blocks:
199         remove_null_refct_call(bb)
200         remove_refct_pairs(bb)
201 
202 
203 def remove_null_refct_call(bb):
204     """
205     Remove refct api calls to NULL pointer
206     """
207     pass
208     ## Skipped for now
209     # for inst in bb.instructions:
210     #     if isinstance(inst, lc.CallOrInvokeInstruction):
211     #         fname = inst.called_function.name
212     #         if fname == "Py_IncRef" or fname == "Py_DecRef":
213     #             arg = inst.args[0]
214     #             print(type(arg))
215     #             if isinstance(arg, lc.ConstantPointerNull):
216     #                 inst.erase_from_parent()
217 
218 
219 def remove_refct_pairs(bb):
220     """
221     Remove incref decref pairs on the same variable
222     """
223 
224     didsomething = True
225 
226     while didsomething:
227         didsomething = False
228 
229         increfs = {}
230         decrefs = {}
231 
232         # Mark
233         for inst in bb.instructions:
234             if isinstance(inst, lc.CallOrInvokeInstruction):
235                 fname = inst.called_function.name
236                 if fname == "Py_IncRef":
237                     arg = inst.operands[0]
238                     increfs[arg] = inst
239                 elif fname == "Py_DecRef":
240                     arg = inst.operands[0]
241                     decrefs[arg] = inst
242 
243         # Sweep
244         for val in increfs.keys():
245             if val in decrefs:
246                 increfs[val].erase_from_parent()
247                 decrefs[val].erase_from_parent()
248                 didsomething = True
249
```
--- 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/targets/cpu.py b/numba/targets/cpu.py
--- a/numba/targets/cpu.py
+++ b/numba/targets/cpu.py
@@ -156,9 +156,12 @@
         baseptr = library.get_pointer_to_function(fndesc.llvm_func_name)
         fnptr = library.get_pointer_to_function(fndesc.llvm_cpython_wrapper_name)
 
+        # Note: we avoid reusing the original docstring to avoid encoding
+        # issues on Python 2, see issue #1908
+        doc = "compiled wrapper for %r" % (fndesc.qualname,)
         cfunc = _dynfunc.make_function(fndesc.lookup_module(),
                                        fndesc.qualname.split('.')[-1],
-                                       fndesc.doc, fnptr, env,
+                                       doc, fnptr, env,
                                        # objects to keepalive with the function
                                        (library,)
                                        )

{"golden_diff": "diff --git a/numba/targets/cpu.py b/numba/targets/cpu.py\n--- a/numba/targets/cpu.py\n+++ b/numba/targets/cpu.py\n@@ -156,9 +156,12 @@\n         baseptr = library.get_pointer_to_function(fndesc.llvm_func_name)\n         fnptr = library.get_pointer_to_function(fndesc.llvm_cpython_wrapper_name)\n \n+        # Note: we avoid reusing the original docstring to avoid encoding\n+        # issues on Python 2, see issue #1908\n+        doc = \"compiled wrapper for %r\" % (fndesc.qualname,)\n         cfunc = _dynfunc.make_function(fndesc.lookup_module(),\n                                        fndesc.qualname.split('.')[-1],\n-                                       fndesc.doc, fnptr, env,\n+                                       doc, fnptr, env,\n                                        # objects to keepalive with the function\n                                        (library,)\n                                        )\n", "issue": "Numba UnicodeEncodeError after importing unicode_literals \nTaking example below from numba documentation with the only addition of `unicode_literals` import and the doc string that contains unicode characters:\n\n```\nfrom __future__ import unicode_literals\nfrom numba import jit\nfrom numpy import arange\n\n# jit decorator tells Numba to compile this function.\n# The argument types will be inferred by Numba when function is called.\n@jit\ndef sum2d(arr):\n    \"\"\" \u2013 \"\"\"\n    M, N = arr.shape\n    result = 0.0\n    for i in range(M):\n        for j in range(N):\n            result += arr[i,j]\n    return result\n\na = arange(9).reshape(3,3)\nprint(sum2d(a))\n```\n\nGives an error below. The error appears only after `unicode_literals` is imported:\n\n```\nraise patched_exception\nUnicodeEncodeError: 'ascii' codec can't encode character u'\\u2013' in position 1: ordinal not in range(128)\n\nD:\\Anaconda\\envs\\py2k\\lib\\site-packages\\numba\\compiler.py:257: UnicodeEncodeError\n```\n\n`python = 2.7.11`\n`numba = 0.25.0`\n\n", "before_files": [{"content": "from __future__ import print_function, absolute_import\n\nimport sys\n\nimport llvmlite.llvmpy.core as lc\nimport llvmlite.binding as ll\n\nfrom numba import _dynfunc, config\nfrom numba.callwrapper import PyCallWrapper\nfrom .base import BaseContext, PYOBJECT\nfrom numba import utils, cgutils, types\nfrom numba.utils import cached_property\nfrom numba.targets import callconv, codegen, externals, intrinsics, listobj, setobj\nfrom .options import TargetOptions\nfrom numba.runtime import rtsys\n\n# Keep those structures in sync with _dynfunc.c.\n\nclass ClosureBody(cgutils.Structure):\n    _fields = [('env', types.pyobject)]\n\n\nclass EnvBody(cgutils.Structure):\n    _fields = [\n        ('globals', types.pyobject),\n        ('consts', types.pyobject),\n    ]\n\n\nclass CPUContext(BaseContext):\n    \"\"\"\n    Changes BaseContext calling convention\n    \"\"\"\n    # Overrides\n    def create_module(self, name):\n        return self._internal_codegen._create_empty_module(name)\n\n    def init(self):\n        self.is32bit = (utils.MACHINE_BITS == 32)\n        self._internal_codegen = codegen.JITCPUCodegen(\"numba.exec\")\n\n        # Map external C functions.\n        externals.c_math_functions.install(self)\n        externals.c_numpy_functions.install(self)\n\n        # Initialize NRT runtime\n        rtsys.initialize(self)\n\n    def load_additional_registries(self):\n        # Add target specific implementations\n        from . import (cffiimpl, cmathimpl, mathimpl, npyimpl, operatorimpl,\n                       printimpl, randomimpl)\n        self.install_registry(cmathimpl.registry)\n        self.install_registry(cffiimpl.registry)\n        self.install_registry(mathimpl.registry)\n        self.install_registry(npyimpl.registry)\n        self.install_registry(operatorimpl.registry)\n        self.install_registry(printimpl.registry)\n        self.install_registry(randomimpl.registry)\n        # Initialize PRNG state\n        randomimpl.random_init()\n\n    @property\n    def target_data(self):\n        return self._internal_codegen.target_data\n\n    def with_aot_codegen(self, name, **aot_options):\n        aot_codegen = codegen.AOTCPUCodegen(name, **aot_options)\n        return self.subtarget(_internal_codegen=aot_codegen,\n                              aot_mode=True)\n\n    def codegen(self):\n        return self._internal_codegen\n\n    @cached_property\n    def call_conv(self):\n        return callconv.CPUCallConv(self)\n\n    def get_env_from_closure(self, builder, clo):\n        \"\"\"\n        From the pointer *clo* to a _dynfunc.Closure, get a pointer\n        to the enclosed _dynfunc.Environment.\n        \"\"\"\n        with cgutils.if_unlikely(builder, cgutils.is_null(builder, clo)):\n            self.debug_print(builder, \"Fatal error: missing _dynfunc.Closure\")\n            builder.unreachable()\n\n        clo_body_ptr = cgutils.pointer_add(\n            builder, clo, _dynfunc._impl_info['offsetof_closure_body'])\n        clo_body = ClosureBody(self, builder, ref=clo_body_ptr, cast_ref=True)\n        return clo_body.env\n\n    def get_env_body(self, builder, envptr):\n        \"\"\"\n        From the given *envptr* (a pointer to a _dynfunc.Environment object),\n        get a EnvBody allowing structured access to environment fields.\n        \"\"\"\n        body_ptr = cgutils.pointer_add(\n            builder, envptr, _dynfunc._impl_info['offsetof_env_body'])\n        return EnvBody(self, builder, ref=body_ptr, cast_ref=True)\n\n    def get_generator_state(self, builder, genptr, return_type):\n        \"\"\"\n        From the given *genptr* (a pointer to a _dynfunc.Generator object),\n        get a pointer to its state area.\n        \"\"\"\n        return cgutils.pointer_add(\n            builder, genptr, _dynfunc._impl_info['offsetof_generator_state'],\n            return_type=return_type)\n\n    def build_list(self, builder, list_type, items):\n        \"\"\"\n        Build a list from the Numba *list_type* and its initial *items*.\n        \"\"\"\n        return listobj.build_list(self, builder, list_type, items)\n\n    def build_set(self, builder, set_type, items):\n        \"\"\"\n        Build a set from the Numba *set_type* and its initial *items*.\n        \"\"\"\n        return setobj.build_set(self, builder, set_type, items)\n\n    def post_lowering(self, mod, library):\n        if self.is32bit:\n            # 32-bit machine needs to replace all 64-bit div/rem to avoid\n            # calls to compiler-rt\n            intrinsics.fix_divmod(mod)\n\n        library.add_linking_library(rtsys.library)\n\n    def create_cpython_wrapper(self, library, fndesc, env, call_helper,\n                               release_gil=False):\n        wrapper_module = self.create_module(\"wrapper\")\n        fnty = self.call_conv.get_function_type(fndesc.restype, fndesc.argtypes)\n        wrapper_callee = wrapper_module.add_function(fnty, fndesc.llvm_func_name)\n        builder = PyCallWrapper(self, wrapper_module, wrapper_callee,\n                                fndesc, env, call_helper=call_helper,\n                                release_gil=release_gil)\n        builder.build()\n        library.add_ir_module(wrapper_module)\n\n    def get_executable(self, library, fndesc, env):\n        \"\"\"\n        Returns\n        -------\n        (cfunc, fnptr)\n\n        - cfunc\n            callable function (Can be None)\n        - fnptr\n            callable function address\n        - env\n            an execution environment (from _dynfunc)\n        \"\"\"\n        # Code generation\n        baseptr = library.get_pointer_to_function(fndesc.llvm_func_name)\n        fnptr = library.get_pointer_to_function(fndesc.llvm_cpython_wrapper_name)\n\n        cfunc = _dynfunc.make_function(fndesc.lookup_module(),\n                                       fndesc.qualname.split('.')[-1],\n                                       fndesc.doc, fnptr, env,\n                                       # objects to keepalive with the function\n                                       (library,)\n                                       )\n\n        return cfunc\n\n    def calc_array_sizeof(self, ndim):\n        '''\n        Calculate the size of an array struct on the CPU target\n        '''\n        aryty = types.Array(types.int32, ndim, 'A')\n        return self.get_abi_sizeof(self.get_value_type(aryty))\n\n\n# ----------------------------------------------------------------------------\n# TargetOptions\n\nclass CPUTargetOptions(TargetOptions):\n    OPTIONS = {\n        \"nopython\": bool,\n        \"nogil\": bool,\n        \"forceobj\": bool,\n        \"looplift\": bool,\n        \"boundcheck\": bool,\n        \"_nrt\": bool,\n        \"no_rewrites\": bool,\n    }\n\n\n# ----------------------------------------------------------------------------\n# Internal\n\ndef remove_refct_calls(func):\n    \"\"\"\n    Remove redundant incref/decref within on a per block basis\n    \"\"\"\n    for bb in func.basic_blocks:\n        remove_null_refct_call(bb)\n        remove_refct_pairs(bb)\n\n\ndef remove_null_refct_call(bb):\n    \"\"\"\n    Remove refct api calls to NULL pointer\n    \"\"\"\n    pass\n    ## Skipped for now\n    # for inst in bb.instructions:\n    #     if isinstance(inst, lc.CallOrInvokeInstruction):\n    #         fname = inst.called_function.name\n    #         if fname == \"Py_IncRef\" or fname == \"Py_DecRef\":\n    #             arg = inst.args[0]\n    #             print(type(arg))\n    #             if isinstance(arg, lc.ConstantPointerNull):\n    #                 inst.erase_from_parent()\n\n\ndef remove_refct_pairs(bb):\n    \"\"\"\n    Remove incref decref pairs on the same variable\n    \"\"\"\n\n    didsomething = True\n\n    while didsomething:\n        didsomething = False\n\n        increfs = {}\n        decrefs = {}\n\n        # Mark\n        for inst in bb.instructions:\n            if isinstance(inst, lc.CallOrInvokeInstruction):\n                fname = inst.called_function.name\n                if fname == \"Py_IncRef\":\n                    arg = inst.operands[0]\n                    increfs[arg] = inst\n                elif fname == \"Py_DecRef\":\n                    arg = inst.operands[0]\n                    decrefs[arg] = inst\n\n        # Sweep\n        for val in increfs.keys():\n            if val in decrefs:\n                increfs[val].erase_from_parent()\n                decrefs[val].erase_from_parent()\n                didsomething = True\n", "path": "numba/targets/cpu.py"}], "after_files": [{"content": "from __future__ import print_function, absolute_import\n\nimport sys\n\nimport llvmlite.llvmpy.core as lc\nimport llvmlite.binding as ll\n\nfrom numba import _dynfunc, config\nfrom numba.callwrapper import PyCallWrapper\nfrom .base import BaseContext, PYOBJECT\nfrom numba import utils, cgutils, types\nfrom numba.utils import cached_property\nfrom numba.targets import callconv, codegen, externals, intrinsics, listobj, setobj\nfrom .options import TargetOptions\nfrom numba.runtime import rtsys\n\n# Keep those structures in sync with _dynfunc.c.\n\nclass ClosureBody(cgutils.Structure):\n    _fields = [('env', types.pyobject)]\n\n\nclass EnvBody(cgutils.Structure):\n    _fields = [\n        ('globals', types.pyobject),\n        ('consts', types.pyobject),\n    ]\n\n\nclass CPUContext(BaseContext):\n    \"\"\"\n    Changes BaseContext calling convention\n    \"\"\"\n    # Overrides\n    def create_module(self, name):\n        return self._internal_codegen._create_empty_module(name)\n\n    def init(self):\n        self.is32bit = (utils.MACHINE_BITS == 32)\n        self._internal_codegen = codegen.JITCPUCodegen(\"numba.exec\")\n\n        # Map external C functions.\n        externals.c_math_functions.install(self)\n        externals.c_numpy_functions.install(self)\n\n        # Initialize NRT runtime\n        rtsys.initialize(self)\n\n    def load_additional_registries(self):\n        # Add target specific implementations\n        from . import (cffiimpl, cmathimpl, mathimpl, npyimpl, operatorimpl,\n                       printimpl, randomimpl)\n        self.install_registry(cmathimpl.registry)\n        self.install_registry(cffiimpl.registry)\n        self.install_registry(mathimpl.registry)\n        self.install_registry(npyimpl.registry)\n        self.install_registry(operatorimpl.registry)\n        self.install_registry(printimpl.registry)\n        self.install_registry(randomimpl.registry)\n        # Initialize PRNG state\n        randomimpl.random_init()\n\n    @property\n    def target_data(self):\n        return self._internal_codegen.target_data\n\n    def with_aot_codegen(self, name, **aot_options):\n        aot_codegen = codegen.AOTCPUCodegen(name, **aot_options)\n        return self.subtarget(_internal_codegen=aot_codegen,\n                              aot_mode=True)\n\n    def codegen(self):\n        return self._internal_codegen\n\n    @cached_property\n    def call_conv(self):\n        return callconv.CPUCallConv(self)\n\n    def get_env_from_closure(self, builder, clo):\n        \"\"\"\n        From the pointer *clo* to a _dynfunc.Closure, get a pointer\n        to the enclosed _dynfunc.Environment.\n        \"\"\"\n        with cgutils.if_unlikely(builder, cgutils.is_null(builder, clo)):\n            self.debug_print(builder, \"Fatal error: missing _dynfunc.Closure\")\n            builder.unreachable()\n\n        clo_body_ptr = cgutils.pointer_add(\n            builder, clo, _dynfunc._impl_info['offsetof_closure_body'])\n        clo_body = ClosureBody(self, builder, ref=clo_body_ptr, cast_ref=True)\n        return clo_body.env\n\n    def get_env_body(self, builder, envptr):\n        \"\"\"\n        From the given *envptr* (a pointer to a _dynfunc.Environment object),\n        get a EnvBody allowing structured access to environment fields.\n        \"\"\"\n        body_ptr = cgutils.pointer_add(\n            builder, envptr, _dynfunc._impl_info['offsetof_env_body'])\n        return EnvBody(self, builder, ref=body_ptr, cast_ref=True)\n\n    def get_generator_state(self, builder, genptr, return_type):\n        \"\"\"\n        From the given *genptr* (a pointer to a _dynfunc.Generator object),\n        get a pointer to its state area.\n        \"\"\"\n        return cgutils.pointer_add(\n            builder, genptr, _dynfunc._impl_info['offsetof_generator_state'],\n            return_type=return_type)\n\n    def build_list(self, builder, list_type, items):\n        \"\"\"\n        Build a list from the Numba *list_type* and its initial *items*.\n        \"\"\"\n        return listobj.build_list(self, builder, list_type, items)\n\n    def build_set(self, builder, set_type, items):\n        \"\"\"\n        Build a set from the Numba *set_type* and its initial *items*.\n        \"\"\"\n        return setobj.build_set(self, builder, set_type, items)\n\n    def post_lowering(self, mod, library):\n        if self.is32bit:\n            # 32-bit machine needs to replace all 64-bit div/rem to avoid\n            # calls to compiler-rt\n            intrinsics.fix_divmod(mod)\n\n        library.add_linking_library(rtsys.library)\n\n    def create_cpython_wrapper(self, library, fndesc, env, call_helper,\n                               release_gil=False):\n        wrapper_module = self.create_module(\"wrapper\")\n        fnty = self.call_conv.get_function_type(fndesc.restype, fndesc.argtypes)\n        wrapper_callee = wrapper_module.add_function(fnty, fndesc.llvm_func_name)\n        builder = PyCallWrapper(self, wrapper_module, wrapper_callee,\n                                fndesc, env, call_helper=call_helper,\n                                release_gil=release_gil)\n        builder.build()\n        library.add_ir_module(wrapper_module)\n\n    def get_executable(self, library, fndesc, env):\n        \"\"\"\n        Returns\n        -------\n        (cfunc, fnptr)\n\n        - cfunc\n            callable function (Can be None)\n        - fnptr\n            callable function address\n        - env\n            an execution environment (from _dynfunc)\n        \"\"\"\n        # Code generation\n        baseptr = library.get_pointer_to_function(fndesc.llvm_func_name)\n        fnptr = library.get_pointer_to_function(fndesc.llvm_cpython_wrapper_name)\n\n        # Note: we avoid reusing the original docstring to avoid encoding\n        # issues on Python 2, see issue #1908\n        doc = \"compiled wrapper for %r\" % (fndesc.qualname,)\n        cfunc = _dynfunc.make_function(fndesc.lookup_module(),\n                                       fndesc.qualname.split('.')[-1],\n                                       doc, fnptr, env,\n                                       # objects to keepalive with the function\n                                       (library,)\n                                       )\n\n        return cfunc\n\n    def calc_array_sizeof(self, ndim):\n        '''\n        Calculate the size of an array struct on the CPU target\n        '''\n        aryty = types.Array(types.int32, ndim, 'A')\n        return self.get_abi_sizeof(self.get_value_type(aryty))\n\n\n# ----------------------------------------------------------------------------\n# TargetOptions\n\nclass CPUTargetOptions(TargetOptions):\n    OPTIONS = {\n        \"nopython\": bool,\n        \"nogil\": bool,\n        \"forceobj\": bool,\n        \"looplift\": bool,\n        \"boundcheck\": bool,\n        \"_nrt\": bool,\n        \"no_rewrites\": bool,\n    }\n\n\n# ----------------------------------------------------------------------------\n# Internal\n\ndef remove_refct_calls(func):\n    \"\"\"\n    Remove redundant incref/decref within on a per block basis\n    \"\"\"\n    for bb in func.basic_blocks:\n        remove_null_refct_call(bb)\n        remove_refct_pairs(bb)\n\n\ndef remove_null_refct_call(bb):\n    \"\"\"\n    Remove refct api calls to NULL pointer\n    \"\"\"\n    pass\n    ## Skipped for now\n    # for inst in bb.instructions:\n    #     if isinstance(inst, lc.CallOrInvokeInstruction):\n    #         fname = inst.called_function.name\n    #         if fname == \"Py_IncRef\" or fname == \"Py_DecRef\":\n    #             arg = inst.args[0]\n    #             print(type(arg))\n    #             if isinstance(arg, lc.ConstantPointerNull):\n    #                 inst.erase_from_parent()\n\n\ndef remove_refct_pairs(bb):\n    \"\"\"\n    Remove incref decref pairs on the same variable\n    \"\"\"\n\n    didsomething = True\n\n    while didsomething:\n        didsomething = False\n\n        increfs = {}\n        decrefs = {}\n\n        # Mark\n        for inst in bb.instructions:\n            if isinstance(inst, lc.CallOrInvokeInstruction):\n                fname = inst.called_function.name\n                if fname == \"Py_IncRef\":\n                    arg = inst.operands[0]\n                    increfs[arg] = inst\n                elif fname == \"Py_DecRef\":\n                    arg = inst.operands[0]\n                    decrefs[arg] = inst\n\n        # Sweep\n        for val in increfs.keys():\n            if val in decrefs:\n                increfs[val].erase_from_parent()\n                decrefs[val].erase_from_parent()\n                didsomething = True\n", "path": "numba/targets/cpu.py"}]}