From 880bc682a9f1222e31345e5d402c712f3c7f1d99 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sun, 4 Jul 2010 16:36:52 +0000 Subject: [PATCH] Modifying String from new/delete to malloc()/free(). Also #include'ing WString.h from WProgram.h. --- build/shared/revisions.txt | 1 + hardware/arduino/cores/arduino/WProgram.h | 1 + hardware/arduino/cores/arduino/WString.cpp | 4 ++-- hardware/arduino/cores/arduino/WString.h | 12 ++++++------ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 441f609de..33b89e9de 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -2,6 +2,7 @@ ARDUINO 0019 [core / libraries] +* Added aliases for the analog input pins: A0, A1, etc. * More accurate delay() function from BenF. * Re-enabling PWM after tone() ends. diff --git a/hardware/arduino/cores/arduino/WProgram.h b/hardware/arduino/cores/arduino/WProgram.h index 39dc611ed..81a1a9b15 100755 --- a/hardware/arduino/cores/arduino/WProgram.h +++ b/hardware/arduino/cores/arduino/WProgram.h @@ -10,6 +10,7 @@ #include "wiring.h" #ifdef __cplusplus +#include "WString.h" #include "HardwareSerial.h" uint16_t makeWord(uint16_t w); diff --git a/hardware/arduino/cores/arduino/WString.cpp b/hardware/arduino/cores/arduino/WString.cpp index 667a304a7..91d4f1513 100644 --- a/hardware/arduino/cores/arduino/WString.cpp +++ b/hardware/arduino/cores/arduino/WString.cpp @@ -113,7 +113,7 @@ const String & String::operator=( const String &rhs ) if ( rhs._length > _length ) { - delete [] _buffer; + free(_buffer); getBuffer( rhs._length ); } _length = rhs._length; @@ -139,7 +139,7 @@ const String & String::operator+=( const String &other ) char *temp = _buffer; getBuffer( _length ); strcpy( _buffer, temp ); - delete [] temp; + free(temp); } strcat( _buffer, other._buffer ); return *this; diff --git a/hardware/arduino/cores/arduino/WString.h b/hardware/arduino/cores/arduino/WString.h index c93d493d3..205c1f068 100644 --- a/hardware/arduino/cores/arduino/WString.h +++ b/hardware/arduino/cores/arduino/WString.h @@ -36,7 +36,7 @@ class String explicit String( const unsigned int, const int base=10 ); explicit String( const long, const int base=10 ); explicit String( const unsigned long, const int base=10 ); - virtual ~String() { delete [] _buffer; } + ~String() { free(_buffer); } // operators const String & operator = ( const String &rhs ); @@ -50,7 +50,7 @@ class String int operator >=( const String &rhs ) const; char operator []( unsigned int index ) const; char& operator []( unsigned int index ); -// operator const char *() const { return _buffer; } + //operator const char *() const { return _buffer; } // general methods char charAt( unsigned int index ) const; @@ -84,8 +84,8 @@ class String protected: char *_buffer; // the actual char array - unsigned int _capacity; // the array length - unsigned int _length; // the String length + unsigned int _capacity; // the array length minus one (for the '\0') + unsigned int _length; // the String length (not counting the '\0') void getBuffer(unsigned int maxStrLen); void doubleBuffer( ); @@ -98,7 +98,7 @@ class String inline void String::getBuffer(unsigned int maxStrLen) { _capacity = maxStrLen; - _buffer = new char[_capacity + 1]; + _buffer = (char *) malloc(_capacity + 1); } // double the buffer size @@ -107,7 +107,7 @@ inline void String::doubleBuffer( ) char *temp = _buffer; getBuffer( ++_capacity * 2 ); strcpy( _buffer, temp ); - delete [] temp; + free(temp); } inline String operator+( String lhs, const String &rhs )