diff --git a/ase/awk/Awk.cpp b/ase/awk/Awk.cpp index 51b6dd82..a9a59780 100644 --- a/ase/awk/Awk.cpp +++ b/ase/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp,v 1.28 2007/05/14 08:40:13 bacon Exp $ + * $Id: Awk.cpp,v 1.29 2007/05/16 06:43:32 bacon Exp $ */ #include @@ -7,6 +7,9 @@ #include #include +#include +#include + namespace ASE { @@ -155,7 +158,47 @@ namespace ASE } } - int Awk::Argument::init (run_t* run, ase_awk_val_t* v) + void* Awk::Argument::operator new (size_t n, awk_t* awk) + { + void* ptr = ase_awk_malloc (awk, ASE_SIZEOF(awk) + n); + if (ptr == ASE_NULL) return ASE_NULL; + + *(awk_t**)ptr = awk; + return (char*)ptr+ASE_SIZEOF(awk); + } + + void* Awk::Argument::operator new[] (size_t n, awk_t* awk) + { + void* ptr = ase_awk_malloc (awk, ASE_SIZEOF(awk) + n); + if (ptr == ASE_NULL) return ASE_NULL; + + *(awk_t**)ptr = awk; + return (char*)ptr+ASE_SIZEOF(awk); + } + + void Awk::Argument::operator delete (void* ptr, awk_t* awk) + { + ase_awk_free (awk, (char*)ptr-ASE_SIZEOF(awk)); + } + + void Awk::Argument::operator delete[] (void* ptr, awk_t* awk) + { + ase_awk_free (awk, (char*)ptr-ASE_SIZEOF(awk)); + } + + void Awk::Argument::operator delete (void* ptr) + { + void* p = (char*)ptr-ASE_SIZEOF(awk_t*); + ase_awk_free (*(awk_t**)p, p); + } + + void Awk::Argument::operator delete[] (void* ptr) + { + void* p = (char*)ptr-ASE_SIZEOF(awk_t*); + ase_awk_free (*(awk_t**)p, p); + } + + int Awk::Argument::init (run_t* run, val_t* v) { // this method is used internally only // and should never be called more than once @@ -266,7 +309,7 @@ namespace ASE clear (); } - ase_awk_val_t* Awk::Return::toVal () const + Awk::val_t* Awk::Return::toVal () const { switch (this->type) { @@ -537,8 +580,9 @@ namespace ASE size_t i, nargs = ase_awk_getnargs(run); - Argument* args = ASE_NULL; - try { args = new Argument [nargs]; } catch (...) {} + //Argument* args = ASE_NULL; + //try { args = new Argument [nargs]; } catch (...) {} + Argument* args = new(awk) Argument[nargs]; if (args == ASE_NULL) { // TODO: SET ERROR INFO @@ -547,7 +591,7 @@ namespace ASE for (i = 0; i < nargs; i++) { - ase_awk_val_t* v = ase_awk_getarg (run, i); + val_t* v = ase_awk_getarg (run, i); if (args[i].init (run, v) == -1) { delete[] args; @@ -568,7 +612,7 @@ namespace ASE return -1; } - ase_awk_val_t* r = ret.toVal (); + val_t* r = ret.toVal (); if (r == ASE_NULL) { // TODO: SET ERROR INFO diff --git a/ase/awk/Awk.hpp b/ase/awk/Awk.hpp index 432a0436..b285548c 100644 --- a/ase/awk/Awk.hpp +++ b/ase/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp,v 1.26 2007/05/14 08:40:13 bacon Exp $ + * $Id: Awk.hpp,v 1.27 2007/05/16 06:43:32 bacon Exp $ */ #ifndef _ASE_AWK_AWK_HPP_ @@ -23,6 +23,7 @@ namespace ASE typedef ase_long_t long_t; typedef ase_real_t real_t; + typedef ase_awk_val_t val_t; typedef ase_awk_map_t map_t; typedef ase_awk_pair_t pair_t; typedef ase_awk_extio_t extio_t; @@ -134,12 +135,24 @@ namespace ASE Argument (); ~Argument (); + // initialization + void* operator new (size_t n, awk_t* awk); + void* operator new[] (size_t n, awk_t* awk); + + // deletion when initialization fails + void operator delete (void* p, awk_t* awk); + void operator delete[] (void* p, awk_t* awk); + + // normal deletion + void operator delete (void* p); + void operator delete[] (void* p); + private: Argument (const Argument&); Argument& operator= (const Argument&); protected: - int init (run_t* run, ase_awk_val_t* v); + int init (run_t* run, val_t* v); public: long_t toInt () const; @@ -151,7 +164,7 @@ namespace ASE protected: run_t* run; - ase_awk_val_t* val; + val_t* val; ase_long_t inum; ase_real_t rnum; @@ -171,7 +184,7 @@ namespace ASE Return (run_t* run); ~Return (); - ase_awk_val_t* toVal () const; + val_t* toVal () const; public: run_t* getRun () const;