summaryrefslogtreecommitdiff
path: root/py/modules/IcePy/Properties.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2007-04-18 17:19:06 +0000
committerMark Spruiell <mes@zeroc.com>2007-04-18 17:19:06 +0000
commit1129b050e2c513f1d0b87d5b29bae7699e35778b (patch)
tree2c1076967a445ce0e26948a03f283337ea80aab4 /py/modules/IcePy/Properties.cpp
parentAdded nmake support for WinCE (diff)
downloadice-1129b050e2c513f1d0b87d5b29bae7699e35778b.tar.bz2
ice-1129b050e2c513f1d0b87d5b29bae7699e35778b.tar.xz
ice-1129b050e2c513f1d0b87d5b29bae7699e35778b.zip
bug 1493: removing use of NULL bug 1852: fixing compiler warnings bug 1853:
fixing compiler warnings bug 2098: change proxy factory methods to return object of same class
Diffstat (limited to 'py/modules/IcePy/Properties.cpp')
-rw-r--r--py/modules/IcePy/Properties.cpp136
1 files changed, 69 insertions, 67 deletions
diff --git a/py/modules/IcePy/Properties.cpp b/py/modules/IcePy/Properties.cpp
index b6097394264..737e0efc2d5 100644
--- a/py/modules/IcePy/Properties.cpp
+++ b/py/modules/IcePy/Properties.cpp
@@ -36,9 +36,9 @@ static PropertiesObject*
propertiesNew(PyObject* /*arg*/)
{
PropertiesObject* self = PyObject_New(PropertiesObject, &PropertiesType);
- if (self == NULL)
+ if(!self)
{
- return NULL;
+ return 0;
}
self->properties = 0;
return self;
@@ -50,18 +50,19 @@ extern "C"
static int
propertiesInit(PropertiesObject* self, PyObject* args, PyObject* /*kwds*/)
{
- PyObject* arglist = NULL;
- PyObject* defaultsObj = NULL;
+ PyObject* arglist = 0;
+ PyObject* defaultsObj = 0;
if(!PyArg_ParseTuple(args, STRCAST("|OO"), &arglist, &defaultsObj))
{
return -1;
}
-
+
Ice::StringSeq seq;
if(arglist)
{
- if(PyObject_IsInstance(arglist, (PyObject*)&PyList_Type))
+ PyTypeObject* listType = &PyList_Type; // Necessary to prevent GCC's strict-alias warnings.
+ if(PyObject_IsInstance(arglist, reinterpret_cast<PyObject*>(listType)))
{
if(!listToStringSeq(arglist, seq))
{
@@ -79,7 +80,7 @@ propertiesInit(PropertiesObject* self, PyObject* args, PyObject* /*kwds*/)
if(defaultsObj)
{
PyObject* propType = lookupType("Ice.PropertiesI");
- assert(propType != NULL);
+ assert(propType);
if(PyObject_IsInstance(defaultsObj, propType))
{
PyObjectHandle impl = PyObject_GetAttrString(defaultsObj, STRCAST("_impl"));
@@ -92,7 +93,6 @@ propertiesInit(PropertiesObject* self, PyObject* args, PyObject* /*kwds*/)
}
}
-
Ice::PropertiesPtr props;
try
{
@@ -109,7 +109,7 @@ propertiesInit(PropertiesObject* self, PyObject* args, PyObject* /*kwds*/)
//
if(arglist)
{
- if(PyList_SetSlice(arglist, 0, PyList_Size(arglist), NULL) < 0)
+ if(PyList_SetSlice(arglist, 0, PyList_Size(arglist), 0) < 0)
{
return -1;
}
@@ -150,7 +150,7 @@ propertiesStr(PropertiesObject* self)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
string str;
@@ -175,7 +175,7 @@ propertiesGetProperty(PropertiesObject* self, PyObject* args)
char* key;
if(!PyArg_ParseTuple(args, STRCAST("s"), &key))
{
- return NULL;
+ return 0;
}
assert(self->properties);
@@ -187,7 +187,7 @@ propertiesGetProperty(PropertiesObject* self, PyObject* args)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
return PyString_FromString(const_cast<char*>(value.c_str()));
@@ -203,7 +203,7 @@ propertiesGetPropertyWithDefault(PropertiesObject* self, PyObject* args)
char* def;
if(!PyArg_ParseTuple(args, STRCAST("ss"), &key, &def))
{
- return NULL;
+ return 0;
}
assert(self->properties);
@@ -215,7 +215,7 @@ propertiesGetPropertyWithDefault(PropertiesObject* self, PyObject* args)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
return PyString_FromString(const_cast<char*>(value.c_str()));
@@ -230,7 +230,7 @@ propertiesGetPropertyAsInt(PropertiesObject* self, PyObject* args)
char* key;
if(!PyArg_ParseTuple(args, STRCAST("s"), &key))
{
- return NULL;
+ return 0;
}
assert(self->properties);
@@ -242,7 +242,7 @@ propertiesGetPropertyAsInt(PropertiesObject* self, PyObject* args)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
return PyInt_FromLong(value);
@@ -258,7 +258,7 @@ propertiesGetPropertyAsIntWithDefault(PropertiesObject* self, PyObject* args)
int def;
if(!PyArg_ParseTuple(args, STRCAST("si"), &key, &def))
{
- return NULL;
+ return 0;
}
assert(self->properties);
@@ -270,7 +270,7 @@ propertiesGetPropertyAsIntWithDefault(PropertiesObject* self, PyObject* args)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
return PyInt_FromLong(value);
@@ -285,7 +285,7 @@ propertiesGetPropertiesForPrefix(PropertiesObject* self, PyObject* args)
char* prefix;
if(!PyArg_ParseTuple(args, STRCAST("s"), &prefix))
{
- return NULL;
+ return 0;
}
assert(self->properties);
@@ -297,19 +297,19 @@ propertiesGetPropertiesForPrefix(PropertiesObject* self, PyObject* args)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
PyObjectHandle result = PyDict_New();
- if(result.get() != NULL)
+ if(result.get())
{
for(Ice::PropertyDict::iterator p = dict.begin(); p != dict.end(); ++p)
{
PyObjectHandle key = PyString_FromString(const_cast<char*>(p->first.c_str()));
PyObjectHandle val = PyString_FromString(const_cast<char*>(p->second.c_str()));
- if(val.get() == NULL || PyDict_SetItem(result.get(), key.get(), val.get()) < 0)
+ if(!val.get() || PyDict_SetItem(result.get(), key.get(), val.get()) < 0)
{
- return NULL;
+ return 0;
}
}
}
@@ -327,7 +327,7 @@ propertiesSetProperty(PropertiesObject* self, PyObject* args)
char* value;
if(!PyArg_ParseTuple(args, STRCAST("ss"), &key, &value))
{
- return NULL;
+ return 0;
}
assert(self->properties);
@@ -338,7 +338,7 @@ propertiesSetProperty(PropertiesObject* self, PyObject* args)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
Py_INCREF(Py_None);
@@ -360,17 +360,17 @@ propertiesGetCommandLineOptions(PropertiesObject* self)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
PyObject* list = PyList_New(0);
- if(list == NULL)
+ if(!list)
{
return false;
}
if(!stringSeqToList(options, list))
{
- return NULL;
+ return 0;
}
return list;
@@ -386,13 +386,13 @@ propertiesParseCommandLineOptions(PropertiesObject* self, PyObject* args)
PyObject* options;
if(!PyArg_ParseTuple(args, STRCAST("sO!"), &prefix, &PyList_Type, &options))
{
- return NULL;
+ return 0;
}
Ice::StringSeq seq;
if(!listToStringSeq(options, seq))
{
- return NULL;
+ return 0;
}
assert(self->properties);
@@ -404,17 +404,17 @@ propertiesParseCommandLineOptions(PropertiesObject* self, PyObject* args)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
PyObject* list = PyList_New(0);
- if(list == NULL)
+ if(!list)
{
return false;
}
if(!stringSeqToList(filteredSeq, list))
{
- return NULL;
+ return 0;
}
return list;
@@ -429,13 +429,13 @@ propertiesParseIceCommandLineOptions(PropertiesObject* self, PyObject* args)
PyObject* options;
if(!PyArg_ParseTuple(args, STRCAST("O!"), &PyList_Type, &options))
{
- return NULL;
+ return 0;
}
Ice::StringSeq seq;
if(!listToStringSeq(options, seq))
{
- return NULL;
+ return 0;
}
assert(self->properties);
@@ -447,17 +447,17 @@ propertiesParseIceCommandLineOptions(PropertiesObject* self, PyObject* args)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
PyObject* list = PyList_New(0);
- if(list == NULL)
+ if(!list)
{
return false;
}
if(!stringSeqToList(filteredSeq, list))
{
- return NULL;
+ return 0;
}
return list;
@@ -472,7 +472,7 @@ propertiesLoad(PropertiesObject* self, PyObject* args)
char* file;
if(!PyArg_ParseTuple(args, STRCAST("s"), &file))
{
- return NULL;
+ return 0;
}
assert(self->properties);
@@ -483,7 +483,7 @@ propertiesLoad(PropertiesObject* self, PyObject* args)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
Py_INCREF(Py_None);
@@ -505,7 +505,7 @@ propertiesClone(PropertiesObject* self)
catch(const Ice::Exception& ex)
{
setPythonException(ex);
- return NULL;
+ return 0;
}
return createProperties(properties);
@@ -513,29 +513,29 @@ propertiesClone(PropertiesObject* self)
static PyMethodDef PropertyMethods[] =
{
- { STRCAST("getProperty"), (PyCFunction)propertiesGetProperty, METH_VARARGS,
+ { STRCAST("getProperty"), reinterpret_cast<PyCFunction>(propertiesGetProperty), METH_VARARGS,
PyDoc_STR(STRCAST("getProperty(key) -> string")) },
- { STRCAST("getPropertyWithDefault"), (PyCFunction)propertiesGetPropertyWithDefault, METH_VARARGS,
+ { STRCAST("getPropertyWithDefault"), reinterpret_cast<PyCFunction>(propertiesGetPropertyWithDefault), METH_VARARGS,
PyDoc_STR(STRCAST("getPropertyWithDefault(key, default) -> string")) },
- { STRCAST("getPropertyAsInt"), (PyCFunction)propertiesGetPropertyAsInt, METH_VARARGS,
+ { STRCAST("getPropertyAsInt"), reinterpret_cast<PyCFunction>(propertiesGetPropertyAsInt), METH_VARARGS,
PyDoc_STR(STRCAST("getPropertyAsInt(key) -> int")) },
- { STRCAST("getPropertyAsIntWithDefault"), (PyCFunction)propertiesGetPropertyAsIntWithDefault, METH_VARARGS,
- PyDoc_STR(STRCAST("getPropertyAsIntWithDefault(key, default) -> int")) },
- { STRCAST("getPropertiesForPrefix"), (PyCFunction)propertiesGetPropertiesForPrefix, METH_VARARGS,
+ { STRCAST("getPropertyAsIntWithDefault"), reinterpret_cast<PyCFunction>(propertiesGetPropertyAsIntWithDefault),
+ METH_VARARGS, PyDoc_STR(STRCAST("getPropertyAsIntWithDefault(key, default) -> int")) },
+ { STRCAST("getPropertiesForPrefix"), reinterpret_cast<PyCFunction>(propertiesGetPropertiesForPrefix), METH_VARARGS,
PyDoc_STR(STRCAST("getPropertiesForPrefix(prefix) -> dict")) },
- { STRCAST("setProperty"), (PyCFunction)propertiesSetProperty, METH_VARARGS,
+ { STRCAST("setProperty"), reinterpret_cast<PyCFunction>(propertiesSetProperty), METH_VARARGS,
PyDoc_STR(STRCAST("setProperty(key, value) -> None")) },
- { STRCAST("getCommandLineOptions"), (PyCFunction)propertiesGetCommandLineOptions, METH_NOARGS,
+ { STRCAST("getCommandLineOptions"), reinterpret_cast<PyCFunction>(propertiesGetCommandLineOptions), METH_NOARGS,
PyDoc_STR(STRCAST("getCommandLineOptions() -> list")) },
- { STRCAST("parseCommandLineOptions"), (PyCFunction)propertiesParseCommandLineOptions, METH_VARARGS,
- PyDoc_STR(STRCAST("parseCommandLineOptions(prefix, options) -> list")) },
- { STRCAST("parseIceCommandLineOptions"), (PyCFunction)propertiesParseIceCommandLineOptions, METH_VARARGS,
- PyDoc_STR(STRCAST("parseIceCommandLineOptions(prefix, options) -> list")) },
- { STRCAST("load"), (PyCFunction)propertiesLoad, METH_VARARGS,
+ { STRCAST("parseCommandLineOptions"), reinterpret_cast<PyCFunction>(propertiesParseCommandLineOptions),
+ METH_VARARGS, PyDoc_STR(STRCAST("parseCommandLineOptions(prefix, options) -> list")) },
+ { STRCAST("parseIceCommandLineOptions"), reinterpret_cast<PyCFunction>(propertiesParseIceCommandLineOptions),
+ METH_VARARGS, PyDoc_STR(STRCAST("parseIceCommandLineOptions(prefix, options) -> list")) },
+ { STRCAST("load"), reinterpret_cast<PyCFunction>(propertiesLoad), METH_VARARGS,
PyDoc_STR(STRCAST("load(file) -> None")) },
- { STRCAST("clone"), (PyCFunction)propertiesClone, METH_NOARGS,
+ { STRCAST("clone"), reinterpret_cast<PyCFunction>(propertiesClone), METH_NOARGS,
PyDoc_STR(STRCAST("clone() -> Ice.Properties")) },
- { NULL, NULL} /* sentinel */
+ { 0, 0 } /* sentinel */
};
namespace IcePy
@@ -545,13 +545,13 @@ PyTypeObject PropertiesType =
{
/* The ob_type field must be initialized in the module init function
* to be portable to Windows without using C++. */
- PyObject_HEAD_INIT(NULL)
+ PyObject_HEAD_INIT(0)
0, /* ob_size */
STRCAST("IcePy.Properties"), /* tp_name */
sizeof(PropertiesObject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
- (destructor)propertiesDealloc, /* tp_dealloc */
+ reinterpret_cast<destructor>(propertiesDealloc), /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
@@ -562,7 +562,7 @@ PyTypeObject PropertiesType =
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
- (reprfunc)propertiesStr, /* tp_str */
+ reinterpret_cast<reprfunc>(propertiesStr), /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
@@ -582,9 +582,9 @@ PyTypeObject PropertiesType =
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
- (initproc)propertiesInit, /* tp_init */
+ reinterpret_cast<initproc>(propertiesInit), /* tp_init */
0, /* tp_alloc */
- (newfunc)propertiesNew, /* tp_new */
+ reinterpret_cast<newfunc>(propertiesNew), /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
};
@@ -598,7 +598,8 @@ IcePy::initProperties(PyObject* module)
{
return false;
}
- if(PyModule_AddObject(module, STRCAST("Properties"), (PyObject*)&PropertiesType) < 0)
+ PyTypeObject* type = &PropertiesType; // Necessary to prevent GCC's strict-alias warnings.
+ if(PyModule_AddObject(module, STRCAST("Properties"), reinterpret_cast<PyObject*>(type)) < 0)
{
return false;
}
@@ -609,18 +610,18 @@ IcePy::initProperties(PyObject* module)
PyObject*
IcePy::createProperties(const Ice::PropertiesPtr& props)
{
- PropertiesObject* obj = propertiesNew(NULL);
- if(obj != NULL)
+ PropertiesObject* obj = propertiesNew(0);
+ if(obj)
{
obj->properties = new Ice::PropertiesPtr(props);
}
- return (PyObject*)obj;
+ return reinterpret_cast<PyObject*>(obj);
}
Ice::PropertiesPtr
IcePy::getProperties(PyObject* p)
{
- PropertiesObject* obj = (PropertiesObject*)p;
+ PropertiesObject* obj = reinterpret_cast<PropertiesObject*>(p);
if(obj->properties)
{
return *obj->properties;
@@ -635,5 +636,6 @@ IcePy_createProperties(PyObject* /*self*/, PyObject* args)
//
// Currently the same as "p = Ice.Properties()".
//
- return PyObject_Call((PyObject*)&PropertiesType, args, NULL);
+ PyTypeObject* type = &PropertiesType; // Necessary to prevent GCC's strict-alias warnings.
+ return PyObject_Call(reinterpret_cast<PyObject*>(type), args, 0);
}