Re: [PHP4BETA] : get_class etc.. : memory leak ?
| From: | (Danny Heijl) | Date: | Thu, 29 Jul 1999 12:50:18 +0000 |
| Subject: | Re: [PHP4BETA] : get_class etc.. : memory leak ? | ||
| References: | 1 2 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-2947@lists.php.net to get a copy of this message | ||
Thanks.
It seems to have fixed bugs #1916 and #1920 too !
Danny.
---
----- Original Message -----
From: Andi Gutmans <andi@zend.com>
To: Danny Heijl <Danny.Heijl@cevi.be>
Sent: donderdag 29 juli 1999 15:32
Subject: Re: [PHP4BETA] : get_class etc.. : memory leak ?
I fixed it in the latest CVS.
Andi
At 09:41 AM 7/29/99 +0200, Danny Heijl wrote:
> ../php testobj
>Content-Type: text/html
>
>foobar
>
>barbara
>foobar
>1
>1
>1
>testobj: Freeing 0x08213030 (7 bytes), allocated in
>/home/php/php4/./libzend/zend-scanner.l on
>line 1062<br>
>
>Should I report this, or is this one of the known problems "to be fixed
>later" ?
>
>Danny.
>---
>
>----- Original Message -----
>From: Andi Gutmans <andi@php.net>
>Newsgroups: php4.beta
>Sent: woensdag 28 juli 1999 19:52
>Subject: [PHP4BETA] cvs: /php4 ChangeLog /php4/ext/standard
>basic_functions.c basic_functions.h soundex.c /php4/tests testobj
>
>
> > andi Wed Jul 28 13:58:39 1999 EDT
> >
> > Modified files:
> > /php4 ChangeLog
> > /php4/ext/standard basic_functions.c basic_functions.h soundex.c
> > /php4/tests testobj
> > Log:
> > - Added get_class($obj), get_parent_class($obj) and
>method_exists($obj,"name")
> >
> >
> > Index: php4/ChangeLog
> > diff -u php4/ChangeLog:1.28 php4/ChangeLog:1.29
> > --- php4/ChangeLog:1.28 Tue Jul 27 16:33:42 1999
> > +++ php4/ChangeLog Wed Jul 28 13:58:37 1999
> > @@ -2,6 +2,9 @@
> >
>|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
>|||
> >
> > ??? ?? 1999, Version 4.0 Beta 2
> > +- Added get_class($obj), get_parent_class($obj) and
>method_exists($obj,"name")
> > + (Andi & Zeev)
> > +- Fixed various inheritance problems (Andi & Zeev, libzend)
> > - Children now inherit their parent's constructor, if they do not
supply
>a
> > constructor of their own.
> > - Fixed runtime inheritence of classes (parent methods/properties were
> > Index: php4/ext/standard/basic_functions.c
> > diff -u php4/ext/standard/basic_functions.c:1.60
>php4/ext/standard/basic_functions.c:1.61
> > --- php4/ext/standard/basic_functions.c:1.60 Wed Jul 28 09:59:35 1999
> > +++ php4/ext/standard/basic_functions.c Wed Jul 28 13:58:37 1999
> > @@ -272,6 +272,9 @@
> > PHP_FE(is_string, first_arg_allow_ref)
> > PHP_FE(is_array, first_arg_allow_ref)
> > PHP_FE(is_object, first_arg_allow_ref)
> > + PHP_FE(get_class, NULL)
> > + PHP_FE(get_parent_class, NULL)
> > + PHP_FE(method_exists, NULL)
> >
> > PHP_FE(leak, NULL)
> > PHP_FE(error_log, NULL)
> > @@ -1594,12 +1597,70 @@
> > }
> >
> >
> > -PHP_FUNCTION(is_long) { php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU,
>IS_LONG); }
> > -PHP_FUNCTION(is_double)
php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU,
>IS_DOUBLE); }
> > -PHP_FUNCTION(is_string)
php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU,
>IS_STRING); }
> > -PHP_FUNCTION(is_array) { php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU,
>IS_ARRAY); }
> > -PHP_FUNCTION(is_object)
php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU,
>IS_OBJECT); }
> > +PHP_FUNCTION(is_long)
> > +{
> > + php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_LONG);
> > +}
> > +
> > +PHP_FUNCTION(is_double)
> > +{
> > + php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_DOUBLE);
> > +}
> > +
> > +PHP_FUNCTION(is_string)
> >
>
> > + php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_STRING);
> > +}
> > +
> > +PHP_FUNCTION(is_array)
> > +{
> > + php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_ARRAY);
> > +}
> > +
> > +PHP_FUNCTION(is_object)
> > +{
> > + php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_OBJECT);
> > +}
> > +
> > +PHP_FUNCTION(get_class)
> > +{
> > + pval *arg;
> > +
> > + if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &arg)==FAILURE) {
> > + RETURN_FALSE;
> > + }
> > + if (arg->type != IS_OBJECT) {
> > + RETURN_FALSE;
> > + }
> > + RETURN_STRINGL(arg->value.obj.ce->name,
arg->value.obj.ce->name_length,
>1);
> > +}
> > +
> > +PHP_FUNCTION(get_parent_class)
> > +{
> > + pval *arg;
> > +
> > + if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &arg)==FAILURE) {
> > + RETURN_FALSE;
> > + }
> > + if ((arg->type != IS_OBJECT) || !arg->value.obj.ce->parent) {
> > + RETURN_FALSE;
> > + }
> > + RETURN_STRINGL(arg->value.obj.ce->parent->name,
>arg->value.obj.ce->parent->name_length, 1);
> > +}
> >
> > +PHP_FUNCTION(method_exists)
> > +{
> > + pval *arg1, *arg2;
> > +
> > + if (ARG_COUNT(ht)!=2 || getParameters(ht, 2, &arg1, &arg2)==FAILURE) {
> > + RETURN_FALSE;
> > + }
> > + if (arg1->type != IS_OBJECT) {
> > + RETURN_FALSE;
> > + }
> > + convert_to_string(arg2);
> > + RETURN_LONG(zend_hash_exists(&arg1->value.obj.ce->function_table,
>arg2->value.str.val, arg2->value.str.len+1));
> > +}
> >
> > PHP_FUNCTION(leak)
> > {
> > Index: php4/ext/standard/basic_functions.h
> > diff -u php4/ext/standard/basic_functions.h:1.12
>php4/ext/standard/basic_functions.h:1.13
> > --- php4/ext/standard/basic_functions.h:1.12 Mon Jul 26 16:09:08 1999
> > +++ php4/ext/standard/basic_functions.h Wed Jul 28 13:58:38 1999
> > @@ -29,7 +29,7 @@
> > */
> >
> >
> > -/* $Id: basic_functions.h,v 1.12 1999/07/26 20:09:08 andrey Exp $ */
> > +/* $Id: basic_functions.h,v 1.13 1999/07/28 17:58:38 andi Exp $ */
> >
> > #ifndef _BASIC_FUNCTIONS_H
> > #define _BASIC_FUNCTIONS_H
> > @@ -92,6 +92,10 @@
> > PHP_FUNCTION(is_string);
> > PHP_FUNCTION(is_array);
> > PHP_FUNCTION(is_object);
> > +
> > +PHP_FUNCTION(get_class);
> > +PHP_FUNCTION(get_parent_class);
> > +PHP_FUNCTION(method_exists);
> >
> > PHP_FUNCTION(leak);
> >
> > Index: php4/ext/standard/soundex.c
> > diff -u php4/ext/standard/soundex.c:1.5 php4/ext/standard/soundex.c:1.6
> > --- php4/ext/standard/soundex.c:1.5 Wed Jul 28 07:26:58 1999
> > +++ php4/ext/standard/soundex.c Wed Jul 28 13:58:38 1999
> > @@ -15,7 +15,7 @@
> > | Author: Bjørn Borud - Guardian Networks AS <borud@guardian.no>
>|
> >
>+----------------------------------------------------------------------+
> > */
> > -/* $Id: soundex.c,v 1.5 1999/07/28 11:26:58 danny Exp $ */
> > +/* $Id: soundex.c,v 1.6 1999/07/28 17:58:38 andi Exp $ */
> >
> > #include "php.h"
> > #include <stdlib.h>
> > @@ -29,7 +29,7 @@
> > PHP_FUNCTION(soundex)
> > {
> > char *somestring;
> > - int i, small, len, code, last;
> > + int i, _small, len, code, last;
> > pval *arg;
> > char soundex[4 + 1];
> >
> > @@ -73,16 +73,16 @@
> >
> > /* build soundex string */
> > last = -1;
> > - for (i = 0, small = 0; i < len && small < 4; i++) {
> > + for (i = 0, _small = 0; i < len && _small < 4; i++) {
> > /* convert chars to upper case and strip non-letter chars */
> > /* BUG: should also map here accented letters used in non */
> > /* English words or names (also found in English text!): */
> > /* esstsett, thorn, n-tilde, c-cedilla, s-caron, ... */
> > code = toupper(somestring[i]);
> > if (code >= 'A' && code <= 'Z') {
> > - if (small == 0) {
> > + if (_small == 0) {
> > /* remember first valid char */
> > - soundex[small++] = code;
> > + soundex[_small++] = code;
> > last = soundex_table[code - 'A'];
> > }
> > else {
> > @@ -92,7 +92,7 @@
> > code = soundex_table[code - 'A'];
> > if (code != last) {
> > if (code != 0) {
> > - soundex[small++] = code;
> > + soundex[_small++] = code;
> > }
> > last = code;
> > }
> > @@ -100,13 +100,13 @@
> > }
> > }
> > /* pad with '0' and terminate with 0 ;-) */
> > - while (small < 4) {
> > - soundex[small++] = '0';
> > + while (_small < 4) {
> > + soundex[_small++] = '0';
> > }
> > - soundex[small] = '\0';
> > + soundex[_small] = '\0';
> >
> > - return_value->value.str.val = estrndup(soundex, small);
> > - return_value->value.str.len = small;
> > + return_value->value.str.val = estrndup(soundex, _small);
> > + return_value->value.str.len = _small;
> > return_value->type = IS_STRING;
> > }
> > /* }}} */
> > Index: php4/tests/testobj
> > diff -u php4/tests/testobj:1.2 php4/tests/testobj:1.3
> > --- php4/tests/testobj:1.2 Mon Jul 26 12:54:41 1999
> > +++ php4/tests/testobj Wed Jul 28 13:58:38 1999
> > @@ -1,14 +1,30 @@
> > <?
> >
> > +define("endl","\n");
> > +
> > +if (1) {
> > class foobar {
> > function foobar() {
> > - print "foobar!\n";
> > $this->initialized = 1;
> > }
> > };
> >
> > +class barbara extends foobar {
> > +
> > +};
> > +}
> > +
> > $foo = new foobar; // or die("Unable to construct foobar\n");
> > -print $foo->initialized;
> > +//print $foo->initialized;
> > +
> > +$boo = new barbara;
> > +print get_class($foo).endl;
> > +print get_parent_class($foo).endl;
> > +print get_class($boo).endl;
> > +print get_parent_class($boo).endl;
> > +print method_exists($foo,"foobar").endl;
> > +print method_exists($boo,"foobar").endl;
> > +print method_exists($boo,"barbara").endl;
> > file://$word = new COm("word.application");
> > file://$word->visible = true;
> > file://sleep(5);
> >
> >
> >
> > --
> > PHP 4 Beta
> >
---
Andi Gutmans <andi@zend.com>
http://www.zend.com/