Author: ArcRiley
Date: 2009-01-18 11:20:45 -0500 (Sun, 18 Jan 2009)
New Revision: 1495

Modified:
   trunk/concordance/src/_core/__init__.c
   trunk/concordance/src/_core/__init__.h
   trunk/concordance/src/_core/utils.h
   trunk/concordance/src/globals.h
   trunk/concordance/src/sockets/Socket.c
   trunk/concordance/src/sockets/__init__.c
   trunk/concordance/src/sockets/__init__.h
Log:
more work with the globals struct


Modified: trunk/concordance/src/_core/__init__.c
===================================================================
--- trunk/concordance/src/_core/__init__.c      2009-01-18 09:04:11 UTC (rev 
1494)
+++ trunk/concordance/src/_core/__init__.c      2009-01-18 16:20:45 UTC (rev 
1495)
@@ -30,7 +30,7 @@
                                                   gboolean is_running);
      void               g_main_loop_run          (GMainLoop *loop);
   */
-  concordGlobals *globals = (concordGlobals *)n;
+  concordGlobals *globals = (concordGlobals *) n;
 
   globals->mainloop = g_main_loop_new(globals->context, 0);
   g_main_loop_run(globals->mainloop);
@@ -42,6 +42,7 @@
   { NULL, NULL }
 };
 
