[Patches] PyMem [Windows] - PC/*

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Tue, 2 May 2000 14:11:40 +0200 (CEST)


[ PC/* ]

I forgot completely to inspect at the Windows specific code, sorry.
I hardly ever look at the PC/* directory. Here's the patch (this is
untested by me).

There are a couple of malloc/free calls, but I think they're fine
because they come in pairs. So at the end, the Windows patch is tiny.

-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252

--

Disclaimer:

I confirm that, to the best of my knowledge and belief, this contribution is
free of any claims of third parties under copyright, patent or other rights
or interests ("claims").  To the extent that I have any such claims, I
hereby grant to CNRI a nonexclusive, irrevocable, royalty-free, worldwide
license to reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part of the
Python software and its related documentation, or any derivative versions
thereof, at no cost to CNRI or its licensed users, and to authorize others
to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or not
to incorporate this contribution in the Python software and its related
documentation.  I further grant CNRI permission to use my name and other
identifying information provided to CNRI by me for use in connection with
the Python software and its related documentation.

-------------------------------[ cut here ]---------------------------
diff -cr PyCVS/PC/winreg.c PyMem/PC/winreg.c
*** PyCVS/PC/winreg.c	Sat Apr 29 00:24:10 2000
--- PyMem/PC/winreg.c	Tue May  2 13:50:57 2000
***************
*** 370,376 ****
  	PyHKEYObject *obkey = (PyHKEYObject *)ob;
  	if (obkey->hkey)
  		RegCloseKey((HKEY)obkey->hkey);
! 	PyMem_DEL(ob);
  }
  
  static int
--- 370,376 ----
  	PyHKEYObject *obkey = (PyHKEYObject *)ob;
  	if (obkey->hkey)
  		RegCloseKey((HKEY)obkey->hkey);
! 	PyObject_DEL(ob);
  }
  
  static int
***************
*** 604,615 ****
  PyObject *
  PyHKEY_FromHKEY(HKEY h)
  {
! 	PyHKEYObject *op = (PyHKEYObject *) malloc(sizeof(PyHKEYObject));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	op->ob_type = &PyHKEY_Type;
  	op->hkey = h;
- 	_Py_NewReference((PyObject *)op);
  	return (PyObject *)op;
  }
  
--- 604,617 ----
  PyObject *
  PyHKEY_FromHKEY(HKEY h)
  {
! 	PyHKEYObject *op;
! 
! 	/* PyObject_New is inlined */
! 	op = (PyHKEYObject *) PyObject_MALLOC(sizeof(PyHKEYObject));
  	if (op == NULL)
  		return PyErr_NoMemory();
! 	PyObject_INIT(op, &PyHKEY_Type);
  	op->hkey = h;
  	return (PyObject *)op;
  }
  
***************
*** 1348,1354 ****
  	Py_BEGIN_ALLOW_THREADS
  	rc = RegSetValueEx(hKey, valueName, 0, typ, data, len);
  	Py_END_ALLOW_THREADS
! 	PyMem_Free(data);
  	if (rc != ERROR_SUCCESS)
  		return PyErr_SetFromWindowsErrWithFunction(rc,
  							   "RegSetValueEx");
--- 1350,1356 ----
  	Py_BEGIN_ALLOW_THREADS
  	rc = RegSetValueEx(hKey, valueName, 0, typ, data, len);
  	Py_END_ALLOW_THREADS
! 	PyMem_DEL(data);
  	if (rc != ERROR_SUCCESS)
  		return PyErr_SetFromWindowsErrWithFunction(rc,
  							   "RegSetValueEx");