Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 2 additions & 63 deletions Pythonwin/win32uimodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ ui_type::ui_type(const char *name, ui_type *pBase, Py_ssize_t typeSize,
tp_methods = methodList;
//#define funky_offsetof_weakreflist ((size_t) &((PyObject *)(ui_base_class *)0)->weakreflist)

#if (PY_VERSION_HEX < 0x03000000)
tp_flags |= Py_TPFLAGS_HAVE_WEAKREFS; // flag doesn't exist in py3k
#endif

tp_weaklistoffset -= pyobjOffset;
// cast away const, as Python doesnt use it.
tp_name = (char *)name;
Expand Down Expand Up @@ -350,12 +346,7 @@ int ui_base_class::setattro(PyObject *obname, PyObject *v)
CString ui_base_class::repr()
{
CString csRet;
#if (PY_VERSION_HEX < 0x03000000)
USES_CONVERSION;
csRet.Format(_T("object '%s'"), A2T((LPSTR)ob_type->tp_name));
#else
csRet.Format(_T("object '%S'"), ob_type->tp_name);
#endif
return csRet;
}
void ui_base_class::cleanup()
Expand Down Expand Up @@ -715,10 +706,6 @@ PyObject *Python_do_callback(PyObject *themeth, PyObject *thearglst)
}

// Copied from PyRecord.cpp, should move into pywintypes.h
#if (PY_VERSION_HEX < 0x03000000)
#define PyWinCoreString_ConcatAndDel PyBytes_ConcatAndDel
#define PyWinCoreString_Concat PyBytes_Concat
#else
// Unicode versions of '_Concat' etc have different sigs. Make them the
// same here...
void PyWinCoreString_Concat(register PyObject **pv, register PyObject *w)
Expand All @@ -733,14 +720,6 @@ void PyWinCoreString_Concat(register PyObject **pv, register PyObject *w)
*pv = tmp;
}

void PyWinCoreString_ConcatAndDel(register PyObject **pv, register PyObject *w)
{
PyWinCoreString_Concat(pv, w);
Py_XDECREF(w);
}

#endif

int Python_do_int_callback(PyObject *themeth, PyObject *thearglst)
{
int retVal = INT_MAX; // an identifiable, but unlikely genuine value
Expand Down Expand Up @@ -1479,7 +1458,7 @@ static PyObject *ui_get_resource(PyObject *self, PyObject *args)
return ret;
}

// @pymethod <o PyUnicode>|win32ui|LoadString|Loads a string from a resource file.
// @pymethod string|win32ui|LoadString|Loads a string from a resource file.
static PyObject *ui_load_string(PyObject *self, PyObject *args)
{
UINT stringId;
Expand Down Expand Up @@ -1852,29 +1831,6 @@ static PyObject *ui_translate_vk(PyObject *, PyObject *args)
return PyBytes_FromStringAndSize(result, nc);
}

/** Seems to have problems on 9x for some people (not me, though?)
// @pymethod <o PyUnicode>/None|win32ui|TranslateVirtualKeyW|
static PyObject *ui_translate_vkW(PyObject *, PyObject *args)
{
int vk;
// @pyparm int|vk||The key to translate
if (!PyArg_ParseTuple(args, "i", &vk))
return NULL;
static HKL layout=GetKeyboardLayout(0);
static BYTE State[256];
if (GetKeyboardState(State)==FALSE)
RETURN_ERR("Can't get keyboard state");
WCHAR result[2];
UINT sc=MapVirtualKeyEx(vk,0,layout);
int nc = ToUnicodeEx(vk,sc,State,result,2, 0,layout);
if (nc==-1) { // a dead char.
Py_INCREF(Py_None);
return Py_None;
}
return PyWinObject_FromWCHAR(result, nc);
}
**/

