sas             Mon Dec  9 07:42:28 2002 EDT

  Added files:                 
    /php4/ext/ircg      php_ircg_formats.h 

  Modified files:              
    /php4/ext/ircg      ircg.c php_ircg_private.h php_ircg_tokenizer.h 
  Log:
  It is now possible to run 'apachectl restart' even if PHP
  and/or the IRCG extension are a shared module. 
  
  In those cases, the heap will be initialized to zero during
  a restart, so we basically lose all state information,
  including pointers to already allocated data structures.
  
  We compensate that by introducing a separate area manager
  which maintains a id => ptr mapping.  That manager can be
  queried through a UNIX domain socket, so that the newly
  loaded DSO (which still has the shared memory segment 
  attached) can ask the manager for the pointers.
  
  
Index: php4/ext/ircg/ircg.c
diff -u php4/ext/ircg/ircg.c:1.158 php4/ext/ircg/ircg.c:1.159
--- php4/ext/ircg/ircg.c:1.158  Fri Dec  6 01:52:47 2002
+++ php4/ext/ircg/ircg.c        Mon Dec  9 07:42:28 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: ircg.c,v 1.158 2002/12/06 06:52:47 sas Exp $ */
+/* $Id: ircg.c,v 1.159 2002/12/09 12:42:28 sas Exp $ */
 
 /* {{{ includes */
 
@@ -83,44 +83,6 @@
 
 /* }}} */
 
-/* {{{ Format string numbers */
-enum {
-       FMT_MSG_CHAN = 0,
-       FMT_MSG_PRIV_TO_ME,
-       FMT_MSG_PRIV_FROM_ME,
-       FMT_MSG_LEAVE,
-       FMT_MSG_JOIN,
-       FMT_MSG_KICK,
-       FMT_MSG_TOPIC,
-       FMT_MSG_ERROR,
-       FMT_MSG_FATAL_ERROR,
-       FMT_MSG_JOIN_LIST_END,
-       FMT_MSG_SELF_PART,
-       FMT_MSG_NICK,
-       FMT_MSG_QUIT,
-       FMT_MSG_MASS_JOIN_BEGIN,
-       FMT_MSG_MASS_JOIN_ELEMENT,
-       FMT_MSG_MASS_JOIN_END,
-       FMT_MSG_WHOIS_USER,
-       FMT_MSG_WHOIS_SERVER,
-       FMT_MSG_WHOIS_IDLE,
-       FMT_MSG_WHOIS_CHANNEL,
-       FMT_MSG_WHOIS_END,
-       FMT_MSG_MODE_VOICE,
-       FMT_MSG_MODE_OP,
-       FMT_MSG_BANLIST,
-       FMT_MSG_BANLIST_END,
-       FMT_MSG_DISCONNECTED,
-       FMT_MSG_LIST,
-       FMT_MSG_LISTEND,
-       FMT_MSG_WHOREPLY1,
-       FMT_MSG_WHOREPLY2,
-       FMT_MSG_ENDOFWHO,
-       FMT_MSG_INVITE,
-       NO_FMTS
-};
-/* }}} */
-
 /* {{{ ircg_functions[] */
 function_entry ircg_functions[] = {
 #ifdef IRCG_PENDING_URL
@@ -177,10 +139,6 @@
 #endif
 
 typedef struct {
-       format_msg_t *fmt_msgs[NO_FMTS];
-} php_fmt_msgs_t;
-
-typedef struct {
        irconn_t conn;
        smart_str buffer;
        time_t login;
@@ -209,7 +167,6 @@
        char *realname; /* dito */
 } php_irconn_t;
 
-static php_fmt_msgs_t fmt_msgs_default_compiled;
 
 #define format_msg php_ircg_format_msg
 
@@ -1754,7 +1711,7 @@
        }
 
        if (!fmt_msgs)
-               fmt_msgs = &fmt_msgs_default_compiled;
+               fmt_msgs = &php_ircg->fmt_msgs_default_compiled;
 
        /*
         * conn must be able to live longer than the hash entry in h_irconn,
@@ -2126,20 +2083,23 @@
 #endif
 /* }}} */
 
