[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/tu_file.cpp libbase/tu_...
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/tu_file.cpp libbase/tu_... |
Date: |
Fri, 28 Mar 2008 10:10:34 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Benjamin Wolsey <bwy> 08/03/28 10:10:34
Modified files:
. : ChangeLog
libbase : tu_file.cpp tu_file.h
Removed files:
libbase : config.cpp membuf.h membuf.cpp
Log message:
* libbase/tu_file.{cpp,h}: remove everything that isn't
currently
used, including all membuf code.
* libbase/membuf.{cpp,h}: unused. Dropped.
* libbase/config.cpp: (lua bindings) dropped.
Perhaps it's time to look at tu_file properly. For now I've dropped
all methods and constructors that are (or appear to be) unused to make
it clearer what's needed.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6049&r2=1.6050
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/tu_file.cpp?cvsroot=gnash&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/tu_file.h?cvsroot=gnash&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/config.cpp?cvsroot=gnash&r1=1.4&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/membuf.h?cvsroot=gnash&r1=1.5&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/membuf.cpp?cvsroot=gnash&r1=1.5&r2=0
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6049
retrieving revision 1.6050
diff -u -b -r1.6049 -r1.6050
--- ChangeLog 27 Mar 2008 17:55:43 -0000 1.6049
+++ ChangeLog 28 Mar 2008 10:10:33 -0000 1.6050
@@ -1,3 +1,10 @@
+2008-03-28 Benjamin Wolsey <address@hidden>
+
+ * libbase/tu_file.{cpp,h}: remove everything that isn't currently
+ used, including all membuf code.
+ * libbase/membuf.{cpp,h}: unused. Dropped.
+ * libbase/config.cpp: (lua bindings) dropped.
+
2008-03-27 Sandro Santilli <address@hidden>
* testsuite/actionscript.all/Inheritance.as: use 'delete x.y'
Index: libbase/tu_file.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/tu_file.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- libbase/tu_file.cpp 22 Mar 2008 14:12:13 -0000 1.25
+++ libbase/tu_file.cpp 28 Mar 2008 10:10:33 -0000 1.26
@@ -8,17 +8,12 @@
#include "tu_file.h"
#include "utility.h"
-#include "membuf.h"
#include "log.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
-#ifdef __sgi
- __SGI_LIBC_USING_FROM_STD(va_list)
-#endif
-
//
// tu_file functions using FILE
//
@@ -162,209 +157,7 @@
}
-//
-// tu_file functions using a readable/writable memory buffer
-//
-
-class filebuf
-{
-public:
-
- membuf m_;
- int m_position;
-
- filebuf()
- {
- m_position = 0;
- m_read_only = false;
- }
-
- filebuf(int size, void* data)
- :
- m_(membuf::READ_ONLY, data, size),
- m_position(0),
- m_read_only(true)
- {
- }
-
- ~filebuf()
- {
- }
-
- bool resize(int new_size)
- // Return false if we couldn't resize.
- {
- if (m_read_only) {
- return false;
- }
-
- m_.resize(new_size);
-
- // Hm, does this make sense? We're truncating the file, so
clamping the cursor.
- // Alternative would be to disallow resize, but that doesn't seem
good either.
- if (m_position > m_.size()) {
- m_position = m_.size();
- }
-
- return true;
- }
-
- bool is_valid()
- {
- return
- m_position >= 0
- && m_position <= m_.size();
- }
-
- unsigned char* get_cursor()
- {
- return ((unsigned char*) m_.data()) + m_position;
- }
-
-private:
- bool m_read_only;
-};
-
-
-static int
-mem_read_func(void* dst, int bytes, void* appdata)
-// Return the number of bytes actually read. EOF or an error would
-// cause that to not be equal to "bytes".
-{
- assert(appdata);
- assert(dst);
-
- filebuf* buf = (filebuf*) appdata;
- assert(buf->is_valid());
-
- int bytes_to_read = imin(bytes, buf->m_.size() - buf->m_position);
- if (bytes_to_read) {
- memcpy(dst, buf->get_cursor(), bytes_to_read);
- }
- buf->m_position += bytes_to_read;
-
- return bytes_to_read;
-}
-
-
-static int mem_write_func(const void* src, int bytes, void* appdata)
-// Return the number of bytes actually written.
-{
- assert(appdata);
- assert(src);
-
- filebuf* buf = (filebuf*) appdata;
- assert(buf->is_valid());
-
- // Expand buffer if necessary.
- int bytes_to_expand = imax(0, buf->m_position + bytes -
buf->m_.size());
- if (bytes_to_expand) {
- if (buf->resize(buf->m_.size() + bytes_to_expand) == false) {
- // Couldn't expand!
- return 0;
- }
- }
-
- memcpy(buf->get_cursor(), src, bytes);
- buf->m_position += bytes;
-
- return bytes;
-}
-
-static int
-mem_seek_func(int pos, void *appdata)
-// Return 0 on success, or TU_FILE_SEEK_ERROR on failure.
-{
- assert(appdata);
- assert(pos >= 0);
-
- filebuf* buf = (filebuf*) appdata;
- assert(buf->is_valid());
-
- if (pos < 0) {
- buf->m_position = 0;
- return TU_FILE_SEEK_ERROR;
- }
-
- if (pos > buf->m_.size()) {
- buf->m_position = buf->m_.size();
- return TU_FILE_SEEK_ERROR;
- }
-
- buf->m_position = pos;
- return 0;
-}
-
-static int
-mem_seek_to_end_func(void* appdata)
-// Return 0 on success, TU_FILE_SEEK_ERROR on failure.
-{
- assert(appdata);
-
- filebuf* buf = (filebuf*) appdata;
- assert(buf->is_valid());
-
- buf->m_position = buf->m_.size();
- return 0;
-}
-
-static int
-mem_tell_func(void* appdata)
-// Return the file position, or -1 on failure.
-{
- assert(appdata);
-
- filebuf* buf = (filebuf*) appdata;
- assert(buf->is_valid());
-
- return buf->m_position;
-}
-
-static bool
-mem_get_eof_func(void* appdata)
-// Return true if we're positioned at the end of the buffer.
-{
- assert(appdata);
-
- filebuf* buf = (filebuf*) appdata;
- assert(buf->is_valid());
-
- return buf->m_position >= buf->m_.size();
-}
-
-static int
-mem_get_err_func(void* appdata)
-// Return true if we're positioned at the end of the buffer.
-{
- filebuf* buf = (filebuf*) appdata;
- return buf->is_valid();
-}
-
-static long
-mem_get_stream_size(void* appdata)
-// Return the file size, or -1 on failure.
-{
- assert(appdata);
-
- filebuf* buf = (filebuf*) appdata;
- assert(buf->is_valid());
-
- return buf->m_.size();
-}
-
-static int mem_close_func(void* appdata)
-// Return 0 on success, or TU_FILE_CLOSE_ERROR on failure.
-{
- assert(appdata);
-
- filebuf* buf = (filebuf*) appdata;
- assert(buf->is_valid());
-
- delete buf;
-
- return 0;
-}
-}
+} // end namespace gnash
//
// generic functionality
@@ -387,7 +180,7 @@
m_close = cf;
}
-// Create a file from a standard file pointer.
+//// Create a file from a standard file pointer.
tu_file::tu_file(FILE* fp, bool autoclose=false)
{
//GNASH_REPORT_FUNCTION;
@@ -422,39 +215,6 @@
m_close = std_close_func;
}
-tu_file::tu_file(memory_buffer_enum /* m */)
-// Create a read/write memory buffer.
-{
- m_data = new filebuf;
-
- m_read = mem_read_func;
- m_write = mem_write_func;
- m_seek = mem_seek_func;
- m_seek_to_end = mem_seek_to_end_func;
- m_tell = mem_tell_func;
- m_get_eof = mem_get_eof_func;
- m_get_err = mem_get_err_func;
- m_get_stream_size = mem_get_stream_size;
- m_close = mem_close_func;
-}
-
-
-tu_file::tu_file(memory_buffer_enum /* m */, int size, void* data)
-// Create a read-only memory buffer, using the given data.
-{
- m_data = new filebuf(size, data);
-
- m_read = mem_read_func;
- m_write = mem_write_func;
- m_seek = mem_seek_func;
- m_seek_to_end = mem_seek_to_end_func;
- m_tell = mem_tell_func;
- m_get_eof = mem_get_eof_func;
- m_get_err = mem_get_err_func;
- m_get_stream_size = mem_get_stream_size;
- m_close = mem_close_func;
-}
-
tu_file::~tu_file()
// Close this file when destroyed.
{
@@ -493,28 +253,6 @@
}
-void
-tu_file::copy_to(membuf* dst)
-// Copy remaining contents of *this into *dst.
-{
- static const int BUFSIZE = 4096;
-
- while (get_eof() == false) {
- // Make room at the end of dst.
- dst->resize(dst->size() + BUFSIZE);
- int bytes_read = read_bytes(((char*) dst->data()) + dst->size() -
BUFSIZE, BUFSIZE);
- if (bytes_read < BUFSIZE) {
- // Didn't use everything we allocated; trim the unused bytes.
- dst->resize(dst->size() - (BUFSIZE - bytes_read));
- }
-
- if (get_error()) {
- break;
- }
- }
-}
-
-
int
tu_file::copy_bytes(tu_file* src, int byte_count)
// Copy a fixed number of bytes from *src into *this. Return the
@@ -575,33 +313,6 @@
return -1;
}
-
-
-#include <cstdarg>
-#include <cstring>
-
-#ifdef _WIN32
-#define vsnprintf _vsnprintf
-// gettext 0.17 redefines printf in libintl.h which confuses cpp 3.x
-#undef printf
-#endif // _WIN32
-
-int tu_file::printf(const char* fmt, ...)
-// Use printf-like semantics to send output to this stream.
-{
- // Workspace for vsnprintf formatting.
- static const int BUFFER_SIZE = 1000;
- char buffer[BUFFER_SIZE];
-
- va_list ap;
- va_start(ap, fmt);
- vsnprintf(buffer, BUFFER_SIZE, fmt, ap);
- va_end(ap);
-
- return write_bytes(buffer, strlen(buffer));
-}
-
-
// Local Variables:
// mode: C++
// indent-tabs-mode: t
Index: libbase/tu_file.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/tu_file.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- libbase/tu_file.h 27 Mar 2008 16:12:36 -0000 1.21
+++ libbase/tu_file.h 28 Mar 2008 10:10:33 -0000 1.22
@@ -14,8 +14,7 @@
#include <cstdio>
-class membuf;
-struct SDL_RWops;
+//class membuf;
enum
{
@@ -61,21 +60,10 @@
// Make a file from an ordinary FILE*.
tu_file(FILE* fp, bool autoclose);
- // Optional: if you're using SDL, this is a constructor to create
- // a tu_file from an SDL_RWops* stream.
- tu_file(SDL_RWops* sdl_stream, bool autoclose);
-
// Open a file using ordinary fopen(). Automatically closes the
// file when we are destroyed.
tu_file(const char* name, const char* mode);
- // Make a memory-buffer file for read/write.
- enum memory_buffer_enum { memory_buffer };
- tu_file(memory_buffer_enum m);
-
- // A read-only memory-buffer with predefined data.
- tu_file(memory_buffer_enum m, int size, void* data);
-
~tu_file();
/// Copy remaining contents of *in into *this.
@@ -85,13 +73,6 @@
///
void copy_from(tu_file* in);
- /// Copy remaining contents of *this into *out.
- //
- /// TODO: define what happens when the stream
- /// is in error condition, see get_error().
- ///
- void copy_to(membuf* out);
-
/// Copy a fixed number of bytes from *in to *this.
//
/// Returns number of bytes copied.
@@ -268,9 +249,6 @@
/// \brief Get the size of the stream
int get_size() { return m_get_stream_size(m_data); }
- // \brief printf-style convenience function.
- int printf(const char* fmt, ...);
-
// \brief UNSAFE back door, for testing only.
void* get_app_data_DEBUG() { return m_data; }
Index: libbase/config.cpp
===================================================================
RCS file: libbase/config.cpp
diff -N libbase/config.cpp
--- libbase/config.cpp 21 Jan 2008 20:55:44 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,449 +0,0 @@
-// config.cpp -- by Thatcher Ulrich <address@hidden> 22 July 2001
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// Configuration glue. C++ interface to Lua scripting library.
-
-// @@ move/finish this later...
-#if 0
-
-
-#include "gnashconfig.h"
-extern "C" {
-#include <lualib.h>
-}
-#include "utility.h"
-
-
-namespace config {
-
-
-static const int LUA_STACK_SIZE = 2048;
-
-
-static bool s_open = false;
-
-lua_State* L = NULL;
-int g_cfloat_tag = 0;
-
-
-static int cfloat_get( lua_State* L )
-// Lua CFunction which returns the value of the cfloat passed in on
-// the top of the Lua stack. Attach this to the "getglobal" event for
-// cfloats.
-{
- // arg 1: varname
- // arg 2: raw var value (in this case the cfloat*)
-
- cfloat* cf = static_cast<cfloat*>( lua_touserdata( L, 2 ) );
- lua_pushnumber( L, float( *cf ) );
-
- return 1;
-}
-
-
-static int cfloat_set( lua_State* L )
-// Lua CFunction which sets the value of the given cfloat to the given lua
-// number.
-{
- // arg 1: varname
- // arg 2: previous var value (in this case the cfloat*)
- // arg 3: new var value
-
- cfloat* cf = static_cast<cfloat*>( lua_touserdata( L, 2 ) );
- *cf = float(lua_tonumber( L, 3 ));
-
- return 0;
-}
-
-
-void open()
-// Initialize the config subsystem. ...
-{
- if ( s_open == true ) return;
-
- //
- // Initialize Lua.
- //
- L = lua_open( LUA_STACK_SIZE );
-
- // Init the standard Lua libs.
- lua_baselibopen( L );
- lua_iolibopen( L );
- lua_strlibopen( L );
- lua_mathlibopen( L );
-
- //
- // Attach the cfloat hooks
- //
-
- g_cfloat_tag = lua_newtag( config::L );
-
- lua_pushcfunction( config::L, cfloat_get );
- lua_settagmethod( config::L, config::g_cfloat_tag, "getglobal" );
// xxx is "getglobal" right?
-
- lua_pushcfunction( config::L, cfloat_set );
- lua_settagmethod( config::L, config::g_cfloat_tag, "setglobal" );
// xxx is "setglobal" right?
-
- // set tag methods for add, sub, mul, div, pow, unm, lt
-
- // gettable{ min, max, default, comment }
- // settable{ min, max, default, comment }
-
- s_open = true;
-}
-
-
-void close()
-// Close the config subsystem.
-{
- // Nothing really to do here.
-}
-
-
-}; // end namespace config
-
-
-
-//
-// cvar
-//
-
-
-void cvar::init( const char* name )
-// Initializes a chain of references to Lua strings, for looking up
-// the value of the specified name.
-//
-// The name can contain embedded '.' separators, to refer to values
-// within nested tables. For example, a name of
-// "player.spaceship.health" would refer to the "health" member of the
-// "player.spaceship" table (where the "player.spaceship" table is
-// found by looking up the "spaceship" member of the "player" table).
-{
- config::open();
-
- // Count the number of keys in the name (keys are separated by '.'
- // chars).
- m_lua_key_count = 1;
- const char* p = name;
- while (*p) {
- if (*p == '.') {
- m_lua_key_count++;
- }
- p++;
- }
-
- // Allocate array for references.
- m_lua_key_reference = new int[m_lua_key_count];
-
- // Now initialize the keys.
- const char* varname = name;
-
- int key_index = 0;
- p = name;
- while (*p) {
- if (*p == '.') {
- if (varname == p) {
- // null string for a key.
- // warning("something or other");
- abort(); // TODO: recover somehow.
- }
-
- // Reference the name of the table.
- lua_pushlstring(config::L, varname, p - varname);
- m_lua_key_reference[key_index] = lua_ref(config::L, 1);
-
- key_index++;
- varname = p + 1;
- }
- p++;
- }
-
- // Get a reference to the last key name.
- assert(varname != p); // else...
- lua_pushlstring(config::L, varname, p - varname);
- m_lua_key_reference[key_index] = lua_ref(config::L, 1);
-}
-
-
-void cvar::push_table_and_key() const
-// Traverse our key names, and push the table and keyname of our value
-// onto the Lua stack.
-//
-// Creates empty tables if necessary to fill in missing links in the
-// chain.
-{
- lua_getglobals(config::L); // Start with the global table.
-
- // Chain through additional tables.
- int i;
- for (i = 0; i < m_lua_key_count - 1; i++) {
- lua_getref(config::L, m_lua_key_reference[i]);
- lua_gettable(config::L, -2);
-
- if (lua_isnil(config::L, -1)) {
- // Tablename is undefined, so create a new empty table
for it.
- lua_pop(config::L, 1); // pop the nil.
- lua_getref(config::L, m_lua_key_reference[i]);
- lua_newtable(config::L);
- lua_settable(config::L, -3);
-
- // Get the newly created table and put it on the top
- // of stack.
- lua_getref(config::L, m_lua_key_reference[i]);
- lua_gettable(config::L, -2);
- }
-
- lua_remove(config::L, -2); // previous table that we just
chained from
- }
-
- // push the final key, on top of the table we just pushed.
- lua_getref(config::L, m_lua_key_reference[i]);
-}
-
-
-cvar::cvar( const char* name )
-// Constructor; leaves existing value, if any (otherwise it's 'nil').
-{
- init(name);
-}
-
-
-cvar::cvar( const char* name, const cvalue& val )
-// Constructor; initializes to given Lua value.
-{
- init(name);
- *this = val; // invoke operator=(const cvalue& val)
-}
-
-
-cvar::cvar( const char* name, const char* val )
-// Constructor; initializes to given string value.
-{
- init(name);
- *this = val; // invoke operator=(const char*)
-}
-
-
-cvar::cvar( const char* name, float val )
-// Constructor; initializes to given float value.
-{
- init(name);
- *this = val; // invoke operator=(float f)
-}
-
-
-cvar::~cvar()
-// Destructor; make sure our references are released.
-{
- // drop lua references, so table & name can be gc'd if not
- // referenced elsewhere.
-
- for (int i = 0; i < m_lua_key_count; i++) {
- lua_unref(config::L, m_lua_key_reference[i]);
- }
-
- m_lua_key_count = 0;
- m_lua_key_reference = NULL;
-}
-
-
-#if 0
-const char* cvar::get_name() const
-// Return our name. The char[] storage is valid at least as long
-// as this variable is alive.
-{
- lua_getref( config::L, m_lua_name_reference );
- return lua_tostring( config::L, -1 );
-}
-#endif // 0
-
-
-cvar::operator float() const
-// Convert the variable to a float and return it.
-{
- push_table_and_key();
- lua_gettable( config::L, -2 ); // get the value of our variable from
the table.
- float f = float(lua_tonumber( config::L, -1 ));
- lua_pop( config::L, 2 ); // pop table & the number result.
-
- return f;
-}
-
-
-void cvar::operator=( float f )
-// Assign a float to this lua variable.
-{
- push_table_and_key();
- lua_pushnumber( config::L, f );
- lua_settable( config::L, -3 );
- lua_pop( config::L, 1 ); // pop the table.
-}
-
-
-cvar::operator const char*() const
-// Convert to a string.
-//
-// xxx there are garbage-collection issues here! Returned string
-// has no valid reference once stack is cleared!
-// Possible fixes:
-// - return some kind of proxy object that holds a locked Lua ref
-// - return a C++ "string" value; i.e. make a copy
-// - hold a locked reference in this instance; drop it on next call to this
conversion operator (blech).
-{
- push_table_and_key();
- lua_gettable( config::L, -2 ); // get the value of our variable from
the table.
- const char* c = lua_tostring( config::L, -1 );
- // TODO: grab a locked reference to the string! Or copy it!
- lua_pop( config::L, 2 ); // discard table & the string result.
-
- return c;
-}
-
-
-void cvar::operator=( const cvalue& val )
-// Assign a Lua value to this lua global variable.
-{
- push_table_and_key();
- val.lua_push();
- lua_settable( config::L, -3 );
- lua_pop( config::L, 1 ); // pop the table.
-}
-
-
-void cvar::operator=( const char* s )
-// Assign a string to this lua variable.
-{
- push_table_and_key();
- lua_pushstring( config::L, s );
- lua_settable( config::L, -3 );
- lua_pop( config::L, 1 ); // pop the table.
-}
-
-
-cvar::operator cvalue() const
-// Return a reference to our value.
-{
- push_table_and_key();
- cvalue c = cvalue::lua_stacktop_reference();
- lua_pop( config::L, 1 ); // pop the table.
-
- return c;
-}
-
-
-// void operator=( const cvar c );
-
-
-
-//
-// cvalue
-//
-
-
-cvalue::cvalue( const char* lua_constructor )
-// Evaluates the given code and takes a reference to the result.
-{
- config::open();
-
- lua_dostring( config::L, lua_constructor ); // @@ could check for
error return codes, presence of return value, etc.
- m_lua_ref = lua_ref( config::L, 1 );
-}
-
-
-cvalue::cvalue( const cvalue& c )
-{
- lua_getref( config::L, c.m_lua_ref );
- m_lua_ref = lua_ref( config::L, 1 );
-}
-
-
-cvalue::cvalue()
-// Creates an reference to nothing. Use this only in special
-// circumstances; i.e. when you're about to set m_lua_ref manually.
-{
- config::open();
- m_lua_ref = LUA_NOREF;
-}
-
-
-cvalue cvalue::lua_stacktop_reference()
-// Factory function; pops the value off the top of the Lua stack, and
-// return a cvalue that references the popped value.
-{
- cvalue c;
- c.m_lua_ref = lua_ref( config::L, 1 );
- return c;
-}
-
-
-cvalue::~cvalue()
-// Drop our Lua reference, to allow our value to be gc'd.
-{
- lua_unref( config::L, m_lua_ref );
- m_lua_ref = LUA_NOREF;
-}
-
-
-void cvalue::lua_push() const
-// Push our value onto the top of the Lua stack.
-{
- assert( m_lua_ref != LUA_NOREF );
- lua_getref( config::L, m_lua_ref );
-}
-
-
-void cvalue::operator=( const char* str )
-// Transfer our reference to the given string.
-{
- lua_unref( config::L, m_lua_ref );
- lua_pushstring( config::L, str );
- m_lua_ref = lua_ref( config::L, 1 );
-}
-
-
-void cvalue::operator=( const cvalue& c )
-// Reference the thing that c references.
-{
- lua_unref( config::L, m_lua_ref );
- lua_getref( config::L, c.m_lua_ref );
- m_lua_ref = lua_ref( config::L, 1 );
-}
-
-
-cvalue::operator float() const
-// Converts this Lua value to a number, and returns it.
-{
- lua_getref( config::L, m_lua_ref );
- float f = float(lua_tonumber( config::L, -1 ));
- lua_pop( config::L, 1 );
- return f;
-}
-
-
-cvalue::operator const char*() const
-// Converts this Lua value to a string, and returns it.
-{
- lua_getref( config::L, m_lua_ref );
- const char* str = lua_tostring( config::L, -1 );
- lua_pop( config::L, 1 ); // @@ I'm pretty sure this imperils the
string, if we just had to do a tostring() conversion! Look into this, and/or
make a copy of the string.
- return str;
-}
-
-
-cvalue cvalue::get( const char* index )
-// Does a table lookup. *this should be a Lua table, and index is its
-// key.
-{
- lua_getref( config::L, m_lua_ref );
- lua_pushstring( config::L, index );
- lua_gettable( config::L, -2 );
- cvalue c = cvalue::lua_stacktop_reference(); // references the value
on the top of the Lua stack.
- lua_pop( config::L, 1 );
-
- return c;
-}
-
-
-#endif // 0
Index: libbase/membuf.h
===================================================================
RCS file: libbase/membuf.h
diff -N libbase/membuf.h
--- libbase/membuf.h 27 Mar 2008 16:12:35 -0000 1.5
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,61 +0,0 @@
-// membuf.h -- Thatcher Ulrich 2005
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// A simple memory buffer. Similar to a string, but can hold null
-// characters.
-
-
-#ifndef MEMBUF_H
-#define MEMBUF_H
-
-#include "utility.h"
-#include <string>
-
-class membuf
-{
-public:
- membuf();
- membuf(const void* data, int size);
- membuf(const membuf& buf);
- membuf(const std::string& str);
- ~membuf();
-
- // Construct a read-only membuf that points at the given data,
- // instead of copying it.
- enum read_only_enum { READ_ONLY };
- membuf(read_only_enum e, const void* data, int size);
-
- int size() const { return m_size; }
- const void* data() const { return m_data; }
- void* data() { assert(!m_read_only); return m_data; }
-
- // Don't call these mutators on read-only membufs.
-
- // Return false if we couldn't resize (i.e. realloc failure).
- bool resize(int new_size);
-
- // Return false on realloc failure.
- bool append(const void* data, int size);
- bool append(const membuf& buf);
- // We do not append the terminating '\0'.
- bool append(const std::string& str);
-
-private:
- int m_size;
- int m_capacity;
- void* m_data;
- bool m_read_only;
-};
-
-
-#endif // MEMBUF_H
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8
-// tab-width: 8
-// indent-tabs-mode: t
-// End:
Index: libbase/membuf.cpp
===================================================================
RCS file: libbase/membuf.cpp
diff -N libbase/membuf.cpp
--- libbase/membuf.cpp 15 Apr 2007 10:52:09 -0000 1.5
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,166 +0,0 @@
-// membuf.cpp -- Ignacio Castaño, Thatcher Ulrich <address@hidden> 2003
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// A simple memory buffer. Similar to a string, but can hold null
-// characters.
-
-
-#include "membuf.h"
-#include "tu_file.h"
-#include "container.h"
-
-
-// Allocate in increments of BLOCKSIZE.
-static const int BLOCKSIZE = (1 << 12);
-
-
-static int capacity(int size)
-// Compute the buffer capacity corresponding to the given size.
-// Basically round up to the next block size.
-// Always return non-zero.
-{
- // BLOCKSIZE must be a power of two.
- compiler_assert((BLOCKSIZE & (BLOCKSIZE - 1)) == 0);
-
- if (size == 0) {
- // Special case, always allocate.
- return BLOCKSIZE;
- }
-
- return (size + BLOCKSIZE - 1) & ~(BLOCKSIZE - 1);
-}
-
-
-membuf::membuf()
- :
- m_size(0),
- m_capacity(0),
- m_data(0),
- m_read_only(false)
-{
-}
-
-
-membuf::membuf(const void* data, int size)
- :
- m_size(0),
- m_capacity(0),
- m_data(0),
- m_read_only(false)
-{
- append(data, size);
-}
-
-
-membuf::membuf(const membuf& buf)
- :
- m_size(0),
- m_capacity(0),
- m_data(0),
- m_read_only(false)
-{
- append(buf);
-}
-
-
-membuf::membuf(const std::string& str)
- :
- m_size(0),
- m_capacity(0),
- m_data(0),
- m_read_only(false)
-{
- append(str);
-}
-
-
-// Special read-only constructor.
-membuf::membuf(read_only_enum /* e */, const void* data, int size)
- :
- m_size(size),
- m_capacity(0),
- m_data(const_cast<void*>(data)),
- m_read_only(true)
-{
-}
-
-
-membuf::~membuf()
-{
- if (!m_read_only) {
- tu_free(m_data, m_capacity);
- }
- m_capacity = 0;
- m_data = NULL;
-}
-
-
-bool membuf::resize(int new_size)
-{
- assert(!m_read_only);
-
- if (new_size == m_size) {
- return true;
- }
-
- int new_capacity = capacity(new_size);
-
- if (m_data == NULL) {
- m_data = tu_malloc(new_capacity);
- } else {
- if (new_capacity != m_capacity) {
- m_data = tu_realloc(m_data, new_capacity, m_capacity);
- }
- }
- if (m_data == NULL) {
- // malloc/realloc failure!
- m_size = 0;
- m_capacity = 0;
- m_data = NULL;
- return false;
- }
- m_capacity = new_capacity;
-
- assert(m_capacity >= new_size);
-
- m_size = new_size;
-
- return true;
-}
-
-
-bool membuf::append(const void* data, int datasize)
-{
- assert(!m_read_only);
-
- int old_size = size();
- if (resize(size() + datasize) == false) {
- return false;
- }
-
- memcpy(((char*) m_data) + old_size, data, datasize);
-
- return true;
-}
-
-
-bool membuf::append(const membuf& buf)
-{
- return append(buf.data(), buf.size());
-}
-
-
-bool membuf::append(const std::string& str)
-{
- return append(str.c_str(), str.length());
-}
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8
-// tab-width: 8
-// indent-tabs-mode: t
-// End:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog libbase/tu_file.cpp libbase/tu_...,
Benjamin Wolsey <=