Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

unify reference counting

  • Loading branch information...
commit 788ce11f1bcf690fb0e5c745327e2f3e566ed630 1 parent 176fec3
@NotFound authored
View
8 winxedxx.winxed
@@ -1690,15 +1690,7 @@ function emit_declare_local(out, funst, string dataname)
out.print("public:\n");
out.print(name + "(" + dataname + " & outer) : "+ DATA + "(outer)\n" );
out.print("{\n");
- out.print(DATA + ".incref();\n");
out.print("}\n");
- out.print("~" + name + "()\n" );
- out.print("{\n");
- out.print(DATA + ".decref();\n");
- out.print("}\n");
- out.print("void incref() { " + DATA + ".incref(); }\n");
- out.print("void decref() { " + DATA + ".decref(); }\n");
-
out.print("\nWxxObjectPtr operator() (const WxxObjectArray &);\n" );
out.print("\n};\n");
View
27 winxedxx_classes.cxx
@@ -19,6 +19,33 @@ namespace WinxedXX
//*************************************************************
+WxxRefcounted::WxxRefcounted() : refcount(0)
+{
+}
+
+WxxRefcounted::WxxRefcounted(size_t initial) : refcount(initial)
+{
+}
+
+WxxRefcounted::~WxxRefcounted()
+{
+}
+
+void WxxRefcounted::incref()
+{
+ ++refcount;
+}
+
+void WxxRefcounted::decref()
+{
+ if (refcount <= 0)
+ throw "Byebye";
+ if (--refcount == 0)
+ delete this;
+}
+
+//*************************************************************
+
std::string WxxNull::class_name() const
{
return "Null";
View
16 winxedxx_object.h
@@ -7,7 +7,7 @@
namespace WinxedXX
{
-class WxxObject
+class WxxObject : public WxxRefcounted
{
public:
virtual int is_null() const = 0;
@@ -41,20 +41,6 @@ class WxxObject
virtual WxxObjectPtr call_method(const std::string &methname, WxxObjectArray &args) = 0;
virtual void print() = 0;
virtual void print(WxxObjectPtr obj) = 0;
- void incref() { ++numrefs; }
- void decref()
- {
- --numrefs;
- if (numrefs <= 0)
- delete this;
- }
-protected:
- int numrefs;
- WxxObject()
- {
- numrefs = 0;
- }
- virtual ~WxxObject() { }
};
WxxObjectPtr wxx_getstdin();
View
31 winxedxx_types.h
@@ -10,27 +10,30 @@
namespace WinxedXX
{
+class WxxRefcounted
+{
+protected:
+ WxxRefcounted();
+ WxxRefcounted(size_t initial);
+ virtual ~WxxRefcounted();
+public:
+ void incref();
+ void decref();
+private:
+ size_t refcount;
+};
+
class WxxObject;
class WxxObjectArray;
class WxxLibrary;
class WxxInnerFunction;
-class WxxFunctionVars
+class WxxFunctionVars : public WxxRefcounted
{
protected:
- WxxFunctionVars() :
- refcount(1)
- {
- }
-public:
- void incref() { ++refcount; }
- void decref()
+ WxxFunctionVars() : WxxRefcounted(1)
{
- if (--refcount == 0)
- delete this;
}
-private:
- size_t refcount;
};
class WxxDataHolder
@@ -107,12 +110,10 @@ class WxxObjectPtr
extern WxxObjectPtr winxedxxnull;
-class WxxInnerFunction
+class WxxInnerFunction : public WxxRefcounted
{
public:
virtual WxxObjectPtr operator()(const WxxObjectArray &args) = 0;
- virtual void incref() = 0;
- virtual void decref() = 0;
};
Please sign in to comment.
Something went wrong with that request. Please try again.