-static void setup(int stage)
+static int init(void *p)
 {
-       if (stage == 0) {
-               int i;
+       int i;
 
-               php_ircg = IRCG_SHARED_ALLOC(sizeof *php_ircg);
-               memset(php_ircg, 0, sizeof *php_ircg);
-       
-               IRCG_LOCK_INIT(php_ircg->fmt_msgs_lock);
-               IRCG_LOCK_INIT(php_ircg->error_msgs_lock);
+       IRCG_LOCK_INIT(php_ircg->fmt_msgs_lock);
+       IRCG_LOCK_INIT(php_ircg->error_msgs_lock);
 
-               for (i = 0; i < NO_FMTS; i++) {
-                       php_ircg_token_compiler(fmt_msgs_default[i], 
&fmt_msgs_default_compiled.fmt_msgs[i]);
-               }
+       for (i = 0; i < NO_FMTS; i++) {
+               php_ircg_token_compiler(fmt_msgs_default[i], 
+&php_ircg->fmt_msgs_default_compiled.fmt_msgs[i]);
+       }
+       return 0;
+}
+       
+static void setup(int stage)
+{
+       if (stage == 0) {
+               ircg_fetch_area("php-ircg-main", &php_ircg, sizeof *php_ircg, init);
        } else if (stage == 1) {
                php_ircg_cache_entries = malloc(sizeof(struct cache_entry) * 
NR_CACHE_ENTRIES);
                memset(php_ircg_cache_entries, 0, sizeof(struct cache_entry) * 
NR_CACHE_ENTRIES);
Index: php4/ext/ircg/php_ircg_private.h
diff -u php4/ext/ircg/php_ircg_private.h:1.4 php4/ext/ircg/php_ircg_private.h:1.5
--- php4/ext/ircg/php_ircg_private.h:1.4        Wed Dec  4 04:53:20 2002
+++ php4/ext/ircg/php_ircg_private.h    Mon Dec  9 07:42:28 2002
@@ -10,6 +10,8 @@
 #define USE_IRCONN_MANAGEMENT
 #define USE_FD2IRCONN
 
+#define ircg_fetch_area(name, ptr, size, fn) do { *(ptr) = IRCG_SHARED_ALLOC((size)); 
+memset(*(ptr), 0, (size)); (fn)(*(ptr)); } while (0)
+
 /* provide dummy definitions */
 #include "php_ircg_hash.h"
 #include "php_ircg_lock.h"
@@ -22,6 +24,13 @@
 
 #include "php_ircg_error.h"
 
+#include "php_ircg_tokenizer.h"
+#include "php_ircg_formats.h"
+
+typedef struct {
+       format_msg_t *fmt_msgs[NO_FMTS];
+} php_fmt_msgs_t;
+
 struct php_ircg_global {
        ircg_hash_table h_fmt_msgs;
 
@@ -38,6 +47,8 @@
 
        struct errormsg *error_msgs;
        IRCG_LOCK(error_msgs_lock);
+       
+       php_fmt_msgs_t fmt_msgs_default_compiled;
 };
 
 extern struct php_ircg_global *php_ircg;
Index: php4/ext/ircg/php_ircg_tokenizer.h
diff -u php4/ext/ircg/php_ircg_tokenizer.h:1.1 php4/ext/ircg/php_ircg_tokenizer.h:1.2
--- php4/ext/ircg/php_ircg_tokenizer.h:1.1      Tue Dec  3 05:13:36 2002
+++ php4/ext/ircg/php_ircg_tokenizer.h  Mon Dec  9 07:42:28 2002
@@ -1,3 +1,6 @@
+#ifndef PHP_IRCG_TOKENIZER_H
+#define PHP_IRCG_TOKENIZER_H
+
 #include "ext/standard/php_smart_str_public.h"
 
 typedef struct {
@@ -9,7 +12,7 @@
        } para;
 } token_t;
 
-typedef struct {
+typedef struct format_msg {
        int ntoken;
        token_t t[1];
 } format_msg_t;
@@ -46,3 +49,4 @@
 void php_ircg_free_fmt_msg(format_msg_t *f);
 
 
+#endif

Index: php4/ext/ircg/php_ircg_formats.h
+++ php4/ext/ircg/php_ircg_formats.h
/* {{{ Format string numbers */
enum {
        FMT_MSG_CHAN = 0,
        FMT_MSG_PRIV_TO_ME,
        FMT_MSG_PRIV_FROM_ME,
        FMT_MSG_LEAVE,
        FMT_MSG_JOIN,
        FMT_MSG_KICK,
        FMT_MSG_TOPIC,
        FMT_MSG_ERROR,
        FMT_MSG_FATAL_ERROR,
        FMT_MSG_JOIN_LIST_END,
        FMT_MSG_SELF_PART,
        FMT_MSG_NICK,
        FMT_MSG_QUIT,
        FMT_MSG_MASS_JOIN_BEGIN,
        FMT_MSG_MASS_JOIN_ELEMENT,
        FMT_MSG_MASS_JOIN_END,
        FMT_MSG_WHOIS_USER,
        FMT_MSG_WHOIS_SERVER,
        FMT_MSG_WHOIS_IDLE,
        FMT_MSG_WHOIS_CHANNEL,
        FMT_MSG_WHOIS_END,
        FMT_MSG_MODE_VOICE,
        FMT_MSG_MODE_OP,
        FMT_MSG_BANLIST,
        FMT_MSG_BANLIST_END,
        FMT_MSG_DISCONNECTED,
        FMT_MSG_LIST,
        FMT_MSG_LISTEND,
        FMT_MSG_WHOREPLY1,
        FMT_MSG_WHOREPLY2,
        FMT_MSG_ENDOFWHO,
        FMT_MSG_INVITE,
        NO_FMTS
};
/* }}} */




-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to