extern PyObject *ui_get_dialog_resource(PyObject *, PyObject *args);
extern PyObject *ui_create_app(PyObject *, PyObject *args);
extern PyObject *ui_get_app(PyObject *, PyObject *args);
Expand Down Expand Up @@ -2086,13 +2042,7 @@ int AddConstants(PyObject *module)
int debug = 0;
#endif
ADD_CONSTANT(debug); // @const win32ui|debug|1 if we are current using a _DEBUG build of win32ui, else 0.
if (PyModule_AddIntConstant(module, "UNICODE",
#ifdef UNICODE
1
#else
0
#endif
) == -1)
if (PyModule_AddIntConstant(module, "UNICODE", 1) == -1)
return -1;
ADD_CONSTANT(AFX_IDW_PANE_FIRST); // @const win32ui|AFX_IDW_PANE_FIRST|Id of the first splitter pane
ADD_CONSTANT(AFX_IDW_PANE_LAST); // @const win32ui|AFX_IDW_PANE_LAST|Id of the last splitter pane
Expand Down Expand Up @@ -2445,11 +2395,7 @@ PYWIN_MODULE_INIT_FUNC(win32ui)
PYWIN_MODULE_INIT_RETURN_ERROR;
}
if (existing_module)
#if (PY_VERSION_HEX < 0x03000000)
return;
#else
return existing_module;
#endif

PYWIN_MODULE_INIT_PREPARE(win32ui, ui_functions, "A module, encapsulating the Microsoft Foundation Classes.");

Expand Down Expand Up @@ -2608,12 +2554,6 @@ extern "C" PYW_EXPORT BOOL Win32uiApplicationInit(Win32uiHostGlue *pGlue, const
// a risk that when Python does "import win32ui", it
// will locate a different one, causing obvious grief!
PyObject *argv = PySys_GetObject("argv");
#if (PY_VERSION_HEX < 0x03000000)
initwin32ui();
// Set sys.argv if not already done!
if (argv == NULL && __targv != NULL && __argc > 0)
PySys_SetArgv(__argc - 1, __targv + 1);
#else
PyInit_win32ui();
// Decide if we render sys.argv from command line.
// PY3.6- Py_Initialize sets sys.argv=NULL .
Expand All @@ -2632,7 +2572,6 @@ extern "C" PYW_EXPORT BOOL Win32uiApplicationInit(Win32uiHostGlue *pGlue, const
LocalFree(myargv);
}
}
#endif
// If the versions of the .h file are not in synch, then we are in trouble!
if (pGlue->versionNo != WIN32UIHOSTGLUE_VERSION) {
MessageBox(0,
Expand Down
30 changes: 1 addition & 29 deletions Pythonwin/win32util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,28 +1136,12 @@ CString GetReprText(PyObject *objectUse)
{
PyObject *s;
CString csRet;
#ifdef UNICODE
// PyObject_Unicode disappeared in Py3k, where PyObject_Str returns unicode object
#if (PY_VERSION_HEX < 0x03000000)
s = PyObject_Unicode(objectUse);
#else
s = PyObject_Str(objectUse);
#endif
if (s) {
csRet = CString(PyUnicode_AsUnicode(s));
Py_DECREF(s);
return csRet;
}
#else
// Assumes that this will always be compiled with UNICODE defined for py3k
s = PyObject_Str(objectUse);
if (s) {
csRet = CString(PyBytes_AsString(s));
Py_DECREF(s);
return csRet;
}
#endif

PyErr_Clear();
s = PyObject_Repr(objectUse);
if (s == NULL) {
Expand All @@ -1166,7 +1150,7 @@ CString GetReprText(PyObject *objectUse)
return csRet;
}

// repr() should return either a string or unicode object, but not sure if this is enforced.
// repr() should always return a unicode string, but for hysterical raisens we check if it is bytes.
if (PyUnicode_Check(s))
csRet = CString(PyUnicode_AS_UNICODE(s));
else if (PyBytes_Check(s))
Expand All @@ -1176,16 +1160,4 @@ CString GetReprText(PyObject *objectUse)
s->ob_type->tp_name);
Py_DECREF(s);
return csRet;

/* This was apparently trying to remove enclosing quotes, parens, and brackets but will only succeed for quotes
Forget about it for now
Py_ssize_t len=strlen(szRepr);
if (len > 2 && strchr("\"'[(", *szRepr)) {
if (szRepr[len-1]==*szRepr) {
++szRepr;
len-=2; // drop first and last chars.
}
}
csRet= CString( szRepr, PyWin_SAFE_DOWNCAST(len, Py_ssize_t, int) );
*/
}
10 changes: 2 additions & 8 deletions SWIG/swig_lib/python/pywintypes.i
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ typedef unsigned long ULONG;
}
}