+
 static struct PyModuleDef concord_Module = {
   PyModuleDef_HEAD_INIT,
   "_core",                             /*m_name*/
@@ -58,8 +59,8 @@
 PyMODINIT_FUNC
 PyInit__core(void) {                                                      /*\
   cdef :                                                                  \*/
-    PyObject* module;
-    concordGlobals *globals;
+    PyObject*           module;
+    concordGlobals*     globals;
 
   /* Initialize Glib threading support
 
@@ -100,9 +101,9 @@
   /* Retrieve the module-global state, which will be initialized to
      zero by the above based on m_size in concord_Module
     
-     void* PyModule_GetState(PyObject*);
+     void*              PyModule_GetState        (PyObject*);
    */
-  globals = (concordGlobals*)PyModule_GetState(module);
+  globals = (concordGlobals*) PyModule_GetState(module);
   
   /* We use a non-default context to avoid conflict with other glib-based
      Python packages which may have their own GMainLoop in other threads.

Modified: trunk/concordance/src/_core/__init__.h
===================================================================
--- trunk/concordance/src/_core/__init__.h      2009-01-18 09:04:11 UTC (rev 
1494)
+++ trunk/concordance/src/_core/__init__.h      2009-01-18 16:20:45 UTC (rev 
1495)
@@ -22,21 +22,6 @@
 #ifndef _CORE_INIT_H
 #define _CORE_INIT_H
 
-#include "Python.h"
-#include "glib.h"
-#include "gsasl.h"
-#include "expat.h"
-
-#ifdef MS_WINDOWS
-  #include <ws2tcpip.h>
-  #include <Winsock2.h>
-  WSADATA        wsaData;
-  gboolean       wsaInit;
-#else
-  #include <sys/socket.h>
-  #include <netdb.h>
-#endif
-
 #include "utils.h"
 #include "../globals.h"
 

Modified: trunk/concordance/src/_core/utils.h
===================================================================
--- trunk/concordance/src/_core/utils.h 2009-01-18 09:04:11 UTC (rev 1494)
+++ trunk/concordance/src/_core/utils.h 2009-01-18 16:20:45 UTC (rev 1495)
@@ -22,6 +22,8 @@
 #ifndef CONCORD_UTILS_H
 #define CONCORD_UTILS_H
 
+#include "../globals.h"
+
 GIOChannel*   concordAddSocket         (gint fd, GIOCondition condition,
                                         GSourceFunc callback, gpointer data,
                                         GMainContext* context);

Modified: trunk/concordance/src/globals.h
===================================================================
--- trunk/concordance/src/globals.h     2009-01-18 09:04:11 UTC (rev 1494)
+++ trunk/concordance/src/globals.h     2009-01-18 16:20:45 UTC (rev 1495)
@@ -22,10 +22,22 @@
 #ifndef GLOBALS_H
 #define GLOBALS_H
 
+#include "Python.h"
 #include "glib.h"
 #include "gsasl.h"
 #include "expat.h"
 
+#ifdef MS_WINDOWS
+  #include <ws2tcpip.h>
+  #include <Winsock2.h>
+  WSADATA        wsaData;
+  gboolean       wsaInit;
+#else
+  #include <sys/socket.h>
+  #include <netdb.h>
+#endif
+
+
 typedef struct {
   GMainContext*    context;              /* Concordance's Glib context */
   GMainLoop*       mainloop;             /* Concordance's Glib mainloop */

Modified: trunk/concordance/src/sockets/Socket.c
===================================================================
--- trunk/concordance/src/sockets/Socket.c      2009-01-18 09:04:11 UTC (rev 
1494)
+++ trunk/concordance/src/sockets/Socket.c      2009-01-18 16:20:45 UTC (rev 
1495)
@@ -36,9 +36,13 @@
     /* start with closed socket */
     self->sock = -1;
 
-    /* grab context from _core */
-    self->cntx = NULL;
+    /* Get context from global state
 
+       void*            PyModule_GetState        (PyObject*);
+    */
+    self->cntx = (*(concordGlobals**) PyModule_GetState(
+                  PyImport_ImportModule("concordance._core")))->context;
+
     return (PyObject*) self;
   }
 

Modified: trunk/concordance/src/sockets/__init__.c
===================================================================
--- trunk/concordance/src/sockets/__init__.c    2009-01-18 09:04:11 UTC (rev 
1494)
+++ trunk/concordance/src/sockets/__init__.c    2009-01-18 16:20:45 UTC (rev 
1495)
@@ -41,7 +41,8 @@
 PyMODINIT_FUNC
 PyInit_sockets(void) {                                                    /*\
   cdef :                                                                  \*/
-    PyObject* module;
+    gpointer            _core;
+    PyObject*           module;
 
   /* Initialize Glib threading support
 
@@ -56,7 +57,6 @@
   */
   if (!g_thread_supported()) g_thread_init(NULL);
 
-
   /* Initialize all types prior to module creation
 
      int PyType_Ready(PyTypeObject*)
@@ -69,15 +69,26 @@
     return NULL;
   if (PyType_Ready(&socketsClient_Type) < 0)
     return NULL;
-  
 
+  /* Get a handle to _core or fail
+
+     PyObject*          PyImport_ImportModule    (const char *name);
+  */
+  if (!(_core = (gpointer) PyImport_ImportModule("concordance._core")))
+    return NULL;
+
   /* Create concordance module object
 
      PyObject* PyModule_Create(struct PyModuleDef*)
   */
   module = PyModule_Create(&sockets_Module);
 
+  /* Record _core in module state so we can decref during garbage collection
 
+     void*              PyModule_GetState        (PyObject*);
+  */
+  *(gpointer*) PyModule_GetState(module) = _core;
+
   /* incref each extension type */
   Py_INCREF(&socketsSocket_Type);
   Py_INCREF(&socketsClient_Type);

Modified: trunk/concordance/src/sockets/__init__.h
===================================================================
--- trunk/concordance/src/sockets/__init__.h    2009-01-18 09:04:11 UTC (rev 
1494)
+++ trunk/concordance/src/sockets/__init__.h    2009-01-18 16:20:45 UTC (rev 
1495)
@@ -30,7 +30,7 @@
 
 typedef struct {
   PyObject_HEAD
-  GMainContext*         cntx;                    /* context from _core */
+  GMainContext*         cntx;          /* Concordance's Glib context */
   const gchar*          addr;
   gushort               port;
   int                   sock;
@@ -43,7 +43,7 @@
 
 typedef struct {
   PyObject_HEAD
-  GMainContext*         cntx;                    /* context from _core */
+  GMainContext*         cntx;          /* Concordance's Glib context */
   const gchar*          addr;
   gushort               port;
   int                   sock;

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to