This is apparently because sys.modules contains Unicode (str) keys, while 'parentname' is an old-style string. Attached patch seems to fix it, but I have no idea if it is correct in principle
Why are you using PyUnicode_AsUTF32String(parentname)? PyUnicode_AsString() is the correct method (although it's not yet in the docs). The rest looks fine. PyModule_GetName() returns a char* from PyUnicode_AsString(). Fixed in r58838.
Thank you for the commit. I just had a problem with my package, and since I was not sure if it was a bug in Py3k or the package, I went to debugging the former and found this. I just didn't know how to work with Unicode strings properly.