Ticket #42 (new defect)

Opened 5 months ago

Last modified 2 months ago

C++ compile error when exception part declared on function

Reported by: d.brooks@auckland.ac.nz Assigned to: somebody
Priority: minor Milestone: wishlist
Component: Code Generation Version:
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

08/18/2008 09:37:45 PM changed by robertwb

  • milestone set to 0.9.8.2.

10/28/2008 12:39:44 PM changed 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).