diff -cp python-gdb-7.2/py-cmd.c python-gdb/py-cmd.c
*** python-gdb-7.2/py-cmd.c	Fri Sep 10 09:27:40 2010
--- python-gdb/py-cmd.c	Fri Sep 10 11:08:00 2010
*************** gdbpy_initialize_commands (void)
*** 526,531 ****
--- 526,541 ----
    if (PyType_Ready (&cmdpy_object_type) < 0)
      return;
  
+ #ifdef __MINGW32__
+   /* 
+ 	 I have to modify some gdb python files because the files 'python-function.c', python-cmd.c and python-frame.c define some 'static PyTypeObject'.
+      The field 'tp_new' of these static variables statically initialized with the python 'PyType_GenericNew' function. 
+      In Windows port of Python, this function is declared as a dllimport function and can not be copied at compilation time in a static variable.
+      For these 3 files, I modify the source code to initialize the 'tp_new' fields to '0' in the static variables and to affect the proper 'PyType_GenericNew' value in the 'gdbpy_initialize_commands', 'gdbpy_initialize_frames' and 'gdbpy_initialize_functions'.
+   */
+   cmdpy_object_type.tp_new = PyType_GenericNew;
+ #endif
+ 
    /* Note: alias and user are special; pseudo appears to be unused,
       and there is no reason to expose tui or xdb, I think.  */
    if (PyModule_AddIntConstant (gdb_module, "COMMAND_NONE", no_class) < 0
*************** static PyTypeObject cmdpy_object_type =
*** 610,616 ****
--- 620,630 ----
    0,				  /* tp_dictoffset */
    cmdpy_init,			  /* tp_init */
    0,				  /* tp_alloc */
+ #ifdef __MINGW32__
+   0				  /* tp_new */
+ #else
    PyType_GenericNew		  /* tp_new */
+ #endif
  };
  
  
diff -cp python-gdb-7.2/py-frame.c python-gdb/py-frame.c
*** python-gdb-7.2/py-frame.c	Fri Sep 10 09:27:40 2010
--- python-gdb/py-frame.c	Fri Sep 10 11:08:00 2010
*************** gdbpy_initialize_frames (void)
*** 568,573 ****
--- 568,583 ----
    if (PyType_Ready (&frame_object_type) < 0)
      return;
  
+ #ifdef __MINGW32__
+   /* 
+      I have to modify some gdb python files because the files 'python-function.c', python-cmd.c and python-frame.c define some 'static PyTypeObject'.
+      The field 'tp_new' of these static variables statically initialized with the python 'PyType_GenericNew' function. 
+      In Windows port of Python, this function is declared as a dllimport function and can not be copied at compilation time in a static variable.
+      For these 3 files, I modify the source code to initialize the 'tp_new' fields to '0' in the static variables and to affect the proper 'PyType_GenericNew' value in the 'gdbpy_initialize_commands', 'gdbpy_initialize_frames' and 'gdbpy_initialize_functions'.
+   */
+   frame_object_type.tp_new = PyType_GenericNew;
+ #endif
+ 
    /* Note: These would probably be best exposed as class attributes of Frame,
       but I don't know how to do it except by messing with the type's dictionary.
       That seems too messy.  */
*************** static PyTypeObject frame_object_type = 
*** 672,676 ****
--- 682,690 ----
    0,				  /* tp_dictoffset */
    0,				  /* tp_init */
    0,				  /* tp_alloc */
+ #ifdef __MINGW32__
+   0				  /* tp_new */
+ #else
    PyType_GenericNew		  /* tp_new */
+ #endif
  };
diff -cp python-gdb-7.2/py-function.c python-gdb/py-function.c
*** python-gdb-7.2/py-function.c	Fri Sep 10 09:27:40 2010
--- python-gdb/py-function.c	Fri Sep 10 11:08:00 2010
*************** gdbpy_initialize_functions (void)
*** 130,135 ****
--- 130,145 ----
    if (PyType_Ready (&fnpy_object_type) < 0)
      return;
  
