]> granicus.if.org Git - php/commitdiff
- Fix Win32 compilation (Use winsock2.h from now on)
authorZeev Suraski <zeev@php.net>
Sat, 3 Jun 2000 01:49:49 +0000 (01:49 +0000)
committerZeev Suraski <zeev@php.net>
Sat, 3 Jun 2000 01:49:49 +0000 (01:49 +0000)
- Add lambda() support

Zend/ZendTS.dsp
Zend/zend-scanner.l
Zend/zend.c
Zend/zend.h
Zend/zend_builtin_functions.c
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_globals.h
Zend/zend_hash.c

index 272208d45ca6690f83ed30fffa48e912fdb57fdb..17c5fceebc53d33a6d69b00f0d0ff345f7aa9056 100644 (file)
@@ -40,7 +40,7 @@ RSC=rc.exe
 # PROP Intermediate_Dir "Release_TS"\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDebug_TS" /D "_MBCS" /D "_LIB" /YX /FD /c\r
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug_TS" /D "_LIB" /D "TSRM_EXPORTS" /D "LIBZEND_EXPORTS" /D ZEND_DEBUG=0 /D "ZTS" /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /D "PHP_WIN32" /FR /FD /c\r
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug_TS" /D ZEND_DEBUG=0 /D _WIN32_WINNT=0x400 /D "_LIB" /D "TSRM_EXPORTS" /D "LIBZEND_EXPORTS" /D "ZTS" /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /D "PHP_WIN32" /D _WIN32_WINNT=0x0400 /FR /FD /c\r
 # SUBTRACT CPP /YX\r
 # ADD BASE RSC /l 0x40d /d "NDebug_TS"\r
 # ADD RSC /l 0x40d /d "NDebug_TS"\r
@@ -62,7 +62,7 @@ LIB32=link.exe -lib
 # PROP Intermediate_Dir "Debug_TS"\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_Debug_TS" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c\r
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /D "_Debug_TS" /D "_LIB" /D "LIBZEND_EXPORTS" /D "TSRM_EXPORTS" /D ZEND_DEBUG=1 /D "ZEND_WIN32" /D "ZTS" /D "WIN32" /D "_MBCS" /D "PHP_WIN32" /FR /YX /FD /GZ /c\r
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /D "_Debug_TS" /D ZEND_DEBUG=1 /D "_LIB" /D "TSRM_EXPORTS" /D "LIBZEND_EXPORTS" /D "ZTS" /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /D "PHP_WIN32" /D _WIN32_WINNT=0x0400 /FR /YX /FD /GZ /c\r
 # ADD BASE RSC /l 0x40d /d "_Debug_TS"\r
 # ADD RSC /l 0x40d /d "_Debug_TS"\r
 BSC32=bscmake.exe\r
@@ -84,7 +84,7 @@ LIB32=link.exe -lib
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug_TS" /D "_LIB" /D "TSRM_EXPORTS" /D "LIBZEND_EXPORTS" /D "ZTS" /D "WIN32" /D "_MBCS" /D ZEND_DEBUG=0 /FR /FD /c\r
 # SUBTRACT BASE CPP /YX\r
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug_TS" /D "_LIB" /D "TSRM_EXPORTS" /D "LIBZEND_EXPORTS" /D ZEND_DEBUG=0 /D "ZTS" /D "ZEND_WIN32" /D "ZEND_WIN32_FORCE_INLINE" /D "WIN32" /D "_MBCS" /D "PHP_WIN32" /FR /FD /c\r
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug_TS" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D _WIN32_WINNT=0x400 /D "_LIB" /D "TSRM_EXPORTS" /D "LIBZEND_EXPORTS" /D "ZTS" /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /D "PHP_WIN32" /D _WIN32_WINNT=0x0400 /FR /FD /c\r
 # SUBTRACT CPP /YX\r
 # ADD BASE RSC /l 0x40d /d "NDebug_TS"\r
 # ADD RSC /l 0x40d /d "NDebug_TS"\r
index 3db1f7e96aa4cea3c9f3f0c07bb31506c0986cf1..4bd51de8046f44b325c1e87311730eee64927881 100644 (file)
@@ -34,7 +34,6 @@
 %{
 
 #ifdef ZEND_WIN32
-#include <winsock.h>
 #include <io.h>
 #endif
 
index d1677088a0f3290c55c60834dec80a9541bdfaa2..07fda8b27c577278b1ad73c645df17c62c07b65b 100644 (file)
@@ -277,6 +277,7 @@ static void executor_globals_ctor(zend_executor_globals *executor_globals)
                zend_copy_constants(executor_globals->zend_constants, global_constants_table);
        }
        zend_init_rsrc_plist(ELS_C);
