title: Cython unable to import and execute a function: Storing unsafe C derivative of temporary Python reference
body: <p>I'm new to Cython and just trying to experiment with a simple script. I'm unable to import a function from a module and use it in another file, but if I declare the function in the same file it works just fine. What could be the problem here. Am I missing something?</p>
  
  <p>This is the original code snippet (test_cy.pyx):</p>
  
  <pre><code># test_cy.pyx
  
  import json
  
  cpdef char* say_hello():
    message = json.dumps({"message": "Hello world"})
    return message.encode()
  
  cdef char* fn(int n):
    cdef char* hello = say_hello()
    return hello
  
  def test():
    cdef char* n = fn(1000)
    print(n)
  </code></pre>
  
  <p>I can run it like (After compiling):</p>
  
  <pre><code>&gt;&gt;&gt; import test_cy
  &gt;&gt;&gt; test_cy.test()
  b'Hello world'
  </code></pre>
  
  <p>However, if I move the say_hello function to another file (utils.pyx):</p>
  
  <pre><code># utils.pyx
  
  import json
  
  cpdef char* say_hello():
    message = json.dumps({"message": "Hello world"})
    return message.encode()
  </code></pre>
  
  <p>... And import it in my original test_cy.pyx file like so:</p>
  
  <pre><code># test_cy.pyx
  
  from utils import say_hello
  
  cdef char* fn(int n):
    cdef char* hello = say_hello()
    return hello
  
  def test():
    cdef char* n = fn(1000)
    print(n)
  </code></pre>
  
  <p>I'm unable to get it to compile as I get the following error:</p>
  
  <pre><code>&gt;&gt;&gt; python3 setup.py build_ext --inplace
  ...
  Error compiling Cython file:
  ------------------------------------------------------------
  ...
  from utils import say_hello
  
  cdef char* fn(int n):
    cdef char* hello = say_hello()
        ^
  ------------------------------------------------------------
  
  test_cy.pyx:4:7: Storing unsafe C derivative of temporary Python reference
  Traceback (most recent call last):
    File "setup.py", line 11, in &lt;module&gt;
      sources=["utils.pyx"]
    File "/Users/asim/.pyenv/versions/3.6.9/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1101, in cythonize
      cythonize_one(*args)
    File "/Users/asim/.pyenv/versions/3.6.9/lib/python3.6/site-packages/Cython/Build/Dependencies.py", line 1224, in cythonize_one
      raise CompileError(None, pyx_file)
  Cython.Compiler.Errors.CompileError: test_cy.pyx
  </code></pre>
  
  <p>Here's my setup.py file:</p>
  
  <pre><code>from distutils.core import setup
  from distutils.extension import Extension
  from Cython.Build import cythonize
  
  setup(
    ext_modules = cythonize([
      Extension("test_cy",
                sources=["test_cy.pyx"]
      ),
      Extension("utils",
                sources=["utils.pyx"]
      )
    ])
  )
  </code></pre>
  
  <p>Please help me as something so simple like importing a function from another module shouldn't be  this complicated. I might be missing something trivial. Thanks!</p>