Skip to content

Commit

Permalink
Use SmartPtr in exception classes.
Browse files Browse the repository at this point in the history
Summary: Use SmartPtr to hold the ArrayData in the exception classes to remove the explicit ref counting.

I had to declare throw_null_pointer_exception and throw_invalid_object_type in smart-ptr.h to break a circular dependency in the includes.

Reviewed By: @edwinsmith

Differential Revision: D1832715
  • Loading branch information
Bill Nell authored and hhvm-bot committed Feb 14, 2015
1 parent 618c3ce commit 01ef964
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
8 changes: 0 additions & 8 deletions hphp/runtime/base/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,5 @@ void throw_not_supported(const char* feature, const char* reason) {
throw ExtendedException("%s is not supported: %s", feature, reason);
}

void intrusive_ptr_add_ref(ArrayData* a) {
a->incRefCount();
}

void intrusive_ptr_release(ArrayData* a) {
decRefArr(a);
}

///////////////////////////////////////////////////////////////////////////////
}
11 changes: 2 additions & 9 deletions hphp/runtime/base/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef incl_HPHP_CPP_BASE_EXCEPTIONS_H_
#define incl_HPHP_CPP_BASE_EXCEPTIONS_H_

#include <boost/intrusive_ptr.hpp>
#include <string>
#include <atomic>
#include <utility>
Expand All @@ -26,22 +25,16 @@

#include "hphp/util/portability.h"
#include "hphp/util/exception.h"
#include "hphp/runtime/base/type-array.h"

namespace HPHP {

//////////////////////////////////////////////////////////////////////

struct Array;
struct ArrayData;
struct String;

//////////////////////////////////////////////////////////////////////

void intrusive_ptr_add_ref(ArrayData* a);
void intrusive_ptr_release(ArrayData* a);

//////////////////////////////////////////////////////////////////////

/*
* ExtendedException is the exception type for C++ exceptions that carry PHP
* stack traces, but do not represent user-visible PHP exception objects.
Expand Down Expand Up @@ -81,7 +74,7 @@ struct ExtendedException : Exception {
void computeBacktrace(bool skipFrame = false);

private:
boost::intrusive_ptr<ArrayData> m_btp;
Array m_btp;
bool m_silent{false};
};

Expand Down
4 changes: 3 additions & 1 deletion hphp/runtime/base/smart-ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#define incl_HPHP_SMART_PTR_H_

#include "hphp/runtime/base/types.h"
#include "hphp/runtime/base/exceptions.h"
#include "hphp/runtime/base/countable.h"
#include "hphp/util/portability.h"
#include "hphp/util/compilation-flags.h"
#include <algorithm>

Expand Down Expand Up @@ -372,6 +372,8 @@ typename std::enable_if<

const char* getClassNameCstr(const ResourceData* p);
const char* getClassNameCstr(const ObjectData* p);
extern void throw_null_pointer_exception() ATTRIBUTE_NORETURN;
extern void throw_invalid_object_type(const char* clsName) ATTRIBUTE_NORETURN;

// Is pointer contained in p castable to a T?
template <typename T, typename P>
Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/base/type-resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef incl_HPHP_RESOURCE_H_
#define incl_HPHP_RESOURCE_H_

#include "hphp/runtime/base/exceptions.h"
#include "hphp/runtime/base/resource-data.h"
#include "hphp/runtime/base/smart-ptr.h"
#include "hphp/runtime/base/sweepable.h"
Expand Down

0 comments on commit 01ef964

Please sign in to comment.