Commit 1a21d2dd authored by Chris Toshok's avatar Chris Toshok

add StackRoot<> and #defines for DECREF

parent 8effb5a4
...@@ -826,7 +826,7 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force) PYSTON_NOEXCEPT; ...@@ -826,7 +826,7 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force) PYSTON_NOEXCEPT;
#define Py_INCREF(op) ((void)(op)) #define Py_INCREF(op) ((void)(op))
#define Py_DECREF(op) ((void)(op)) #define Py_DECREF(op) asm volatile("" : : "X"(op))
/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear /* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
* and tp_dealloc implementatons. * and tp_dealloc implementatons.
...@@ -874,7 +874,7 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force) PYSTON_NOEXCEPT; ...@@ -874,7 +874,7 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force) PYSTON_NOEXCEPT;
/* Macros to use in case the object pointer may be NULL: */ /* Macros to use in case the object pointer may be NULL: */
// Pyston change: made these noops as well // Pyston change: made these noops as well
#define Py_XINCREF(op) ((void)(op)) #define Py_XINCREF(op) ((void)(op))
#define Py_XDECREF(op) ((void)(op)) #define Py_XDECREF(op) asm volatile("" : : "X"(op))
/* /*
These are provided as conveniences to Python runtime embedders, so that These are provided as conveniences to Python runtime embedders, so that
......
// Copyright (c) 2014-2015 Dropbox, Inc.
//
// Licensed 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.
#ifndef PYSTON_GC_ROOTS_H
#define PYSTON_GC_ROOTS_H
#include "core/common.h"
#include "core/threading.h"
namespace pyston {
#define GC_KEEP_ALIVE(t) asm volatile("" : : "X"(t))
template <class T> class StackRoot {
public:
StackRoot(T* t) : t(t) {}
StackRoot(const StackRoot& other) : t(other.t) {}
~StackRoot() { GC_KEEP_ALIVE(t); }
T& operator*() const { return *t; }
T* operator->() const { return t; }
operator T*() const { return t; }
private:
T* t;
};
class Box;
class BoxedString;
typedef StackRoot<Box> RootedBox;
typedef StackRoot<BoxedString> RootedBoxedString;
//
// the above types can be used whenever we need to explicitly root a Box subclass within some lexical scope.
//
// {
// RootedBoxedString sub(new BoxedString("hello world"));
// for (auto c : sub->s) {
// doSomethingThatCouldTriggerACollection();
// }
// // sub will be rooted conservatively until here
// }
//
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment