Commits

Ruslan Osmanov committed fa97274

Change: Moved all constants to the Ev class

Comments (0)

Files changed (3)

 	zend_hash_init(&classes, 0, NULL, NULL, 1);
 	php_ev_register_classes(TSRMLS_C);
 
-
-	/* {{{ EvLoop flags */
-	PHP_EV_REGISTER_LONG_CONSTANT(EVFLAG_AUTO);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVFLAG_NOENV);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVFLAG_FORKCHECK);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVFLAG_NOINOTIFY);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVFLAG_SIGNALFD);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVFLAG_NOSIGMASK);
-
-	PHP_EV_REGISTER_LONG_CONSTANT(EVRUN_NOWAIT);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVRUN_ONCE);
-
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBREAK_CANCEL);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBREAK_ONE);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBREAK_ALL);
-	/* }}} */
-
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_MINPRI);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_MAXPRI);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_READ);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_WRITE);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_TIMER);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_PERIODIC);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_SIGNAL);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_CHILD);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_STAT);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_IDLE);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_PREPARE);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_CHECK);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_EMBED);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_CUSTOM);
-	PHP_EV_REGISTER_LONG_CONSTANT(EV_ERROR);
-
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBACKEND_SELECT);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBACKEND_POLL);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBACKEND_EPOLL);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBACKEND_KQUEUE);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBACKEND_DEVPOLL);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBACKEND_PORT);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBACKEND_ALL);
-	PHP_EV_REGISTER_LONG_CONSTANT(EVBACKEND_MASK);
+	/* Loop flags */
+
+	REGISTER_EV_CLASS_CONST_LONG(FLAG_AUTO,      EVFLAG_AUTO);
+	REGISTER_EV_CLASS_CONST_LONG(FLAG_NOENV,     EVFLAG_NOENV);
+	REGISTER_EV_CLASS_CONST_LONG(FLAG_FORKCHECK, EVFLAG_FORKCHECK);
+	REGISTER_EV_CLASS_CONST_LONG(FLAG_NOINOTIFY, EVFLAG_NOINOTIFY);
+	REGISTER_EV_CLASS_CONST_LONG(FLAG_SIGNALFD,  EVFLAG_SIGNALFD);
+	REGISTER_EV_CLASS_CONST_LONG(FLAG_NOSIGMASK, EVFLAG_NOSIGMASK);
+
+	/* ev_run flags */
+
+	REGISTER_EV_CLASS_CONST_LONG(RUN_NOWAIT, EVRUN_NOWAIT);
+	REGISTER_EV_CLASS_CONST_LONG(RUN_ONCE,   EVRUN_ONCE);
+
+	/* ev_break flags */
+
+	REGISTER_EV_CLASS_CONST_LONG(BREAK_CANCEL, EVBREAK_CANCEL);
+	REGISTER_EV_CLASS_CONST_LONG(BREAK_ONE,    EVBREAK_ONE);
+	REGISTER_EV_CLASS_CONST_LONG(BREAK_ALL,    EVBREAK_ALL);
+
+	/* Watcher priorities */
+
+	REGISTER_EV_CLASS_CONST_LONG(MINPRI, EV_MINPRI);
+	REGISTER_EV_CLASS_CONST_LONG(MAXPRI, EV_MAXPRI);
+
+
+	/* Watcher events/types */
+
+	REGISTER_EV_CLASS_CONST_LONG(READ,     EV_READ);
+	REGISTER_EV_CLASS_CONST_LONG(WRITE,    EV_WRITE);
+	REGISTER_EV_CLASS_CONST_LONG(TIMER,    EV_TIMER);
+	REGISTER_EV_CLASS_CONST_LONG(PERIODIC, EV_PERIODIC);
+	REGISTER_EV_CLASS_CONST_LONG(SIGNAL,   EV_SIGNAL);
+	REGISTER_EV_CLASS_CONST_LONG(CHILD,    EV_CHILD);
+	REGISTER_EV_CLASS_CONST_LONG(STAT,     EV_STAT);
+	REGISTER_EV_CLASS_CONST_LONG(IDLE,     EV_IDLE);
+	REGISTER_EV_CLASS_CONST_LONG(PREPARE,  EV_PREPARE);
+	REGISTER_EV_CLASS_CONST_LONG(CHECK,    EV_CHECK);
+	REGISTER_EV_CLASS_CONST_LONG(EMBED,    EV_EMBED);
+	REGISTER_EV_CLASS_CONST_LONG(CUSTOM,   EV_CUSTOM);
+	REGISTER_EV_CLASS_CONST_LONG(ERROR,    EV_ERROR);
+
+	/* Backend types */
+
+	REGISTER_EV_CLASS_CONST_LONG(BACKEND_SELECT,  EVBACKEND_SELECT);
+	REGISTER_EV_CLASS_CONST_LONG(BACKEND_POLL,    EVBACKEND_POLL);
+	REGISTER_EV_CLASS_CONST_LONG(BACKEND_EPOLL,   EVBACKEND_EPOLL);
+	REGISTER_EV_CLASS_CONST_LONG(BACKEND_KQUEUE,  EVBACKEND_KQUEUE);
+	REGISTER_EV_CLASS_CONST_LONG(BACKEND_DEVPOLL, EVBACKEND_DEVPOLL);
+	REGISTER_EV_CLASS_CONST_LONG(BACKEND_PORT,    EVBACKEND_PORT);
+	REGISTER_EV_CLASS_CONST_LONG(BACKEND_ALL,     EVBACKEND_ALL);
+	REGISTER_EV_CLASS_CONST_LONG(BACKEND_MASK,    EVBACKEND_MASK);
 
 #if !defined(_WIN32) && !defined(_MINIX)
 	pthread_atfork(0, 0, php_ev_default_fork);
 #endif
 
 
-#define PHP_EV_REGISTER_LONG_CONSTANT(name) \
-	REGISTER_LONG_CONSTANT(#name, name, CONST_CS | CONST_PERSISTENT)
-
-#define PHP_EV_REGISTER_CLASS_LONG_CONSTANT(name, zconst)     \
-    zconst = pemalloc(sizeof(zval), 1);                       \
-    INIT_PZVAL(zconst);                                       \
-    ZVAL_LONG(zconst, name);                                  \
-    zend_hash_add(&ce->constants_table, #name, sizeof(#name), \
-            (void*) &zconst, sizeof(zval*), NULL);
+#define PHP_EV_REGISTER_LONG_CONSTANT(name)                           \
+    REGISTER_LONG_CONSTANT(#name, name, CONST_CS | CONST_PERSISTENT)
+
+#define REGISTER_EV_CLASS_CONST_LONG(const_name, value)               \
+    zend_declare_class_constant_long(ev_class_entry_ptr, #const_name, \
+            sizeof(#const_name)-1, (long) value TSRMLS_CC)
 
 #define PHP_EV_REGISTER_CLASS_ENTRY(name, ce, ce_functions) \
 {                                                           \
   <notes>
   Change: moved ev_* functions to Ev singleton(due to some issues with reflection)
   Change: renamed EvLoop::break to EvLoop::stop, and ev_break to Ev::stop
+  Change: moved all constants to Ev class
   Fix: release version
   </notes>
   <!--}}}-->
   <notes>
   Change: moved ev_* functions to Ev singleton(due to some issues with reflection)
   Change: renamed EvLoop::break to EvLoop::stop, and ev_break to Ev::stop
+  Change: moved all constants to Ev class
   Fix: release version
   </notes>
   <!--}}}-->