message: Attempted fix for Python stream capture init (OSX)
diff: @@ -60,14 +60,21 @@ PyObject* Stdstream_flush(PyObject* self, PyObject* args)
  return Py_BuildValue("");
  }
  -PyMethodDef Stdstream_methods[] =
  +// This will be reliably initialized when the module is loaded as a shared library,
  +// unlike the PyTypeObject which is sometimes initialized AFTER we attempt to register
  +// it with the Python runtime.
  +static PyTypeObject * initializedStdstreamType = nullptr;
  +
  +PyMODINIT_FUNC PyInit_streamcapture(void)
  +{
  + static PyMethodDef Stdstream_methods[] =
  {
  {"write", Stdstream_write, METH_VARARGS, "sys.stdstream.write"},
  {"flush", Stdstream_flush, METH_VARARGS, "sys.stdstream.flush"},
  {0, 0, 0, 0} // sentinel
  };
  -PyTypeObject StdstreamType =
  + static PyTypeObject StdstreamType =
  {
  PyVarObject_HEAD_INIT(0, 0)
  "streamcapture.StdstreamType", /* tp_name */
  @@ -109,14 +116,12 @@ PyTypeObject StdstreamType =
  0, /* tp_new */
  };
  -PyModuleDef streamcapturemodule =
  + static PyModuleDef streamcapturemodule =
  {
  PyModuleDef_HEAD_INIT,
  "streamcapture", 0, -1, 0,
  };
  -PyMODINIT_FUNC PyInit_streamcapture(void)
  -{
  StdstreamType.tp_new = PyType_GenericNew;
  if (PyType_Ready(&StdstreamType) < 0) {
  cerr << "type not ready" << endl;
  @@ -129,6 +134,9 @@ PyMODINIT_FUNC PyInit_streamcapture(void)
  Py_INCREF(&StdstreamType);
  PyModule_AddObject(m, "Stdstream", reinterpret_cast<PyObject*>(&StdstreamType));
  }
  +
  + initializedStdstreamType = &StdstreamType;
  +
  return m;
  }
  @@ -144,7 +152,8 @@ setStdStream(const EnterThreadToken & token,
  const std::string & streamName)
  {
  PyObject * oldStream = PySys_GetObject(streamName.c_str()); // borrowed
  - PyObject * newStream = StdstreamType.tp_new(&StdstreamType, 0, 0);
  + assert(initializedStdstreamType);
  + PyObject * newStream = initializedStdstreamType->tp_new(initializedStdstreamType, 0, 0);
  Stdstream* impl = reinterpret_cast<Stdstream*>(newStream);
  impl->write = std::move(write);
  