By default a cdef (or cpdef) function returning C type suppresses all exceptions, which is quite surprising to new (and old) users, and makes debugging difficult. I would propose that we make exception propagation the default.
The primary motivation to not do this would be for fear of performance regression, especially for external functions that can't possibly raise exceptions. While the the catch-all "except *" does seem to have non-trivial overhead, the "except? value" version looks indistinguishable from no exception throwing at all (in tight loops, yay branch prediction, would be interested in what other people see [1]). Does this sound like a reasonable proposal? There are still some open questions, e.g. - What value should we pick. We want something unlikely, but recognizable to external code (e.g. 0xBadBad). - What about non-numeric/pointer/reference types; are there other sentinel values we could use? - Should we default to except * in that case? Presumably these are likely to be more expensive functions anyways (making the relative cost lower). - Or could we use, essentially, reinterpret_cast to get a possible error value? This could work for PODs (including C structs) but destructors could wreck havoc here. - Should we add syntax (e.g. "except -") to manually obtain the old behavior? Or should such be done by surrounding the entire block with an try/bare except statement? This wouldn't catch argument-parsing errors. (Another crazy idea, though I'm not sold, is lifting an initial try and with block that spans the full function body to above the argument parsing--this could simply the gil syntax as well.) - Robert [1] https://gist.github.com/robertwb/0ef6bfaa3c9b2ea11ed64d1c1a0bda43 time_with_nothing 0.0322368144989 3.22368144989e-08 time_with_star 0.097442150116 9.7442150116e-08 time_with_value 0.0940091609955 9.40091609955e-08 time_with_maybe_value 0.10076379776 1.0076379776e-07 time_with_nothing 0.0767869949341 3.8393497467e-08 time_with_star 0.189253091812 9.46265459061e-08 time_with_value 0.176230192184 8.81150960922e-08 time_with_maybe_value 0.179567098618 8.97835493088e-08 time_with_nothing 0.110851049423 3.69503498077e-08 time_with_star 0.268408060074 8.9469353358e-08 time_with_value 0.254024982452 8.46749941508e-08 time_with_maybe_value 0.244876861572 8.16256205241e-08 time_with_nothing 0.138132095337 3.45330238342e-08 time_with_star 0.345059156418 8.62647891045e-08 time_with_value 0.329736948013 8.24342370033e-08 time_with_maybe_value 0.341785907745 8.54464769363e-08 time_with_nothing 0.0680961608887 6.80961608887e-10 time_with_star 0.285541057587 2.85541057587e-09 time_with_value 0.0707340240479 7.07340240479e-10 time_with_maybe_value 0.0762150287628 7.62150287628e-10 time_with_nothing 0.148243904114 7.41219520569e-10 time_with_star 0.560220956802 2.80110478401e-09 time_with_value 0.136430978775 6.82154893875e-10 time_with_maybe_value 0.143126964569 7.15634822845e-10 time_with_nothing 0.211837053299 7.06123510997e-10 time_with_star 0.812189102173 2.70729700724e-09 time_with_value 0.197682142258 6.58940474192e-10 time_with_maybe_value 0.203264951706 6.7754983902e-10 time_with_nothing 0.283420085907 7.08550214767e-10 time_with_star 1.09991884232 2.74979710579e-09 time_with_value 0.281104803085 7.02762007713e-10 time_with_maybe_value 0.288016080856 7.20040202141e-10 DONE _______________________________________________ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel