On Feb 11, 2008 4:25 PM, Lars Strojny <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Am Montag, den 11.02.2008, 12:51 +0100 schrieb Lars Strojny:
> [...]
> > [1] http://lars.schokokeks.org/php/dir-constant-2.diff
>
> Updated version. Moved and renamed php_dirname() to zend_dirname() to
> not use PHP internals in the Zend Engine. Fixed a memory leak and added
> the TSRM-includes to have some macros/constants defined.
>
> Comments? Critics?

I did not see the zend_dirname usage (wrong link?) and did not find
either this function/macro.

I slightly modified it to avoid too much strlen and to do not process
the string if there is nothing to process. Please find my version of
your patch as attachment.

Thanks for your work!
-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org
? t
? tz
Index: zend_language_parser.y
===================================================================
RCS file: /repository/ZendEngine2/zend_language_parser.y,v
retrieving revision 1.160.2.4.2.9
diff -u -p -r1.160.2.4.2.9 zend_language_parser.y
--- zend_language_parser.y      28 Dec 2007 13:38:19 -0000      1.160.2.4.2.9
+++ zend_language_parser.y      11 Feb 2008 16:11:35 -0000
@@ -132,6 +132,7 @@
 %token T_FUNC_C
 %token T_LINE
 %token T_FILE
+%token T_DIR
 %token T_COMMENT
 %token T_DOC_COMMENT
 %token T_OPEN_TAG
@@ -682,6 +683,7 @@ common_scalar:
        |       T_CONSTANT_ENCAPSED_STRING      { $$ = $1; }
        |       T_LINE                                          { $$ = $1; }
        |       T_FILE                                          { $$ = $1; }
+       |       T_DIR                                           { $$ = $1; }
        |       T_CLASS_C                                       { $$ = $1; }
        |       T_METHOD_C                                      { $$ = $1; }
        |       T_FUNC_C                                        { $$ = $1; }
Index: zend_language_scanner.l
===================================================================
RCS file: /repository/ZendEngine2/zend_language_scanner.l,v
retrieving revision 1.131.2.11.2.13
diff -u -p -r1.131.2.11.2.13 zend_language_scanner.l
--- zend_language_scanner.l     9 Sep 2007 16:33:34 -0000       1.131.2.11.2.13
+++ zend_language_scanner.l     11 Feb 2008 16:11:36 -0000
@@ -1543,6 +1543,25 @@ HEREDOC_CHARS       ("{"*([^$\n\r\\{]|("
        return T_FILE;
 }
 
+<ST_IN_SCRIPTING>"__DIR__" {
+       const char *filename = zend_get_compiled_filename(TSRMLS_C);
+
+       if (!filename) {
+               zendlval->value.str.len = 0;
+               zendlval->value.str.val = "";
+       } else {
+               const int len = strlen(filename);
+               const char *dirname = estrndup(filename, len);
+               php_dirname(dirname, len);
+
+               zendlval->value.str.len = strlen(dirname);
+               zendlval->value.str.val = estrndup(dirname, 
zendlval->value.str.len);
+       }
+
+       zendlval->type = IS_STRING;
+       return T_DIR;
+}
+
 <INITIAL>(([^<]|"<"[^?%s<]){1,400})|"<s"|"<" {
 #ifdef ZEND_MULTIBYTE
        if (SCNG(output_filter)) {
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to