dsimcha wrote:
I've started looking at the best way to annotate all the pure/nothrow
functions in druntime.  A lot of druntime functionality calls functions from
the C standard library or the Windows/POSIX API.  I figure the best way to get
started is to deal w/ these first, and then worry about the higher level stuff
that's built on to of it.  These functions are obviously nothrow, since C
doesn't even support exceptions.  First of all, is there a decent automated
way to fix all of the declarations for these functions so that they're nothrow?

I did think of making all functions that are extern(C) automatically nothrow, but was concerned that it would result in a lot of bugs and broken code from ones that did throw.

Secondly, since we don't have the sources to the C libraries for which the
function prototypes are declared, we can't be absolutely sure about their
purity.  A good portion of the ones that seem like they could be pure, mostly
math stuff like sqrt, log, etc., are probably messing w/ errno, and
theoretically they could be memoizing stuff, etc.  What's a reasonable course
of action for these?  It seems like pure is most useful for mathematical
functions, , so it would really be a shame not to use it here.

Functions that modify errno cannot be pure. What needs to be done is go through the definition of each. For example, strlen, strcmp, etc. can be marked as pure. printf and strtok cannot.

The math functions can be a problem since earlier incarnations often messed with global state, but with the advent of thread safe C runtime libraries, this shouldn't be an issue anymore.

Reply via email to