/[weechat]/weechat/src/plugins/scripts/python/weechat-python.c
ViewVC logotype

Diff of /weechat/src/plugins/scripts/python/weechat-python.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by kolter, Wed Oct 19 15:43:13 2005 UTC revision 1.6 by kolter, Thu Oct 20 09:19:10 2005 UTC
# Line 560  weechat_python_load (t_weechat_plugin *p Line 560  weechat_python_load (t_weechat_plugin *p
560  {  {
561      FILE *fp;      FILE *fp;
562      PyThreadState *python_current_interpreter;      PyThreadState *python_current_interpreter;
563      PyObject *outputs;      PyObject *weechat_module, *weechat_outputs;
564            
565      plugin->printf_server (plugin, "Loading Python script \"%s\"", filename);      plugin->printf_server (plugin, "Loading Python script \"%s\"", filename);
566            
# Line 590  weechat_python_load (t_weechat_plugin *p Line 590  weechat_python_load (t_weechat_plugin *p
590      }      }
591    
592      PyThreadState_Swap (python_current_interpreter);      PyThreadState_Swap (python_current_interpreter);
593        
594        weechat_module = Py_InitModule ("weechat", weechat_python_funcs);
595    
596      if (Py_InitModule ("weechat", weechat_python_funcs) == NULL)      if ( weechat_module == NULL)
597      {      {
598          plugin->printf_server (plugin,          plugin->printf_server (plugin,
599                                 "Python error: unable to initialize WeeChat module");                                 "Python error: unable to initialize WeeChat module");
# Line 603  weechat_python_load (t_weechat_plugin *p Line 605  weechat_python_load (t_weechat_plugin *p
605          return 0;          return 0;
606      }      }
607    
608      outputs = Py_InitModule("weechatOutputs", weechat_python_output_funcs);      weechat_outputs = Py_InitModule("weechatOutputs", weechat_python_output_funcs);
609      if (outputs == NULL)      if (weechat_outputs == NULL)
610      {      {
611          plugin->printf_server (plugin,          plugin->printf_server (plugin,
612                                 "Python warning: unable to redirect stdout and stderr");                                 "Python warning: unable to redirect stdout and stderr");
613      }      }
614      else      else
615      {      {
616          if (PySys_SetObject("stdout", outputs) == -1)          if (PySys_SetObject("stdout", weechat_outputs) == -1)
617              plugin->printf_server (plugin,              plugin->printf_server (plugin,
618                                     "Python warning: unable to redirect stdout");                                     "Python warning: unable to redirect stdout");
619          if (PySys_SetObject("stderr", outputs) == -1)          if (PySys_SetObject("stderr", weechat_outputs) == -1)
620              plugin->printf_server (plugin,              plugin->printf_server (plugin,
621                                     "Python warning: unable to redirect stderr");                                     "Python warning: unable to redirect stderr");
622      }      }
# Line 632  weechat_python_load (t_weechat_plugin *p Line 634  weechat_python_load (t_weechat_plugin *p
634          PyThreadState_Delete (python_current_interpreter);          PyThreadState_Delete (python_current_interpreter);
635          PyEval_ReleaseLock ();          PyEval_ReleaseLock ();
636          fclose (fp);          fclose (fp);
637            /* if script was registered, removing from list */
638            if (python_current_script != NULL)
639                weechat_script_remove (plugin, &python_scripts, python_current_script);
640          return 0;          return 0;
641      }      }
642            
# Line 671  weechat_python_unload (t_weechat_plugin Line 676  weechat_python_unload (t_weechat_plugin
676            
677      if (script->shutdown_func[0])      if (script->shutdown_func[0])
678          weechat_python_exec (plugin, script, script->shutdown_func, "", "");          weechat_python_exec (plugin, script, script->shutdown_func, "", "");
679        
680        PyEval_AcquireLock ();
681      PyThreadState_Swap (NULL);      PyThreadState_Swap (NULL);
682      PyThreadState_Clear (script->interpreter);      PyThreadState_Clear (script->interpreter);
683      PyThreadState_Delete (script->interpreter);      PyThreadState_Delete (script->interpreter);
684        PyEval_ReleaseLock ();
685            
686      weechat_script_remove (plugin, &python_scripts, script);      weechat_script_remove (plugin, &python_scripts, script);
687  }  }
# Line 874  weechat_python_cmd (t_weechat_plugin *pl Line 881  weechat_python_cmd (t_weechat_plugin *pl
881  int  int
882  weechat_plugin_init (t_weechat_plugin *plugin)  weechat_plugin_init (t_weechat_plugin *plugin)
883  {  {
884        char *argv[] = { "__weechat_plugin__" , NULL };
885    
886      python_plugin = plugin;      python_plugin = plugin;
887            
888      plugin->printf_server (plugin, "Loading Python module \"weechat\"");      plugin->printf_server (plugin, "Loading Python module \"weechat\"");
# Line 886  weechat_plugin_init (t_weechat_plugin *p Line 895  weechat_plugin_init (t_weechat_plugin *p
895          return 0;          return 0;
896      }      }
897            
898        PySys_SetArgv(1, argv);
899    
900      PyEval_InitThreads();      PyEval_InitThreads();
901            
902      python_mainThreadState = PyThreadState_Get();      python_mainThreadState = PyThreadState_Get();
# Line 924  weechat_plugin_end (t_weechat_plugin *pl Line 935  weechat_plugin_end (t_weechat_plugin *pl
935      /* unload all scripts */      /* unload all scripts */
936      weechat_python_unload_all (plugin);      weechat_python_unload_all (plugin);
937            
938        PyEval_AcquireLock ();
939    
940      /* free Python interpreter */      /* free Python interpreter */
941      if (python_mainThreadState != NULL)      if (python_mainThreadState != NULL)
942      {      {
943          PyThreadState_Swap (python_mainThreadState);          PyThreadState_Swap (python_mainThreadState);
944          python_mainThreadState = NULL;          python_mainThreadState = NULL;
945      }      }
946        
947      Py_Finalize ();      Py_Finalize ();
948      if (Py_IsInitialized () != 0)      if (Py_IsInitialized () != 0)
949          python_plugin->printf_server (python_plugin,          python_plugin->printf_server (python_plugin,

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26