Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad code generated for `except +_topyexc` function calling another such function #3064

Open
navytux opened this issue Jul 31, 2019 · 0 comments

Comments

@navytux
Copy link
Contributor

commented Jul 31, 2019

Hello up there. Please consider the following example:

---- 8< ---- (qqq.pyx)

# cython: language_level=2                                                                              
# distutils: language=c++
                                                                                                        
cdef void _topyexc() except *:
    raise RuntimeError("zzz")                                                                           
                                                                                                        
cdef extern from *:
    """
    #include <exception>
    void panic() {
        throw std::bad_alloc();
    }
    """
    void panic() except +_topyexc

cdef void zzz() except +_topyexc:
    panic()

When trying to cythonize, it gives:

/home/kirr/src/tools/go/pygolang/golang/qqq.cpp: In function ‘void __pyx_f_6golang_3qqq_zzz()’:
/home/kirr/src/tools/go/pygolang/golang/qqq.cpp:1148:3: error: ‘__pyx_r’ was not declared in this scope
   __pyx_r = <Cython.Compiler.ExprNodes.NameNode object at 0x7fcdd7b78ca0>;
   ^~~~~~~
/home/kirr/src/tools/go/pygolang/golang/qqq.cpp:1148:3: note: suggested alternative: ‘__pyx_f’
   __pyx_r = <Cython.Compiler.ExprNodes.NameNode object at 0x7fcdd7b78ca0>;
   ^~~~~~~
   __pyx_f
/home/kirr/src/tools/go/pygolang/golang/qqq.cpp:1148:13: error: expected primary-expression before ‘<’ token
   __pyx_r = <Cython.Compiler.ExprNodes.NameNode object at 0x7fcdd7b78ca0>;
             ^
/home/kirr/src/tools/go/pygolang/golang/qqq.cpp:1148:14: error: ‘Cython’ was not declared in this scope
   __pyx_r = <Cython.Compiler.ExprNodes.NameNode object at 0x7fcdd7b78ca0>;
              ^~~~~~

Here is the full source of generated __pyx_f_6golang_3qqq_zzz:

static void __pyx_f_6golang_3qqq_zzz(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("zzz", 0);

  /* "golang/qqq.pyx":17
 * 
 * cdef void zzz() except +_topyexc:
 *     panic()             # <<<<<<<<<<<<<<
 * 
 */
  try {
    panic();
  } catch(...) {
    __pyx_f_6golang_3qqq__topyexc(); if (!PyErr_Occurred())PyErr_SetString(PyExc_RuntimeError, "Error converting c++ exception.");
    __PYX_ERR(0, 17, __pyx_L1_error)
  }

  /* "golang/qqq.pyx":16
 *     void panic() except +_topyexc
 * 
 * cdef void zzz() except +_topyexc:             # <<<<<<<<<<<<<<
 *     panic()
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("golang.qqq.zzz", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = <Cython.Compiler.ExprNodes.NameNode object at 0x7fd305110ca0>;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

It compiles ok if I remove _topyexc usage, so that the functions are marked with only except +:

# cython: language_level=2
# distutils: language=c++

cdef extern from *:
    """
    #include <exception>
    void panic() {                                                                                      
        throw std::bad_alloc();
    }
    """                                                                                                 
    void panic() except +

cdef void zzz() except +:
    panic()

Cython version: 0.29.13-514-gac1c9fe47 (today's master)

Thanks beforehand,
Kirill

/cc @scoder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.