+       EG(lambda_count)=0;
 }
 
 
@@ -594,3 +595,28 @@ ZEND_API void zend_error(int type, const char *format, ...)
        va_end(args);
 }
 
+
+ZEND_API void zend_output_debug_string(zend_bool trigger_break, char *format, ...)
+{
+#if ZEND_DEBUG
+       va_list args;
+
+       va_start(args, format);
+#      if ZEND_WIN32
+       {
+               char output_buf[1024];
+
+               vsnprintf(output_buf, 1024, format, args);
+               OutputDebugString(output_buf);
+               OutputDebugString("\n");
+               if (trigger_break && IsDebuggerPresent()) {
+                       DebugBreak();
+               }
+       }
+#      else
+       vfprintf(stderr, format, args);
+       fprintf(stderr, "\n");
+#      endif
+       va_end(args);
+#endif
+}
index cb9a20b2af2182f12f6bc0f31c663704bb4eecd9..137484f076b62132690c33b5a922e1c2a95e0d3d 100644 (file)
@@ -293,6 +293,13 @@ ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int in
 ZEND_API void zend_print_zval_r(zval *expr, int indent);
 ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent);
 
+ZEND_API void zend_output_debug_string(zend_bool trigger_break, char *format, ...);
+#if ZEND_DEBUG
+#define Z_DBG(expr)            (expr)
+#else
+#define        Z_DBG(expr)
+#endif
+
 ZEND_API extern char *empty_string;
 
 #define STR_FREE(ptr) if (ptr && ptr!=empty_string) { efree(ptr); }
index 3333530db27f637ee4f4ab01eee6f685456e9c1f..acbd24de918c9b443d152e3aeb0e7abc68835d24 100644 (file)
@@ -55,6 +55,7 @@ static ZEND_FUNCTION(get_class_methods);
 static ZEND_FUNCTION(trigger_error);
 static ZEND_FUNCTION(set_error_handler);
 static ZEND_FUNCTION(get_declared_classes);
+static ZEND_FUNCTION(lambda);
 
 unsigned char first_arg_force_ref[] = { 1, BYREF_FORCE };
 unsigned char first_arg_allow_ref[] = { 1, BYREF_ALLOW };
@@ -93,6 +94,7 @@ static zend_function_entry builtin_functions[] = {
        ZEND_FALIAS(user_error,         trigger_error,          NULL)
        ZEND_FE(set_error_handler,              NULL)
        ZEND_FE(get_declared_classes, NULL)
+       ZEND_FE(lambda,                         NULL)
        { NULL, NULL, NULL }
 };
 
@@ -798,3 +800,57 @@ ZEND_FUNCTION(get_declared_classes)
        zend_hash_apply_with_argument(CG(class_table), (apply_func_arg_t)copy_class_name, return_value);
 }
 /* }}} */
+
+
+#define LAMBDA_TEMP_FUNCNAME   "__lambda_func"
+
+/* {{ proto string lambda(string args, string code)
+   Creates an anonymous function, and returns its name (funny, eh?) */
+ZEND_FUNCTION(lambda)
+{
+       char *eval_code, *function_name;
+       int eval_code_length, function_name_length;
+       zval **z_function_args, **z_function_code;
+       int retval;
+       CLS_FETCH();
+
+       if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &z_function_args, &z_function_code)==FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+
+       convert_to_string_ex(z_function_args);
+       convert_to_string_ex(z_function_code);
+
+       eval_code_length = sizeof("function " LAMBDA_TEMP_FUNCNAME)
+                       +Z_STRLEN_PP(z_function_args)
+                       +2      /* for the args parentheses */
+                       +2      /* for the curly braces */
+                       +Z_STRLEN_PP(z_function_code);
+
+       eval_code = (char *) emalloc(eval_code_length);
+       sprintf(eval_code, "function " LAMBDA_TEMP_FUNCNAME "(%s){%s}", Z_STRVAL_PP(z_function_args), Z_STRVAL_PP(z_function_code));
+
+       retval = zend_eval_string(eval_code, NULL CLS_CC ELS_CC);
+       efree(eval_code);
+       if (retval==SUCCESS) {
+               zend_function *func;
+
+               if (zend_hash_find(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME), (void **) &func)==FAILURE) {
+                       zend_error(E_ERROR, "Unexpected inconsistency in lambda()");
+                       RETURN_FALSE;
+               }
+               function_add_ref(func);
+
+               function_name = (char *) emalloc(sizeof("0lambda_")+MAX_LENGTH_OF_LONG);
+
+               do {
+                       sprintf(function_name, "%clambda_%d", 0, ++EG(lambda_count));
+                       function_name_length = strlen(function_name);
+               } while (zend_hash_add(EG(function_table), function_name, function_name_length+1, func, sizeof(zend_function), NULL)==FAILURE);
+               zend_hash_del(EG(function_table), LAMBDA_TEMP_FUNCNAME, sizeof(LAMBDA_TEMP_FUNCNAME));
+               RETURN_STRINGL(function_name, function_name_length, 0);
+       } else {
+               RETURN_FALSE;
+       }
+}
+/* }}} */
\ No newline at end of file
index 2d6b79939e84518b172cb6a0c4630cf21cd663d5..badb133ad18c6a7401c1250d76aea09b7c34d0a2 100644 (file)
@@ -1040,7 +1040,7 @@ void do_return(znode *expr, int do_end_vparse CLS_DC)
 }
 
 
