From patchwork Sat Aug 6 12:12:47 2005 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Schmidinger X-Patchwork-Id: 11964 Received: from tiger.cadsoft.de ([217.7.101.210]) by www.linuxtv.org with esmtp (Exim 4.34) id 1E1NXn-0006ca-Co for vdr@linuxtv.org; Sat, 06 Aug 2005 14:12:51 +0200 Received: from raven.cadsoft.de (raven.cadsoft.de [217.7.101.211]) by tiger.cadsoft.de (8.12.7/8.12.7) with ESMTP id j76CCo8w006270 for ; Sat, 6 Aug 2005 14:12:50 +0200 Received: from [192.168.100.10] (hawk.cadsoft.de [192.168.100.10]) by raven.cadsoft.de (8.13.3/8.13.3) with ESMTP id j76CCnVp005520 for ; Sat, 6 Aug 2005 14:12:49 +0200 Message-ID: <42F4A93F.8070109@cadsoft.de> Date: Sat, 06 Aug 2005 14:12:47 +0200 From: Klaus Schmidinger Organization: CadSoft Computer GmbH User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en MIME-Version: 1.0 To: vdr@linuxtv.org Subject: Re: [vdr] Problem with cChannel's copy constructor References: <200508041517.54203.marcel.wiesweg@gmx.de> In-Reply-To: <200508041517.54203.marcel.wiesweg@gmx.de> X-Greylist: Sender DNS name whitelisted, not delayed by milter-greylist-2.0 (tiger.cadsoft.de [217.7.101.210]); Sat, 06 Aug 2005 14:12:50 +0200 (CEST) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (raven.cadsoft.de [192.168.1.1]); Sat, 06 Aug 2005 14:12:50 +0200 (CEST) X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Klaus Schmidinger's VDR List-Id: Klaus Schmidinger's VDR List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Aug 2005 12:12:51 -0000 Status: O X-Status: X-Keywords: X-UID: 3948 Marcel Wiesweg wrote: > Hi, > > I just ran into a problem with cChannel's copy constructor. > The problem is that this is actually not a copy constructor, because it sets > the values to 0 instead of copying, and - most important - it behaves > different from operator=. > > It seems these two are not used in VDR except for one place (where I found > this), cSectionHandler::SetChannel. The value stored by cSectionHandle has > nid,tid,sid set to 0. > In the line > shp->channel = Channel ? *Channel : cChannel(); > there seems only the operator= involved, but actually the copy constructor is > invoked before the *Channel is given to opertator=. > Attached is a short test program which illustrates the problem. > > Solution is to make the copy constructor do copying. The "copy constructor" is actually used intentionally in cChannels::NewChannel(), where its sole purpose is to copy the actual transponder data. But you're of course right, a copy constructor should behave like a real copy constructor, and not serve a very special purpose. I have therefore introduced cChannel::CopyTransponderData() for that purpose, and changed the copy ctor so that it calls operator=. See the attached patch and let me know if this works for you. Klaus --- channels.h 2005/05/28 13:57:08 1.32 +++ channels.h 2005/08/06 11:23:32 @@ -181,6 +181,7 @@ bool IsTerr(void) const { return cSource::IsTerr(source); } tChannelID GetChannelID(void) const { return tChannelID(source, nid, (nid || tid) ? tid : Transponder(), sid, rid); } int Modification(int Mask = CHANNELMOD_ALL); + void CopyTransponderData(const cChannel *Channel); bool SetSatTransponderData(int Source, int Frequency, char Polarization, int Srate, int CoderateH); bool SetCableTransponderData(int Source, int Frequency, int Modulation, int Srate, int CoderateH); bool SetTerrTransponderData(int Source, int Frequency, int Bandwidth, int Modulation, int Hierarchy, int CodeRateH, int CodeRateL, int Guard, int Transmission); --- channels.c 2005/05/29 10:32:38 1.42 +++ channels.c 2005/08/06 12:06:37 @@ -179,27 +179,13 @@ cChannel::cChannel(const cChannel &Channel) { - name = strdup(""); - shortName = strdup(""); - provider = strdup(""); - portalName = strdup(""); - *this = Channel; - vpid = 0; - ppid = 0; - apids[0] = 0; - dpids[0] = 0; - spids[0] = 0; - tpid = 0; - caids[0] = 0; - nid = 0; - tid = 0; - sid = 0; - rid = 0; - number = 0; - groupSep = false; - modification = CHANNELMOD_NONE; + name = NULL; + shortName = NULL; + provider = NULL; + portalName = NULL; linkChannels = NULL; refChannel = NULL; + *this = Channel; } cChannel::~cChannel() @@ -265,6 +251,24 @@ return Result; } +void cChannel::CopyTransponderData(const cChannel *Channel) +{ + if (Channel) { + frequency = Channel->frequency; + source = Channel->source; + srate = Channel->srate; + polarization = Channel->polarization; + inversion = Channel->inversion; + bandwidth = Channel->bandwidth; + coderateH = Channel->coderateH; + coderateL = Channel->coderateL; + modulation = Channel->modulation; + transmission = Channel->transmission; + guard = Channel->guard; + hierarchy = Channel->hierarchy; + } +} + bool cChannel::SetSatTransponderData(int Source, int Frequency, char Polarization, int Srate, int CoderateH) { // Workarounds for broadcaster stupidity: @@ -977,7 +981,8 @@ { if (Transponder) { dsyslog("creating new channel '%s,%s;%s' on %s transponder %d with id %d-%d-%d-%d", Name, ShortName, Provider, *cSource::ToString(Transponder->Source()), Transponder->Transponder(), Nid, Tid, Sid, Rid); - cChannel *NewChannel = new cChannel(*Transponder); + cChannel *NewChannel = new cChannel; + NewChannel->CopyTransponderData(Transponder); NewChannel->SetId(Nid, Tid, Sid, Rid); NewChannel->SetName(Name, ShortName, Provider); Add(NewChannel);