From 63f2f424dbfe2f873a61d9638127c693f1475ab1 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 4 Apr 2003 16:14:25 +0000 Subject: [PATCH] handle copy constructor properly --- panda/src/putil/pipelineCycler.I | 20 ++++++++++---------- panda/src/putil/pipelineCycler.h | 2 +- panda/src/putil/pipelineCyclerBase.I | 14 +++++++++++--- panda/src/putil/pipelineCyclerBase.h | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/panda/src/putil/pipelineCycler.I b/panda/src/putil/pipelineCycler.I index 96a36d95a4..c1f0b51934 100644 --- a/panda/src/putil/pipelineCycler.I +++ b/panda/src/putil/pipelineCycler.I @@ -41,7 +41,7 @@ PipelineCycler(Pipeline *pipeline) : template INLINE PipelineCycler:: PipelineCycler(const PipelineCycler ©) : - PipelineCyclerBase(copy) + PipelineCyclerBase(copy._data->make_copy(), copy) { } @@ -129,7 +129,7 @@ cheat() const { template INLINE PipelineCycler:: PipelineCycler(Pipeline *pipeline) : - PipelineCyclerBase(&_data, pipeline) + PipelineCyclerBase(&_typed_data, pipeline) { } @@ -141,8 +141,8 @@ PipelineCycler(Pipeline *pipeline) : template INLINE PipelineCycler:: PipelineCycler(const PipelineCycler ©) : - PipelineCyclerBase(copy), - _data(copy._data) + PipelineCyclerBase(&_typed_data, copy), + _typed_data(copy._typed_data) { } @@ -155,7 +155,7 @@ template INLINE void PipelineCycler:: operator = (const PipelineCycler ©) { PipelineCyclerBase::operator = (copy); - _data = copy._data; + _typed_data = copy._typed_data; } //////////////////////////////////////////////////////////////////// @@ -166,7 +166,7 @@ operator = (const PipelineCycler ©) { template INLINE const CycleDataType *PipelineCycler:: read() const { - return &_data; + return &_typed_data; } //////////////////////////////////////////////////////////////////// @@ -177,7 +177,7 @@ read() const { template INLINE CycleDataType *PipelineCycler:: write() { - return &_data; + return &_typed_data; } //////////////////////////////////////////////////////////////////// @@ -188,7 +188,7 @@ write() { template INLINE CycleDataType *PipelineCycler:: elevate_read(const CycleDataType *) { - return &_data; + return &_typed_data; } //////////////////////////////////////////////////////////////////// @@ -199,7 +199,7 @@ elevate_read(const CycleDataType *) { template INLINE CycleDataType *PipelineCycler:: write_stage(int) { - return &_data; + return &_typed_data; } //////////////////////////////////////////////////////////////////// @@ -215,7 +215,7 @@ write_stage(int) { template INLINE CycleDataType *PipelineCycler:: cheat() const { - return (CycleDataType *)&_data; + return (CycleDataType *)&_typed_data; } diff --git a/panda/src/putil/pipelineCycler.h b/panda/src/putil/pipelineCycler.h index 3d69f3ec65..dbf446e598 100644 --- a/panda/src/putil/pipelineCycler.h +++ b/panda/src/putil/pipelineCycler.h @@ -73,7 +73,7 @@ public: private: // If we are *not* compiling in support for pipelining, we just // store the CycleData object right here. No pointers needed. - CycleDataType _data; + CycleDataType _typed_data; #endif // !DO_PIPELINING }; diff --git a/panda/src/putil/pipelineCyclerBase.I b/panda/src/putil/pipelineCyclerBase.I index 4b3108128e..789451e9bc 100644 --- a/panda/src/putil/pipelineCyclerBase.I +++ b/panda/src/putil/pipelineCyclerBase.I @@ -44,8 +44,8 @@ PipelineCyclerBase(CycleData *initial_data, Pipeline *pipeline) : // Description: //////////////////////////////////////////////////////////////////// INLINE PipelineCyclerBase:: -PipelineCyclerBase(const PipelineCyclerBase ©) : - _data(copy._data->make_copy()), +PipelineCyclerBase(CycleData *initial_data, const PipelineCyclerBase ©) : + _data(initial_data), _pipeline(copy._pipeline), _read_count(0), _write_count(0) @@ -312,7 +312,13 @@ PipelineCyclerBase(CycleData *initial_data, Pipeline *) { // Description: //////////////////////////////////////////////////////////////////// INLINE PipelineCyclerBase:: -PipelineCyclerBase(const PipelineCyclerBase &) { +PipelineCyclerBase(CycleData *initial_data, const PipelineCyclerBase &) { + // The copy constructor for the DO_PIPELINING case is +#ifdef SIMPLE_STRUCT_POINTERS + nassertv(initial_data == (CycleData *)this); +#else + _data = initial_data; +#endif // SIMPLE_STRUCT_POINTERS } //////////////////////////////////////////////////////////////////// @@ -322,6 +328,8 @@ PipelineCyclerBase(const PipelineCyclerBase &) { //////////////////////////////////////////////////////////////////// INLINE void PipelineCyclerBase:: operator = (const PipelineCyclerBase &) { + // We don't reassign the _data pointer here; we assume it was set + // correctly previously. } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/putil/pipelineCyclerBase.h b/panda/src/putil/pipelineCyclerBase.h index 5abd7c957e..10293b7585 100644 --- a/panda/src/putil/pipelineCyclerBase.h +++ b/panda/src/putil/pipelineCyclerBase.h @@ -39,7 +39,7 @@ struct EXPCL_PANDA PipelineCyclerBase { public: INLINE PipelineCyclerBase(CycleData *initial_data, Pipeline *pipeline = NULL); - INLINE PipelineCyclerBase(const PipelineCyclerBase ©); + INLINE PipelineCyclerBase(CycleData *initial_data, const PipelineCyclerBase ©); INLINE void operator = (const PipelineCyclerBase ©); INLINE ~PipelineCyclerBase();