
There are two calls to load_next() in import_module_ex(). The segfault is occuring during the second call.
The code is somewhat pathological in that the callee, load_next(), is modifying the caller's /parameters/ by changing the contents of name.
For some reason, the compiler emits code which makes a copy of import_module_ex()'s parameters in the stack frame. When load_next() is called, the reference &name is the location in the parameter area of the frame, but when name is tested in the while loop, the copy in the local area of the frame is used. Since this has not been modified by load_next(), the fact that name has been set to 0x00 is missed. load_next() gets called erroneously and passes a null pointer to strchr.
I tried a volatile declaration, but no joy. Adding a proper local, mod_name, resolved the problem.
Wow. Thanks for the analysis. But this is clearly a compiler bug. Where do we report that? And why would it be unique to OpenBSD?
In the mean time, Kurt, please check in your fix -- it can't hurt, and we might as well avoid the pain for the next person who wants to build a debugging Python. The fix could use a comment referring to a compiler bug, to keep the next maintainer from unfixing it. :-)
--Guido van Rossum (home page: http://www.python.org/~guido/)