This is an archive of the discontinued LLVM Phabricator instance.

libc++ iostream: Clean up standard I/O stream object creation in preparation for conditionalizing streams
ClosedPublic

Authored by ed on Mar 14 2015, 9:15 AM.

Details

Summary

Interleave the code for narrow and wide character streams. This makes it more obvious that the two pieces of code are identical. Furthermore, it makes it easier to conditionally compile support for certain streams, as less #ifdef blocks are needed.

Diff Detail

Repository
rL LLVM

Event Timeline

ed updated this revision to Diff 21986.Mar 14 2015, 9:15 AM
ed retitled this revision from to libc++ iostream: Clean up standard I/O stream object creation in preparation for conditionalizing streams.
ed updated this object.
ed edited the test plan for this revision. (Show Details)
ed added reviewers: EricWF, mclow.lists, jroelofs.
ed added a subscriber: Unknown Object (MLST).
jroelofs edited edge metadata.Mar 14 2015, 10:12 AM

I'm going to have to defer to @mclow.lists on this one... I'm not sure whether the state_types have to be contiguous or not.

ed added a comment.Mar 16 2015, 9:22 AM

I'm going to have to defer to @mclow.lists on this one... I'm not sure whether the state_types have to be contiguous or not.

I just looked through include/__std_stream and it doesn't seem to be the case that they need to be contiguous.

The address of the mbstate_t is stored in the __st_ member. A reference to it gets passed on to codecvt objects. The codecvt code in src/locale.cpp passes on the addresses to wcrtomb_l() and friends. It looks like we never do any pointer arithmetic on them.

mclow.lists edited edge metadata.Mar 16 2015, 10:56 AM

How about we do this in two steps:

  1. Move the code around w/o any functionality change.

[ i.e, Interleave the code for narrow and wide character streams. This makes it more obvious that the two pieces of code are identical. ]

  1. Get rid (maybe) of the mbstates array - though I don't really see the motivation for that.
ed added a comment.Mar 16 2015, 11:10 AM
  1. Get rid (maybe) of the mbstates array - though I don't really see the motivation for that.

The reason why I removed the array and replaced it by separate mbstates is that once the change for making std::cin and std::cout optional hits the tree, the array will only be used partially. You could add some #ifdefs to reduce the size of the array and use different indexing based on whether std::cin/std::cout should be present, but that makes things even worse.

Let me split this change up even further.

ed updated this revision to Diff 22037.Mar 16 2015, 11:56 AM
ed updated this object.
ed edited edge metadata.
In D8342#141435, @ed wrote:

Let me split this change up even further.

Done!

mclow.lists accepted this revision.Mar 17 2015, 7:48 AM
mclow.lists edited edge metadata.
This revision is now accepted and ready to land.Mar 17 2015, 7:48 AM
This revision was automatically updated to reflect the committed changes.