[Gambas-devel] Returning a reference to an array ...

Gareth Bult gareth at ...560...
Tue Jan 13 00:22:49 CET 2009


Arhrhrhr, sorry, I should've spotted that one.

It's all looking pretty tight now, except for the Signal#11 I'm generating on my unref
on the second pass through this routine .. I guess I'm misunderstanding memory management
somewhere. First pass works fine, second pass not so good .. anything obvious?

What's confusing me is I'm successfully refing and unrefing "dev", and I'm refing THIS->devices,
however for some reason it doesn't like the unref. Should I not be using ref/unref on the array?

void refresh_audio_devices(void* _object)
{
	struct iaxc_audio_device *devs;
	int ndevs,input,output,ring,i;
	CIAX2DEVICE *dev;

        // this is the "free" code, only activated on second call ..

	if(THIS->devices) { 
		for( i=0; i< GB.Array.Count(THIS->devices); i++ ) {
	  		dev = *((void **)GB.Array.Get(THIS->devices, i));
			GB.FreeString(&dev->name);
			GB.Unref(&dev);
		}
		printf("Unref:%p\n",&THIS->devices); fflush(stdout);
===>		GB.Unref(&THIS->devices);    ' dies here with signal #11 !!!!!!
		logger("Done!");
	}

        // this part happens on both passes ...

	iaxc_audio_devices_get(&devs,&ndevs,&input,&output,&ring);

	GB.Array.New(&THIS->devices, (GB_TYPE)GB.FindClass("IAX2Device"), ndevs);
	for (i = 0; i < ndevs; i++)
	{
		GB.New((void**)&dev,GB.FindClass("IAX2Device"),NULL,NULL);
		GB.Ref(dev);
		GB.NewString(&dev->name,devs[i].name,0);
		dev->id = devs[i].devID;
		dev->capabilities = devs[i].capabilities;
	  	*((void **)GB.Array.Get(THIS->devices, i)) = dev;
	}	
	GB.Ref(THIS->devices);
}

typedef struct
{        
	GB_BASE 	ob;		// inherited from Gambas
	char*		host;		// server host name or IP
	char*		user;		// user name
	char*		password;	// user password
	int		id;		// registration id
	int 		reply;		// registration reply
	int 		count;		// connection counter
==>	GB_ARRAY	devices;	// THIS->devices !!

} CIAX2CONNECTION;


----- Original Message -----
From: "Benoit Minisini" <gambas at ...1...>
To: "mailing list for gambas developers" <gambas-devel at lists.sourceforge.net>
Sent: Monday, 12 January, 2009 8:11:45 PM GMT +00:00 GMT Britain, Ireland, Portugal
Subject: Re: [Gambas-devel] Returning a reference to an array ...

On lundi 12 janvier 2009, Gareth Bult wrote:
> Ok,
>
> My array seems to work fine .. but now I'm adding;
>
> (ndevs=15)
>
> >>GB.Array.New(&THIS->devices, (GB_TYPE)GB.FindClass("IAX2Device"), ndevs);
>
> ++printf("Devices=%d (%d)\n",GB.Count(THIS->devices),ndevs);
>
> I was sort of expecting this to print;
>
> Devices=15 (15)
>
> But it prints;
>
> Devices=1308438512 (15)
>
> Am I making an obvious mistake, or is GB.Count not working ?
>
> Gareth.
>
>

GB.Count() if for arrays created with GB.NewArray(). For Gambas arrays, use 
GB.Array.Count().

Regards,

-- 
Benoit Minisini

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Gambas-devel mailing list
Gambas-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-devel

-- 
Managing Director, Encryptec Limited
Tel: 0845 5082719, Mob: 0785 3305393
Email: gareth at ...560... 
Statements made are at all times subject to Encryptec's Terms and Conditions of Business, which are available upon request.




More information about the Devel mailing list