[llvm-commits] [PATCH] Replace all uses of std::string* for errors with error_code in Support/MemoryBuffer.

Chris Lattner clattner at apple.com
Thu Dec 9 00:24:06 PST 2010


On Dec 7, 2010, at 1:23 PM, Michael Spencer wrote:

> The two attached patches replace all uses of std::string* for error
> handling with error_code in Support/MemoryBuffer and updates clients
> to use them.

Sounds good to me, please apply with some minor changes:

+++ b/include/llvm/Support/MemoryBuffer.h
@@ -16,7 +16,7 @@
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/DataTypes.h"
-#include <string>
+#include "llvm/Support/system_error.h"

Please extern system_error instead of #including it.


+++ b/include/llvm/Support/system_error.h
@@ -668,6 +668,11 @@ public:
 const error_category& generic_category();
 const error_category& system_category();
 
+/// Get the error_category used for errno values from POSIX functions. This is
+/// the same as the system_category on POISIX systems, but is the same as the
+/// generic_category on Windows.
+const error_category& posix_category();

Space before the &, not after.


Aside from minor stuff, one thing strikes me as odd: the FS interfaces all return the errorcode as the result value, and the result as an "out" parameter.  I think this is a good pattern, and we should encourage it for clients as well.  What do you think about:

  ...
  static error_code getSTDIN(std::auto_ptr<MemoryBuffer> &Result);
  ...

Use of auto_ptr also self-documents that the client owns the result pointer.  What do you think?

-Chris






More information about the llvm-commits mailing list