+ #ifdef __MINGW32__
+   /* 
+      I have to modify some gdb python files because the files 'python-function.c', python-cmd.c and python-frame.c define some 'static PyTypeObject'.
+      The field 'tp_new' of these static variables statically initialized with the python 'PyType_GenericNew' function. 
+      In Windows port of Python, this function is declared as a dllimport function and can not be copied at compilation time in a static variable.
+      For these 3 files, I modify the source code to initialize the 'tp_new' fields to '0' in the static variables and to affect the proper 'PyType_GenericNew' value in the 'gdbpy_initialize_commands', 'gdbpy_initialize_frames' and 'gdbpy_initialize_functions'.
+   */
+   fnpy_object_type.tp_new = PyType_GenericNew;
+ #endif
+ 
    Py_INCREF (&fnpy_object_type);
    PyModule_AddObject (gdb_module, "Function", (PyObject *) &fnpy_object_type);
  }
*************** static PyTypeObject fnpy_object_type =
*** 176,180 ****
--- 186,194 ----
    0,				  /* tp_dictoffset */
    fnpy_init,			  /* tp_init */
    0,				  /* tp_alloc */
+ #ifdef __MINGW32__
+   0				  /* tp_new */
+ #else
    PyType_GenericNew		  /* tp_new */
+ #endif
  };
diff -cp python-gdb-7.2/py-inferior.c python-gdb/py-inferior.c
*** python-gdb-7.2/py-inferior.c	Fri Sep 10 09:27:40 2010
--- python-gdb/py-inferior.c	Fri Sep 10 11:08:00 2010
*************** gdbpy_initialize_inferior (void)
*** 593,598 ****
--- 593,608 ----
    if (PyType_Ready (&membuf_object_type) < 0)
      return;
  
+ #ifdef __MINGW32__
+   /* 
+      I have to modify some gdb python files because the files 'python-function.c', python-cmd.c and python-frame.c define some 'static PyTypeObject'.
+      The field 'tp_new' of these static variables statically initialized with the python 'PyType_GenericNew' function. 
+      In Windows port of Python, this function is declared as a dllimport function and can not be copied at compilation time in a static variable.
+      For these 3 files, I modify the source code to initialize the 'tp_new' fields to '0' in the static variables and to affect the proper 'PyType_GenericNew' value in the 'gdbpy_initialize_commands', 'gdbpy_initialize_frames' and 'gdbpy_initialize_functions'.
+   */
+   membuf_object_type.tp_new = PyType_GenericNew;
+ #endif
+ 
    Py_INCREF (&membuf_object_type);
    PyModule_AddObject (gdb_module, "Membuf", (PyObject *)
  		      &membuf_object_type);
*************** static PyTypeObject membuf_object_type =
*** 724,728 ****
--- 734,742 ----
    0,				  /* tp_dictoffset */
    0,				  /* tp_init */
    0,				  /* tp_alloc */
+ #ifdef __MINGW32__
+   0				  /* tp_new */
+ #else
    PyType_GenericNew		  /* tp_new */
+ #endif
  };
diff -cp python-gdb-7.2/py-param.c python-gdb/py-param.c
*** python-gdb-7.2/py-param.c	Fri Sep 10 09:27:40 2010
--- python-gdb/py-param.c	Fri Sep 10 11:08:00 2010
*************** gdbpy_initialize_parameters (void)
*** 555,560 ****
--- 555,570 ----
    if (PyType_Ready (&parmpy_object_type) < 0)
      return;
  
+ #ifdef __MINGW32__
+   /* 
+      I have to modify some gdb python files because the files 'python-function.c', python-cmd.c and python-frame.c define some 'static PyTypeObject'.
+      The field 'tp_new' of these static variables statically initialized with the python 'PyType_GenericNew' function. 
+      In Windows port of Python, this function is declared as a dllimport function and can not be copied at compilation time in a static variable.
+      For these 3 files, I modify the source code to initialize the 'tp_new' fields to '0' in the static variables and to affect the proper 'PyType_GenericNew' value in the 'gdbpy_initialize_commands', 'gdbpy_initialize_frames' and 'gdbpy_initialize_functions'.
+   */
+   parmpy_object_type.tp_new = PyType_GenericNew;
+ #endif
+ 
    set_doc_cst = PyString_FromString ("set_doc");
    if (! set_doc_cst)
      return;
*************** static PyTypeObject parmpy_object_type =
*** 617,621 ****
--- 627,635 ----
    0,				  /* tp_dictoffset */
    parmpy_init,			  /* tp_init */
    0,				  /* tp_alloc */
+ #ifdef __MINGW32__
+   0				  /* tp_new */
+ #else
    PyType_GenericNew		  /* tp_new */
