Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A6A72200B76 for ; Tue, 16 Aug 2016 07:09:11 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A51E6160AB8; Tue, 16 Aug 2016 05:09:11 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id ED9D7160AA7 for ; Tue, 16 Aug 2016 07:09:10 +0200 (CEST) Received: (qmail 27692 invoked by uid 500); 16 Aug 2016 05:09:10 -0000 Mailing-List: contact commits-help@arrow.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@arrow.apache.org Delivered-To: mailing list commits@arrow.apache.org Received: (qmail 27677 invoked by uid 99); 16 Aug 2016 05:09:10 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Aug 2016 05:09:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D2CE6E03C0; Tue, 16 Aug 2016 05:09:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: wesm@apache.org To: commits@arrow.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: arrow git commit: ARROW-251: Expose APIs for getting code and message of the status Date: Tue, 16 Aug 2016 05:09:09 +0000 (UTC) archived-at: Tue, 16 Aug 2016 05:09:11 -0000 Repository: arrow Updated Branches: refs/heads/master 689cd270e -> 268e108c2 ARROW-251: Expose APIs for getting code and message of the status Author: Jihoon Son Closes #114 from jihoonson/ARROW-251 and squashes the following commits: d1186bf [Jihoon Son] Fix compilation failure 4275c70 [Jihoon Son] Add tests for status 1162084 [Jihoon Son] Merge branch 'master' of https://github.com/apache/arrow into ARROW-251 a76b888 [Jihoon Son] Make code() public and add message() Project: http://git-wip-us.apache.org/repos/asf/arrow/repo Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/268e108c Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/268e108c Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/268e108c Branch: refs/heads/master Commit: 268e108c2d9101eccf2624fccf1fddf6f7f97b8b Parents: 689cd27 Author: Jihoon Son Authored: Mon Aug 15 22:08:56 2016 -0700 Committer: Wes McKinney Committed: Mon Aug 15 22:08:56 2016 -0700 ---------------------------------------------------------------------- cpp/src/arrow/util/CMakeLists.txt | 1 + cpp/src/arrow/util/status-test.cc | 38 ++++++++++++++++++++++++++++++++++ cpp/src/arrow/util/status.h | 16 ++++++++++---- 3 files changed, 51 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/arrow/blob/268e108c/cpp/src/arrow/util/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/CMakeLists.txt b/cpp/src/arrow/util/CMakeLists.txt index 4e941fb..13c0d75 100644 --- a/cpp/src/arrow/util/CMakeLists.txt +++ b/cpp/src/arrow/util/CMakeLists.txt @@ -70,3 +70,4 @@ endif() ADD_ARROW_TEST(bit-util-test) ADD_ARROW_TEST(buffer-test) ADD_ARROW_TEST(memory-pool-test) +ADD_ARROW_TEST(status-test) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/arrow/blob/268e108c/cpp/src/arrow/util/status-test.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/status-test.cc b/cpp/src/arrow/util/status-test.cc new file mode 100644 index 0000000..45e0ff3 --- /dev/null +++ b/cpp/src/arrow/util/status-test.cc @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "gtest/gtest.h" + +#include "arrow/util/status.h" +#include "arrow/test-util.h" + +namespace arrow { + +TEST(StatusTest, TestCodeAndMessage) { + Status ok = Status::OK(); + ASSERT_EQ(StatusCode::OK, ok.code()); + Status file_error = Status::IOError("file error"); + ASSERT_EQ(StatusCode::IOError, file_error.code()); + ASSERT_EQ("file error", file_error.message()); +} + +TEST(StatusTest, TestToString) { + Status file_error = Status::IOError("file error"); + ASSERT_EQ("IOError: file error", file_error.ToString()); +} + +} // namespace arrow http://git-wip-us.apache.org/repos/asf/arrow/blob/268e108c/cpp/src/arrow/util/status.h ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/status.h b/cpp/src/arrow/util/status.h index 6ba2035..d558531 100644 --- a/cpp/src/arrow/util/status.h +++ b/cpp/src/arrow/util/status.h @@ -138,6 +138,18 @@ class ARROW_EXPORT Status { // Get the POSIX code associated with this Status, or -1 if there is none. int16_t posix_code() const; + StatusCode code() const { + return ((state_ == NULL) ? StatusCode::OK : static_cast(state_[4])); + } + + std::string message() const { + uint32_t length; + memcpy(&length, state_, sizeof(length)); + std::string msg; + msg.append((state_ + 7), length); + return msg; + } + private: // OK status has a NULL state_. Otherwise, state_ is a new[] array // of the following form: @@ -147,10 +159,6 @@ class ARROW_EXPORT Status { // state_[7..] == message const char* state_; - StatusCode code() const { - return ((state_ == NULL) ? StatusCode::OK : static_cast(state_[4])); - } - Status(StatusCode code, const std::string& msg, int16_t posix_code); static const char* CopyState(const char* s); };