Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13274 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71192 invoked by uid 1010); 12 Oct 2004 06:54:15 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 71166 invoked from network); 12 Oct 2004 06:54:14 -0000 Received: from unknown (HELO bobsilva.com) (198.237.84.92) by pb1.pair.com with SMTP; 12 Oct 2004 06:54:14 -0000 Received: from [198.237.84.90] (account me HELO salty) by bobsilva.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 461094 for internals@lists.php.net; Mon, 11 Oct 2004 23:28:44 -0700 To: Date: Mon, 11 Oct 2004 23:54:50 -0700 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0053_01C4AFED.B204B760" X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Thread-Index: AcSwKF5FSwzWjGFEQK66CYTI66upig== Message-ID: Subject: [PATCH] Resubmitted for review From: junkmail@bobsilva.com ("Robert Silva") ------=_NextPart_000_0053_01C4AFED.B204B760 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch allows php extension authors to declare constants on internal objects. This pretty much just duplicates the zend_declare_property_* functions but for constants. Currently there is no way for C level class authors to declare constants on their objects since the engine has to allocate space for them. Bob Silva ------=_NextPart_000_0053_01C4AFED.B204B760 Content-Type: text/plain; name="zend_constants.diff.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="zend_constants.diff.txt" diff -ur php5.orig/Zend/zend_API.c php5/Zend/zend_API.c=0A= --- php5.orig/Zend/zend_API.c 2004-09-28 14:45:40.000000000 -0700=0A= +++ php5/Zend/zend_API.c 2004-09-28 14:52:45.000000000 -0700=0A= @@ -2037,6 +2037,67 @@=0A= return value;=0A= }=0A= =0A= +ZEND_API int zend_declare_constant(zend_class_entry *ce, char *name, = int name_length, zval *constant TSRMLS_DC)=0A= +{=0A= +=0A= + switch(Z_TYPE_P(constant)) {=0A= + case IS_ARRAY:=0A= + case IS_CONSTANT_ARRAY:=0A= + case IS_OBJECT:=0A= + case IS_RESOURCE:=0A= + zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects = or resources");=0A= + break;=0A= + default:=0A= + break;=0A= + }=0A= +=0A= + zend_hash_update(&(ce)->constants_table, name, name_length+1, = &constant, sizeof(zval *), NULL);=0A= + return SUCCESS;=0A= +}=0A= +=0A= +ZEND_API int zend_declare_constant_null(zend_class_entry *ce, char = *name, int name_length TSRMLS_DC)=0A= +{=0A= + zval *constant;=0A= +=0A= + if (ce->type & ZEND_INTERNAL_CLASS) {=0A= + constant =3D malloc(sizeof(zval));=0A= + } else {=0A= + ALLOC_ZVAL(constant);=0A= + }=0A= + INIT_ZVAL(*constant);=0A= + return zend_declare_constant(ce, name, name_length, constant = TSRMLS_CC);=0A= +}=0A= +=0A= +ZEND_API int zend_declare_constant_long(zend_class_entry *ce, char = *name, int name_length, long value TSRMLS_DC)=0A= +{=0A= + zval *constant;=0A= +=0A= + if (ce->type & ZEND_INTERNAL_CLASS) {=0A= + constant =3D malloc(sizeof(zval));=0A= + } else {=0A= + ALLOC_ZVAL(constant);=0A= + }=0A= + INIT_PZVAL(constant);=0A= + ZVAL_LONG(constant, value);=0A= + return zend_declare_constant(ce, name, name_length, constant = TSRMLS_CC);=0A= +}=0A= +=0A= +ZEND_API int zend_declare_constant_string(zend_class_entry *ce, char = *name, int name_length, char *value TSRMLS_DC)=0A= +{=0A= + zval *constant;=0A= + int len =3D strlen(value);=0A= +=0A= + if (ce->type & ZEND_INTERNAL_CLASS) {=0A= + constant =3D malloc(sizeof(zval));=0A= + ZVAL_STRINGL(constant, zend_strndup(value, len), len, 0);=0A= + } else {=0A= + ALLOC_ZVAL(constant);=0A= + ZVAL_STRINGL(constant, value, len, 1);=0A= + }=0A= + INIT_PZVAL(constant);=0A= + return zend_declare_constant(ce, name, name_length, constant = TSRMLS_CC);=0A= +}=0A= +=0A= /*=0A= * Local variables:=0A= * tab-width: 4=0A= diff -ur php5.orig/Zend/zend_API.h php5/Zend/zend_API.h=0A= --- php5.orig/Zend/zend_API.h 2004-09-28 14:45:40.000000000 -0700=0A= +++ php5/Zend/zend_API.h 2004-09-28 14:46:04.000000000 -0700=0A= @@ -195,6 +195,11 @@=0A= =0A= ZEND_API zval *zend_read_property(zend_class_entry *scope, zval = *object, char *name, int name_length, zend_bool silent TSRMLS_DC);=0A= =0A= +ZEND_API int zend_declare_constant(zend_class_entry *ce, char *name, = int name_length, zval *property TSRMLS_DC);=0A= +ZEND_API int zend_declare_constant_null(zend_class_entry *ce, char = *name, int name_length TSRMLS_DC);=0A= +ZEND_API int zend_declare_constant_long(zend_class_entry *ce, char = *name, int name_length, long value TSRMLS_DC);=0A= +ZEND_API int zend_declare_constant_string(zend_class_entry *ce, char = *name, int name_length, char *value TSRMLS_DC);=0A= +=0A= ZEND_API zend_class_entry *zend_get_class_entry(zval *zobject = TSRMLS_DC);=0A= =0A= #define getThis() (this_ptr)=0A= ------=_NextPart_000_0053_01C4AFED.B204B760--