Ticket #42 (closed defect: fixed)

Opened 5 years ago

Last modified 4 weeks ago

C++ compile error when exception part declared on function

Reported by: d.brooks@… Owned by: somebody
Priority: minor Milestone: wishlist
Component: Code Generation Keywords:
Cc:

Description

The following results in gcc 4.01 reporting "error: invalid conversion from ‘const char*’ to ‘char*’" when using Cython 0.9.8

test.pyx:

cdef extern from "test.h":
  ctypedef struct c_Test "Test":
    char *getString() except +RuntimeError
                     ## All OK if no 'except +RuntimeError'
cdef class Test:
  cdef c_Test *thisptr
  def getString(self):
    return self.thisptr.getString()

test.h:

static const char *astring = "123" ;
class Test {
 public:
  const char *getString(void) { return astring ; }
  } ;

setup.py:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
  name = 'biosigpy',
  ext_modules = [
    Extension('test', ['test.pyx'],
      language='c++',
      extra_link_args=["-g"],
      )
    ],
  cmdclass = {'build_ext': build_ext}
  )

Change History

Changed 5 years ago by robertwb

  • milestone set to 0.9.8.2

Changed 5 years ago by robertwb

  • milestone changed from 0.9.8.2 to wishlist

This is not an error with except, so much as it is an error with const. See  http://wiki.cython.org/FAQ#head-af019db12f683abe6bc226926e8a2a92425b8e57 on how to handle this until we get full const support (which is not as trivial as one might suppose).

Changed 4 weeks ago by robertwb

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.