Re: [PHP4BETA] major problem with allocating zval in modules
| From: | bourbon at netvision dot net dot il | Date: | Fri, 02 Jul 1999 17:04:15 +0000 |
| Subject: | Re: [PHP4BETA] major problem with allocating zval in modules | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-1837@lists.php.net to get a copy of this message | ||
You only get into trouble if you don't use API functions. Using emalloc()
for allocating a zval is quite alright.
Zeev
On Fri, 2 Jul 1999, Thies C. Arntzen wrote:
> On Fri, 2 Jul 1999 bourbon@netvision.net.il wrote:
>
> > Well, this shouldn't affect you if you use API functions.
> >
> > If the array in question is the return value of the function, you need not
> > take care of its reference counting.
> > If it's a member in a different array (do we have any functions that
> > return multidimensional arrays?), then you should be using API functions
> > to register it in the array. Unfortunately, it seems we don't have API
> > functions to register arrays within other arrays (only scalar types), but
> > in any case, this should be the solution.
>
> there are a few functions that handle p^Hzvals themself, and all they do
> i use emalloc and fill in the stuff they know - but never is_ref or
> refcount, so it's up to emalloc what those values are;-)
>
> we should have some kind of an api for that.
>
> grep "sizeof(pval)" php4/ext/*/*.c | wc
> 72 442 5552
>
> so we have ~70 places where we possibly get is_ref/refcount wrong!
>
> tc
>
> >
> > Zeev
> >
> > On Fri, 2 Jul 1999, Thies C. Arntzen wrote:
> >
> > > hi,
> > >
> > > the following code is wrong (was correct in php3)
> > >
> > > zval *hallo = emalloc(sizeof(zval));
> > > array_init(hallo);
> > >
> > > as emalloc does NOT initialize is_ref and refcount in the zval structure.
> > >
> > > we should have some more api-functions that take care of this cause adding
> > >
> > > bla->is_ref = 0;
> > > bla->refcount = 1;
> > >
> > > in every module that creates zvals is painful! and i'm sure we'll forget
> > > some.
> > >
> > > this should be sorted before b1 in my opinion!
> > >
> > > btw: my last commit fixed all mem-leaks from my testcase (and there was a
> > > LOT!).
> > >
> > >
> > > tc
> > >
> > >
> > > Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!"
> > > Digital Collections Phone +49 40 235350 Fax +49 40 23535180
> > > Hammerbrookstr. 93 20097 Hamburg / Germany
> > >
> > >
> > > --
> > > PHP 4 Beta
> > >
> >
> > --
> > -----------------------------------------------------
> > Zeev Suraski <zeev@zend.com>
> > For a PGP public key, finger bourbon@netvision.net.il
> >
> >
> >
>
>
> Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!"
> Digital Collections Phone +49 40 235350 Fax +49 40 23535180
> Hammerbrookstr. 93 20097 Hamburg / Germany
>
>
> --
> PHP 4 Beta
>
--
-----------------------------------------------------
Zeev Suraski <zeev@zend.com>
For a PGP public key, finger bourbon@netvision.net.il