Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21379/win32/src
Modified Files:
win32security.i win32security_ds.cpp win32security_sspi.cpp
win32service.i
Log Message:
Fix 64-bit issues, and consolidate conversion functions into pywintypes
Index: win32security_ds.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security_ds.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** win32security_ds.cpp 3 Jun 2007 14:53:07 -0000 1.5
--- win32security_ds.cpp 12 Aug 2007 08:16:29 -0000 1.6
***************
*** 99,142 ****
}
- void PyWinObject_FreeWCHARArray(LPWSTR *wchars, DWORD str_cnt)
- {
- if (wchars!=NULL){
- for (DWORD wchar_index=0; wchar_index<str_cnt; wchar_index++)
- PyWinObject_FreeWCHAR(wchars[wchar_index]);
- free(wchars);
- }
- }
-
- BOOL PyWinObject_AsWCHARArray(PyObject *str_seq, LPWSTR **wchars, DWORD *str_cnt)
- {
- BOOL ret=FALSE;
- PyObject *str_tuple=NULL, *tuple_item;
- DWORD bufsize, tuple_index;
- *wchars=NULL;
- *str_cnt=0;
- if ((str_tuple=PySequence_Tuple(str_seq))==NULL)
- return FALSE;
- *str_cnt=PyTuple_Size(str_tuple);
- bufsize=*str_cnt * sizeof(LPWSTR);
- *wchars=(LPWSTR *)malloc(bufsize);
- if (*wchars==NULL){
- PyErr_Format(PyExc_MemoryError, "Unable to allocate %d bytes", bufsize);
- goto done;
- }
- ZeroMemory(*wchars, bufsize);
- for (tuple_index=0;tuple_index<*str_cnt;tuple_index++){
- tuple_item=PyTuple_GET_ITEM(str_tuple, tuple_index);
- if (!PyWinObject_AsWCHAR(tuple_item, &((*wchars)[tuple_index]), FALSE)){
- PyWinObject_FreeWCHARArray(*wchars, *str_cnt);
- *wchars=NULL;
- *str_cnt=0;
- goto done;
- }
- }
- ret=TRUE;
- done:
- Py_XDECREF(str_tuple);
- return ret;
- }
extern PyObject *PyDsGetSpn(PyObject *self, PyObject *args)
--- 99,102 ----
Index: win32security_sspi.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security_sspi.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** win32security_sspi.cpp 30 May 2007 06:51:48 -0000 1.8
--- win32security_sspi.cpp 12 Aug 2007 08:16:29 -0000 1.9
***************
*** 423,436 ****
{
PySecBuffer *This=(PySecBuffer *)self;
! char *name, *value;
! Py_ssize_t valuelen;
name=PyString_AsString(obname);
if (name==NULL)
return -1;
if (strcmp(name,"Buffer")==0){
! if (PyString_AsStringAndSize(obvalue, &value, &valuelen)==-1)
return -1;
PSecBuffer psecbuffer=This->GetSecBuffer();
! if (valuelen>(Py_ssize_t)This->maxbufsize){
PyErr_Format(PyExc_ValueError, "Data size (%d) greater than allocated buffer size (%d)",valuelen, This->maxbufsize);
return -1;
--- 423,437 ----
{
PySecBuffer *This=(PySecBuffer *)self;
! char *name;
! void *value;
! DWORD valuelen;
name=PyString_AsString(obname);
if (name==NULL)
return -1;
if (strcmp(name,"Buffer")==0){
! if (!PyWinObject_AsReadBuffer(obvalue, &value, &valuelen))
return -1;
PSecBuffer psecbuffer=This->GetSecBuffer();
! if (valuelen > This->maxbufsize){
PyErr_Format(PyExc_ValueError, "Data size (%d) greater than allocated buffer size (%d)",valuelen, This->maxbufsize);
return -1;
Index: win32service.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32service.i,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** win32service.i 3 Jun 2007 14:53:07 -0000 1.14
--- win32service.i 12 Aug 2007 08:16:29 -0000 1.15
***************
*** 711,767 ****
%{
- BOOL BuildDeps(PyObject *obDeps, TCHAR **ppDeps)
- {
- TCHAR *lpDeps = NULL;
- BOOL rc = FALSE;
- if (obDeps!=Py_None) {
- if (!PySequence_Check(obDeps)) {
- PyErr_SetString(PyExc_ValueError, "Dependencies must be None or a list of strings");
- goto cleanup;
- }
- int numStrings = PySequence_Length(obDeps);
- // Need to loop twice - once to get the buffer length
- int i, len = 0;
- for (i=0;i<numStrings;i++) {
- PyObject *obString = PySequence_GetItem(obDeps, i);
- if (obString==NULL)
- goto cleanup;
- if (!PyString_Check(obString)) {
- Py_DECREF(obString);
- PyErr_SetString(PyExc_ValueError, "The list items for Dependencies must all be strings");
- goto cleanup;
- }
- len += PyString_Size(obString) + 1;
- Py_DECREF(obString);
- }
- // Allocate the buffer
- lpDeps = new TCHAR[len+2]; // Double '\0' terminated
- TCHAR *p = lpDeps;
- for (i=0;i<numStrings;i++) {
- // We know the sequence is valid.
- PyObject *obString = PySequence_GetItem(obDeps, i);
- BSTR pStr;
- if (!PyWinObject_AsTCHAR(obString, &pStr)) {
- Py_DECREF(obString);
- goto cleanup;
- }
- size_t len = _tcslen(pStr);
- _tcsncpy(p, pStr, len);
- p += len;
- *p++ = L'\0';
- PyWinObject_FreeTCHAR(pStr);
- Py_DECREF(obString);
- }
- *p = L'\0'; // Add second terminator.
- }
- *ppDeps = lpDeps;
- rc = TRUE;
- cleanup:
- if (!rc) {
- delete [] lpDeps;
- }
- return rc;
- }
-
PyObject *MyCreateService(
SC_HANDLE hSCManager, // handle to service control manager database
--- 711,714 ----
***************
*** 785,789 ****
DWORD *pTagID = bFetchTag ? &tagID : NULL;
SC_HANDLE sh = 0;
! if (!BuildDeps(obDeps, &lpDeps))
goto cleanup;
--- 732,736 ----
DWORD *pTagID = bFetchTag ? &tagID : NULL;
SC_HANDLE sh = 0;
! if (!PyWinObject_AsMultipleString(obDeps, &lpDeps, TRUE))
goto cleanup;
***************
*** 796,805 ****
} else {
if (bFetchTag)
! rc = Py_BuildValue("Nl", PyWinLong_FromHANDLE(sh), tagID);
else
! rc = PyWinLong_FromHANDLE(sh);
}
cleanup:
! delete [] lpDeps;
return rc;
--- 743,752 ----
} else {
if (bFetchTag)
! rc = Py_BuildValue("Nl", PyWinObject_FromSC_HANDLE(sh), tagID);
else
! rc = PyWinObject_FromSC_HANDLE(sh);
}
cleanup:
! PyWinObject_FreeMultipleString(lpDeps);
return rc;
***************
*** 825,829 ****
DWORD *pTagID = bFetchTag ? &tagID : NULL;
SC_HANDLE sh = 0;
! if (!BuildDeps(obDeps, &lpDeps))
goto cleanup;
--- 772,776 ----
DWORD *pTagID = bFetchTag ? &tagID : NULL;
SC_HANDLE sh = 0;
! if (!PyWinObject_AsMultipleString(obDeps, &lpDeps, TRUE))
goto cleanup;
***************
*** 840,844 ****
}
cleanup:
! delete [] lpDeps;
return rc;
--- 787,791 ----
}
cleanup:
! PyWinObject_FreeMultipleString(lpDeps);
return rc;
***************
*** 847,884 ****
PyObject *MyStartService( SC_HANDLE scHandle, PyObject *serviceArgs )
{
! LPTSTR *pArgs;
DWORD numStrings = 0;
! if (serviceArgs==Py_None)
! pArgs = NULL;
! else if (!PySequence_Check(serviceArgs)) {
! PyErr_SetString(PyExc_ValueError, "Service arguments must be list of strings.");
return NULL;
! } else {
! numStrings = PySequence_Length(serviceArgs);
! pArgs = new LPTSTR [numStrings];
! if (pArgs==NULL) {
! PyErr_SetString(PyExc_MemoryError, "Allocating argument arrays");
! return NULL;
! }
! for (DWORD i=0;i<numStrings;i++) {
! PyObject *obString = PySequence_GetItem(serviceArgs, (int)i);
! if (obString==NULL) {
! delete [] pArgs;
! return NULL;
! }
! pArgs[i] = NULL;
! PyWinObject_AsTCHAR(obString, pArgs+i);
! Py_DECREF(obString);
! }
! }
PyObject *rc;
! if (StartService(scHandle, numStrings, (LPCTSTR *)pArgs)) {
rc = Py_None;
Py_INCREF(Py_None);
} else
rc = PyWin_SetAPIError("StartService");
! for (DWORD i=0;i<numStrings;i++)
! PyWinObject_FreeTCHAR(pArgs[i]);
! delete [] pArgs;
return rc;
}
--- 794,809 ----
PyObject *MyStartService( SC_HANDLE scHandle, PyObject *serviceArgs )
{
! LPWSTR *pArgs;
DWORD numStrings = 0;
! if (!PyWinObject_AsWCHARArray(serviceArgs, &pArgs, &numStrings, TRUE))
return NULL;
!
PyObject *rc;
! if (StartService(scHandle, numStrings, (LPCWSTR *)pArgs)) {
rc = Py_None;
Py_INCREF(Py_None);
} else
rc = PyWin_SetAPIError("StartService");
! PyWinObject_FreeWCHARArray(pArgs, numStrings);
return rc;
}
***************
*** 1488,1506 ****
BOOL PyWinObject_AsSC_ACTIONS(PyObject *obActions, SC_ACTION **ppActions, LPDWORD cActions)
{
! static char* err="SC_ACTIONS must be a tuple of 2-tuples ((int, int),...)";
DWORD action_ind;
BOOL ret=TRUE;
SC_ACTION *pAction;
if (obActions==Py_None){
*ppActions=NULL;
return TRUE;
}
! if (!PyTuple_Check(obActions)){
! PyErr_SetString(PyExc_TypeError,err);
return FALSE;
! }
! *cActions=PyTuple_Size(obActions);
*ppActions=(SC_ACTION *)malloc(*cActions*sizeof(SC_ACTION));
if (*ppActions==NULL){
PyErr_Format(PyExc_MemoryError,"Unable to allocate %d SC_ACTION structures", *cActions);
return FALSE;
--- 1413,1432 ----
BOOL PyWinObject_AsSC_ACTIONS(PyObject *obActions, SC_ACTION **ppActions, LPDWORD cActions)
{
! static char* err="SC_ACTIONS must be a sequence of 2-tuples ((int, int),...)";
DWORD action_ind;
BOOL ret=TRUE;
SC_ACTION *pAction;
if (obActions==Py_None){
+ *cActions=0;
*ppActions=NULL;
return TRUE;
}
! PyObject *actions_tuple=PyWinSequence_Tuple(obActions, cActions);
! if (actions_tuple==NULL)
return FALSE;
!
*ppActions=(SC_ACTION *)malloc(*cActions*sizeof(SC_ACTION));
if (*ppActions==NULL){
+ Py_DECREF(actions_tuple);
PyErr_Format(PyExc_MemoryError,"Unable to allocate %d SC_ACTION structures", *cActions);
return FALSE;
***************
*** 1508,1512 ****
pAction=*ppActions;
for (action_ind=0;action_ind<*cActions;action_ind++){
! ret=PyWinObject_AsSC_ACTION(PyTuple_GET_ITEM(obActions, action_ind), pAction);
if (!ret){
free(*ppActions);
--- 1434,1438 ----
pAction=*ppActions;
for (action_ind=0;action_ind<*cActions;action_ind++){
! ret=PyWinObject_AsSC_ACTION(PyTuple_GET_ITEM(actions_tuple, action_ind), pAction);
if (!ret){
free(*ppActions);
***************
*** 1517,1520 ****
--- 1443,1447 ----
pAction++;
}
+ Py_DECREF(actions_tuple);
return ret;
}
Index: win32security.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security.i,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** win32security.i 8 Aug 2007 08:43:50 -0000 1.44
--- win32security.i 12 Aug 2007 08:16:29 -0000 1.45
***************
*** 331,349 ****
}
- // Converts sequence into a tuple and verifies that length fits in length variable
- PyObject *PyWinSequence_Tuple(PyObject *obseq, DWORD *len)
- {
- PyObject *obtuple=PySequence_Tuple(obseq);
- if (obtuple==NULL)
- return NULL;
- Py_ssize_t py_len=PyTuple_GET_SIZE(obtuple);
- if (py_len > MAXDWORD){
- Py_DECREF(obtuple);
- return PyErr_Format(PyExc_ValueError, "Sequence can contain at most %d items", MAXDWORD);
- }
- *len=(DWORD)py_len;
- return obtuple;
- }
-
BOOL PyWinObject_AsSID_AND_ATTRIBUTESArray(PyObject *obsids, PSID_AND_ATTRIBUTES *psid_attr_array, DWORD *sid_cnt)
{
--- 331,334 ----
|