// String and UniCode support
// String support
%typemap(python,in) char *inNullString {
if ($source==Py_None) {
$target = NULL;
Expand Down Expand Up @@ -588,13 +588,7 @@ typedef float HWND;
#ifndef SWIG_PYTHONCOM
/* This code only valid if non COM SWIG builds */
#ifndef PYCOM_EXPORT
PyDict_SetItemString(d,"UNICODE", PyLong_FromLong(
#ifdef UNICODE
1
#else
0
#endif
));
PyDict_SetItemString(d,"UNICODE", PyLong_FromLong(1));
#endif
PyWinGlobals_Ensure();
PyDict_SetItemString(d, "error", PyWinExc_ApiError);
Expand Down
6 changes: 0 additions & 6 deletions com/win32com/src/MiscTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ PyComEnumTypeObject::PyComEnumTypeObject(const char *name, PyComTypeObject *pBas
tp_iter = iter;
tp_iternext = iternext;
// Py3k does not have this flag, and depends just on presence of tp_iter
#if (PY_VERSION_HEX < 0x03000000)
tp_flags |= Py_TPFLAGS_HAVE_ITER;
#endif
}

// PyIEnum iter methods - generic for any "standard" COM IEnum interface, but
Expand Down Expand Up @@ -153,9 +150,6 @@ PyComEnumProviderTypeObject::PyComEnumProviderTypeObject(const char *name, PyCom
{
tp_iter = iter;
// tp_iternext remains NULL
#if (PY_VERSION_HEX < 0x03000000)
tp_flags |= Py_TPFLAGS_HAVE_ITER;
#endif
}

// PyIEnumProvider iter methods - generic for COM object that can provide an IEnum*
Expand Down
4 changes: 0 additions & 4 deletions com/win32com/src/PyComHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ PyObject *get_Decimal_class(void)

PyObject *PyObject_FromCurrency(CURRENCY &cy)
{
#if (PY_VERSION_HEX < 0x03000000)
static char *divname = "__div__";
#else
static char *divname = "__truediv__";
#endif
if (Decimal_class == NULL) {
Decimal_class = get_Decimal_class();
if (Decimal_class == NULL)
Expand Down
8 changes: 0 additions & 8 deletions com/win32com/src/PyRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,6 @@ static void _FreeFieldNames(BSTR *strings, ULONG num_names)
delete[] strings;
}

#if (PY_VERSION_HEX < 0x03000000)
#define PyWinCoreString_ConcatAndDel PyBytes_ConcatAndDel
#define PyWinCoreString_Concat PyBytes_Concat
#else
// Unicode versions of '_Concat' etc have different sigs. Make them the
// same here...
void PyWinCoreString_Concat(register PyObject **pv, register PyObject *w)
{
if (!w) { // hrm - string version doesn't do this, but I saw PyObject_Repr() return NULL...
Expand All @@ -372,8 +366,6 @@ void PyWinCoreString_ConcatAndDel(register PyObject **pv, register PyObject *w)
Py_XDECREF(w);
}

#endif

PyObject *PyRecord::tp_repr(PyObject *self)
{
ULONG i;
Expand Down
4 changes: 0 additions & 4 deletions com/win32com/src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,7 @@ HRESULT DoRegisterUnregister(LPCSTR fileName, int argc, char **argv)
PyCom_DLLAddRef();
{ // A scope for _celp
CEnterLeavePython _celp;
#if (PY_VERSION_HEX < 0x03000000)
PySys_SetArgv(argc, argv);
#else
PySys_SetArgv(argc, __wargv);
#endif;

if (PyRun_SimpleFile(fp, (char *)fileName) != 0) {
// Convert the Python error to a HRESULT.
Expand Down
7 changes: 0 additions & 7 deletions com/win32com/src/extensions/PyIPropertyStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,6 @@ BOOL PyObject_AsPROPVARIANT(PyObject *ob, PROPVARIANT *pVar)
pVar->vt = VT_UI4;
}
}
#if (PY_VERSION_HEX < 0x03000000)
// Not needed in Py3k, as PyLong_Check is defined to PyLong_Check
}
else if (PyLong_Check(ob)) {
pVar->lVal = PyLong_AsLong(ob);
pVar->vt = VT_I4;
#endif
}
else if (PyFloat_Check(ob)) {
pVar->dblVal = PyFloat_AsDouble(ob);
Expand Down
16 changes: 0 additions & 16 deletions com/win32com/src/oleargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ static PyObject *PyVariant_Type;
#define BYREF_ARRAY_USE_EXISTING_ARRAY

// Need to put this in pywintypes.h with rest of compatibility macros
#if (PY_VERSION_HEX < 0x03000000)
#define PYWIN_BUFFER_CHECK PyBuffer_Check
#else
#define PYWIN_BUFFER_CHECK(obj) (PyBytes_Check(obj) || PyByteArray_Check(obj) || PyMemoryView_Check(obj))
#endif

// A little helper just for this file
static PyObject *OleSetTypeError(TCHAR *msg)
Expand Down Expand Up @@ -124,9 +120,6 @@ BOOL PyCom_VariantFromPyObject(PyObject *obj, VARIANT *var)
V_VT(var) = VT_EMPTY;
if (
// In py3k we don't convert PyBytes_Check objects (ie, bytes) to BSTR...
#if (PY_VERSION_HEX < 0x03000000)
PyBytes_Check(obj) ||
#endif
PyUnicode_Check(obj)) {
if (!PyWinObject_AsBstr(obj, &V_BSTR(var))) {
PyErr_SetString(PyExc_MemoryError, "Making BSTR for variant");
Expand Down Expand Up @@ -223,15 +216,6 @@ BOOL PyCom_VariantFromPyObject(PyObject *obj, VARIANT *var)
else if (obj == Py_None) {
V_VT(var) = VT_NULL;
}
#if (PY_VERSION_HEX < 0x03000000)
// This is redundant in 3.x, since PyLong_Check is #defined to PyLong_Check
else if (PyLong_Check(obj)) {
V_VT(var) = VT_I4;
V_I4(var) = PyLong_AsLong(obj);
if (V_I4(var) == -1 && PyErr_Occurred())
return FALSE;
}
#endif
else if (PyObject_HasAttrString(obj, "_oleobj_")) {
if (PyCom_InterfaceFromPyInstanceOrObject(obj, IID_IDispatch, (void **)&V_DISPATCH(var), FALSE))
V_VT(var) = VT_DISPATCH;
Expand Down
19 changes: 0 additions & 19 deletions com/win32com/src/univgw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ static void free_vtbl(gw_vtbl *vtbl)
VirtualFree(vtbl, 0, MEM_RELEASE);
}

#if PY_VERSION_HEX > 0x03010000
// Use the new capsule API
const char *capsule_name = "win32com universal gateway";

Expand All @@ -359,20 +358,6 @@ static PyObject *PyVTable_Create(void *vtbl) { return PyCapsule_New(vtbl, capsul
static gw_vtbl *PyVTable_Get(PyObject *ob) { return (gw_vtbl *)PyCapsule_GetPointer(ob, capsule_name); }

static bool PyVTable_Check(PyObject *ob) { return PyCapsule_IsValid(ob, capsule_name) != 0; }
#else
// Use the old CObject API.
static void __cdecl do_free_vtbl(void *cobject)
{
gw_vtbl *vtbl = (gw_vtbl *)cobject;
free_vtbl(vtbl);
}

static PyObject *PyVTable_Create(void *vtbl) { return PyCObject_FromVoidPtr(vtbl, do_free_vtbl); }

static gw_vtbl *PyVTable_Get(PyObject *ob) { return (gw_vtbl *)PyCObject_AsVoidPtr(ob); }

static bool PyVTable_Check(PyObject *ob) { return PyCObject_Check(ob) != 0; }
#endif

static PyObject *univgw_CreateVTable(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -731,13 +716,9 @@ BOOL initunivgw(PyObject *parentDict)

PyObject *module;

#if (PY_VERSION_HEX < 0x03000000)
module = Py_InitModule("pythoncom.__univgw", univgw_functions);
#else
static PyModuleDef univgw_def = {PyModuleDef_HEAD_INIT, "pythoncom.__univgw", "Univeral gateway", -1,
univgw_functions};
module = PyModule_Create(&univgw_def);
#endif
if (!module) /* Eeek - some serious error! */
return FALSE;

Expand Down
Loading