+ #endif
  };
diff -cp python-gdb-7.2/py-prettyprint.c python-gdb/py-prettyprint.c
*** python-gdb-7.2/py-prettyprint.c	Fri Sep 10 09:27:40 2010
--- python-gdb/py-prettyprint.c	Fri Sep 10 11:08:00 2010
*************** apply_val_pretty_printer (struct type *t
*** 617,622 ****
--- 617,627 ----
    struct cleanup *cleanups;
    int result = 0;
    int is_py_none = 0;
+ 
+   /* Do not enable python scripting if the PYTHONHOME variable is undefined */
+   if (have_python() == 0)
+     return 0;
+ 
    cleanups = ensure_python_env (gdbarch, language);
  
    /* Instantiate the printer.  */
diff -cp python-gdb-7.2/py-value.c python-gdb/py-value.c
*** python-gdb-7.2/py-value.c	Fri Sep 10 09:27:40 2010
--- python-gdb/py-value.c	Fri Sep 10 11:08:00 2010
*************** preserve_python_values (struct objfile *
*** 158,163 ****
--- 158,167 ----
  {
    value_object *iter;
  
+   /* Do not enable python scripting if the PYTHONHOME variable is undefined */
+   if (have_python() == 0)
+     return;
+ 
    for (iter = values_in_python; iter; iter = iter->next)
      preserve_one_value (iter->value, objfile, copied_types);
  }
diff -cp python-gdb-7.2/python-config.py python-gdb/python-config.py
*** python-gdb-7.2/python-config.py	Fri Sep 10 09:27:40 2010
--- python-gdb/python-config.py	Fri Sep 10 11:08:00 2010
*************** elif opt in ('--libs', '--ldflags'):
*** 50,54 ****
--- 50,59 ----
      # shared library in prefix/lib/.
      if opt == '--ldflags' and not getvar('Py_ENABLE_SHARED'):
          libs.insert(0, '-L' + getvar('LIBPL'))
+ 
+     # Get python shared library path
+     if opt == '--ldflags' and getvar('Py_ENABLE_SHARED'):
+         libs.insert(0, '-L' + getvar('LIBDIR'))        
+         
      print ' '.join(libs)
  
diff -cp python-gdb-7.2/python-internal.h python-gdb/python-internal.h
*** python-gdb-7.2/python-internal.h	Fri Sep 10 09:27:40 2010
--- python-gdb/python-internal.h	Fri Sep 10 11:08:00 2010
***************
*** 26,31 ****
--- 26,34 ----
     needed by pyport.h.  */
  #include <stdint.h>
  
+ /* Do not enable python scripting if the PYTHONHOME variable is undefined */
+ int have_python();
+ 
  /* /usr/include/features.h on linux systems will define _POSIX_C_SOURCE
     if it sees _GNU_SOURCE (which config.h will define).
     pyconfig.h defines _POSIX_C_SOURCE to a different value than
diff -cp python-gdb-7.2/python.c python-gdb/python.c
*** python-gdb-7.2/python.c	Fri Sep 10 09:27:40 2010
--- python-gdb/python.c	Fri Sep 10 11:08:00 2010
*************** PyObject *gdbpy_enabled_cst;
*** 61,66 ****
--- 61,73 ----
  /* The GdbError exception.  */
  PyObject *gdbpy_gdberror_exc;
  
+ /* Do not enable python scripting if the PYTHONHOME variable is undefined */
+ int havePython = 1;
+ int have_python()
+ {
+   return havePython;
+ }
+ 
  /* Architecture and language to be used in callbacks from
     the Python interpreter.  */
  struct gdbarch *python_gdbarch;
*************** eval_python_from_control_command (struct
*** 147,152 ****
--- 154,165 ----
    char *script;
    struct cleanup *cleanup;
  
+   /* Do not enable python scripting if the PYTHONHOME variable is undefined */
+   if (havePython == 0)
+     {
+       return;
+     }
+ 
    if (cmd->body_count != 1)
      error (_("Invalid \"python\" block structure."));
  
*************** python_command (char *arg, int from_tty)
*** 171,176 ****
--- 184,209 ----
  {
    struct cleanup *cleanup;
  
+   /* Do not enable python scripting if the PYTHONHOME variable is undefined */
+ #ifdef HAVE_PYTHON
+   if (havePython == 0)
+     {
+       while (arg && *arg && isspace (*arg))
+ 	++arg;
+       if (arg && *arg)
+ 	error (_("Python scripting is not supported when the PYTHONHOME variable is undefined."));
+       else
+ 	{
+ 	  struct command_line *l = get_command_line (python_control, "");
+ 	  struct cleanup *cleanups = make_cleanup_free_command_lines (&l);
+ 	  execute_control_command_untraced (l);
+ 	  do_cleanups (cleanups);
+ 	}
+       return;
+     }
+ #endif /* HAVE_PYTHON */
+ 
+ 
    cleanup = ensure_python_env (get_current_arch (), current_language);
    while (arg && *arg && isspace (*arg))
      ++arg;
*************** source_python_script (FILE *stream, cons
*** 403,413 ****
--- 436,467 ----
  {
    struct cleanup *cleanup;
  
+ #ifdef HAVE_PYTHON
+   /* Do not enable python scripting if the PYTHONHOME variable is undefined */
+   if (havePython == 0)
+     {
+       error (_("Python scripting is not supported when the PYTHONHOME variable is undefined."));
+       return;
+     }
+ #endif /* HAVE_PYTHON */
+ 
    cleanup = ensure_python_env (get_current_arch (), current_language);
  
+ #ifdef __MINGW32__
+   {
+     /* We can not use 'PyRun_SimpleFile' because Python may not be compiled using the same MSVCRT DLL than GDB
+        so the FILE* stream will not be known in this DLL. This generate an error when the MSVCRT will try to lock the file handle. */
+     PyObject* PyFileObject = PyFile_FromString( (char*) file, "r"); 
+     if (PyFileObject == NULL)
+       error (_("Could not source file %s."), file);
+     PyRun_SimpleFile(PyFile_AsFile(PyFileObject), file); 
+     Py_DECREF(PyFileObject);
+   }
+ #else
    /* Note: If an exception occurs python will print the traceback and
       clear the error indicator.  */
    PyRun_SimpleFile (stream, file);
+ #endif
  
    do_cleanups (cleanup);
  }
*************** source_python_script_for_objfile (struct
*** 516,524 ****
--- 570,590 ----
    cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
    gdbpy_current_objfile = objfile;
  
+ #ifdef __MINGW32__
+   {
+     /* We can not use 'PyRun_SimpleFile' because Python may not be compiled using the same MSVCRT DLL than GDB
+        so the FILE* stream will not be known in this DLL. This generate an error when the MSVCRT will try to lock the file handle. */
+     PyObject* PyFileObject = PyFile_FromString( (char*) file, "r"); 
+     if (PyFileObject == NULL)
+       error (_("Could not source file %s."), file);
+     PyRun_SimpleFile(PyFile_AsFile(PyFileObject), file); 
+     Py_DECREF(PyFileObject);
+   }
+ #else
    /* Note: If an exception occurs python will print the traceback and
       clear the error indicator.  */
    PyRun_SimpleFile (stream, file);
+ #endif
  
    do_cleanups (cleanups);
    gdbpy_current_objfile = NULL;
*************** extern initialize_file_ftype _initialize
*** 633,638 ****
--- 699,719 ----
  void
  _initialize_python (void)
  {
+   /* Do not enable python scripting if the PYTHONHOME variable is undefined */
+ #ifdef HAVE_PYTHON
+   if (getenv( "PYTHONHOME") == NULL)
+     {
+        havePython = 0;
+        add_com ("python", class_obscure, python_command,
+ 		_("\
+ Evaluate a Python command.\n\
+ \n\
+ Python scripting is not supported when the PYTHONHOME variable is undefined.")
+ 		);
+     }
+   else
+ #endif /* HAVE_PYTHON */
+ 
    add_com ("python", class_obscure, python_command,
  #ifdef HAVE_PYTHON
  	   _("\
*************** Enables or disables printing of Python s
*** 683,688 ****
--- 764,778 ----
    Py_SetProgramName (concat (ldirname (python_libdir), SLASH_STRING, "bin",
  			     SLASH_STRING, "python", NULL));
  #endif
+ 
+   /* Do not enable python scripting if the PYTHONHOME variable is undefined */
+ #ifdef HAVE_PYTHON
+   if (havePython == 0)
+     {
+       return;
+     }
+ #endif /* HAVE_PYTHON */
+ 
  
    Py_Initialize ();
    PyEval_InitThreads ();