-static void function_add_ref(zend_function *function)
+void function_add_ref(zend_function *function)
 {
        if (function->type == ZEND_USER_FUNCTION) {
                zend_op_array *op_array = &function->op_array;
index d3eb8dde581fdb9efed18b9ef96e75c3b3bcf787..f7b51287849c39b8b0c103efee8e222c94f98108 100644 (file)
@@ -363,6 +363,8 @@ void do_extended_fcall_end(CLS_D);
 
 void do_ticks(CLS_D);
 
+void function_add_ref(zend_function *function);
+
 #define INITIAL_OP_ARRAY_SIZE 64
 
 
index 2c76a8de062f4420330b95eccb8c686d6340a028..8b5f21053811caf098dbfb5eb45a81a03e54c6b4 100644 (file)
@@ -181,6 +181,8 @@ struct _zend_executor_globals {
 
        zval *user_error_handler;
 
+       int lambda_count;
+
        void *reserved[ZEND_MAX_RESERVED_RESOURCES];
 #if SUPPORT_INTERACTIVE
        int interactive;
index 7487eebf7ceae333463f5d9daedcfcead4cad8fe..3566c97ce2ffd3617c26c86d69358e9d1f739f94 100644 (file)
        }
 
 #if ZEND_DEBUG
+#define HT_OK                          0
 #define HT_IS_DESTROYING       1
 #define HT_DESTROYED           2
-#define HT_CLEANING            3
-#define HT_OK                          0
+#define HT_CLEANING                    3
 
 static void _zend_is_inconsistent(HashTable *ht, char *file, int line)
 {
+       if (ht->inconsistent==HT_OK) {
+               return;
+       }
     switch (ht->inconsistent) {
-       case HT_IS_DESTROYING:
-        zend_error(E_CORE_ERROR, "ht=%08x is destroying in %s:%d", ht, file, line);
-               break;
-       case HT_DESTROYED:
-        zend_error(E_CORE_ERROR, "ht=%08x is already destroyed in %s:%d", ht, file, line);
-               break;
-       case HT_CLEANING:
-        zend_error(E_CORE_ERROR, "ht=%08x is cleaning %s:%d", ht, file, line);
-               break;
+               case HT_IS_DESTROYING:
+                       zend_output_debug_string(1, "%s(%d) : ht=0x%08x is being destroyed", file, line, ht);
+                       break;
+               case HT_DESTROYED:
+                       zend_output_debug_string(1, "%s(%d) : ht=0x%08x is already destroyed", file, line, ht);
+                       break;
+               case HT_CLEANING:
+                       zend_output_debug_string(1, "%s(%d) : ht=0x%08x is being cleaned", file, line, ht);
+                       break;
     }
+       zend_bailout();
 }
 #define IS_CONSISTENT(a) _zend_is_inconsistent(a,__FILE__,__LINE__);
 #define SET_INCONSISTENT(n) ht->inconsistent = n;
@@ -1106,7 +1110,7 @@ void zend_hash_display_pListTail(HashTable *ht)
 
        p = ht->pListTail;
        while (p != NULL) {
-               zend_printf("pListTail has key %s\n", p->arKey);
+               zend_output_debug_string(0, "pListTail has key %s\n", p->arKey);
                p = p->pListLast;
        }
 }
@@ -1119,14 +1123,14 @@ void zend_hash_display(HashTable *ht)
        for (i = 0; i < ht->nTableSize; i++) {
                p = ht->arBuckets[i];
                while (p != NULL) {
-                       zend_printf("%s <==> 0x%X\n", p->arKey, p->h);
+                       zend_output_debug_string(0, "%s <==> 0x%X\n", p->arKey, p->h);
                        p = p->pNext;
                }
        }
 
        p = ht->pListTail;
        while (p != NULL) {
-               zend_printf("%s <==> 0x%X\n", p->arKey, p->h);
+               zend_output_debug_string(0, "%s <==> 0x%X\n", p->arKey, p->h);
                p = p->pListLast;
        }
 }