py3.7 fix

PyUnicode_AsUTF8() returns const char* in py3.7 instead of char*. Making
changes to reflect that which should also be safe in
other Python versions.
This commit is contained in:
Michal Ulianko
2018-08-17 14:42:21 +02:00
committed by wmayer
parent 591c1d32cd
commit faf8834484
12 changed files with 34 additions and 34 deletions

View File

@@ -103,8 +103,8 @@ public:
//@{
static int __setattro(PyObject *PyObj, PyObject *attro, PyObject *value);
//@}
PyObject *_getattr(char *attr); // __getattr__ function
int _setattr(char *attr, PyObject *value); // __setattr__ function
PyObject *_getattr(const char *attr); // __getattr__ function
int _setattr(const char *attr, PyObject *value); // __setattr__ function
protected:
PyObject * dict_methods;

View File

@@ -104,7 +104,7 @@ FeaturePythonPyT<FeaturePyT>::~FeaturePythonPyT()
template<class FeaturePyT>
int FeaturePythonPyT<FeaturePyT>::__setattro(PyObject *obj, PyObject *attro, PyObject *value)
{
char *attr;
const char *attr;
#if PY_MAJOR_VERSION >= 3
attr = PyUnicode_AsUTF8(attro);
#else
@@ -127,7 +127,7 @@ int FeaturePythonPyT<FeaturePyT>::__setattro(PyObject *obj, PyObject *attro, PyO
template<class FeaturePyT>
int FeaturePythonPyT<FeaturePyT>::_setattr(char *attr, PyObject *value)
int FeaturePythonPyT<FeaturePyT>::_setattr(const char *attr, PyObject *value)
{
App::Property *prop = FeaturePyT::getPropertyContainerPtr()->getPropertyByName(attr);
if (prop && !value) {
@@ -162,7 +162,7 @@ int FeaturePythonPyT<FeaturePyT>::_setattr(char *attr, PyObject *value)
}
template<class FeaturePyT>
PyObject *FeaturePythonPyT<FeaturePyT>::_getattr(char *attr)
PyObject *FeaturePythonPyT<FeaturePyT>::_getattr(const char *attr)
{
// See CallTipsList::extractTips
if (Base::streq(attr, "__fc_template__")) {

View File

@@ -141,7 +141,7 @@ PyMethodDef PyObjectBase::Methods[] = {
PyObject* PyObjectBase::__getattro(PyObject * obj, PyObject *attro)
{
char *attr;
const char *attr;
#if PY_MAJOR_VERSION >= 3
attr = PyUnicode_AsUTF8(attro);
#else
@@ -195,7 +195,7 @@ PyObject* PyObjectBase::__getattro(PyObject * obj, PyObject *attro)
int PyObjectBase::__setattro(PyObject *obj, PyObject *attro, PyObject *value)
{
char *attr;
const char *attr;
#if PY_MAJOR_VERSION >= 3
attr = PyUnicode_AsUTF8(attro);
#else
@@ -236,7 +236,7 @@ int PyObjectBase::__setattro(PyObject *obj, PyObject *attro, PyObject *value)
/*------------------------------
* PyObjectBase attributes -- attributes
------------------------------*/
PyObject *PyObjectBase::_getattr(char *attr)
PyObject *PyObjectBase::_getattr(const char *attr)
{
if (streq(attr, "__class__")) {
// Note: We must return the type object here,
@@ -279,7 +279,7 @@ PyObject *PyObjectBase::_getattr(char *attr)
}
}
int PyObjectBase::_setattr(char *attr, PyObject *value)
int PyObjectBase::_setattr(const char *attr, PyObject *value)
{
if (streq(attr,"softspace"))
return -1; // filter out softspace

View File

@@ -231,7 +231,7 @@ public:
* need to call the method of the base class! Otherwise even the
* methods of the object will disappear!
*/
virtual PyObject *_getattr(char *attr);
virtual PyObject *_getattr(const char *attr);
/// static wrapper for pythons _getattro()
static PyObject *__getattro(PyObject * PyObj, PyObject *attro);
@@ -241,7 +241,7 @@ public:
* this method.
* You have to call the method of the base class.
*/
virtual int _setattr(char *attro, PyObject *value); // _setattr method
virtual int _setattr(const char *attro, PyObject *value); // _setattr method
/// static wrapper for pythons _setattro(). // This should be the entry in Type.
static int __setattro(PyObject *PyObj, PyObject *attro, PyObject *value);

View File

@@ -549,7 +549,7 @@ PYCXX_EXPORT int &_Py_InteractiveFlag() { return Py_InteractiveFlag
PYCXX_EXPORT int &_Py_OptimizeFlag() { return Py_OptimizeFlag; }
PYCXX_EXPORT int &_Py_NoSiteFlag() { return Py_NoSiteFlag; }
PYCXX_EXPORT int &_Py_VerboseFlag() { return Py_VerboseFlag; }
PYCXX_EXPORT char *__Py_PackageContext() { return _Py_PackageContext; }
PYCXX_EXPORT const char *__Py_PackageContext() { return _Py_PackageContext; }
//
// Needed to keep the abstactions for delayload interface

View File

@@ -193,7 +193,7 @@ PYCXX_EXPORT int &_Py_UnicodeFlag();
PYCXX_EXPORT void _XINCREF( PyObject *op );
PYCXX_EXPORT void _XDECREF( PyObject *op );
PYCXX_EXPORT char *__Py_PackageContext();
PYCXX_EXPORT const char *__Py_PackageContext();
}
#endif // __CXX_INDIRECT_PYTHON_INTERFACE__HXX__

View File

@@ -178,7 +178,7 @@ PYCXX_EXPORT int &_Py_UnicodeFlag();
PYCXX_EXPORT void _XINCREF( PyObject *op );
PYCXX_EXPORT void _XDECREF( PyObject *op );
PYCXX_EXPORT char *__Py_PackageContext();
PYCXX_EXPORT const char *__Py_PackageContext();
};
#endif // __CXX_INDIRECT_PYTHON_INTERFACE__HXX__

View File

@@ -64,7 +64,7 @@ PyObject* PythonWorkbenchPy::appendMenu(PyObject *args)
PyObject* item = PyList_GetItem(pPath, j);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(item);
const char* pItem = PyUnicode_AsUTF8(item);
path.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
@@ -81,7 +81,7 @@ PyObject* PythonWorkbenchPy::appendMenu(PyObject *args)
}
} else if (PyUnicode_Check(pPath)) {
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(pPath);
const char* pItem = PyUnicode_AsUTF8(pPath);
path.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(pPath, "utf-8", 0);
@@ -106,7 +106,7 @@ PyObject* PythonWorkbenchPy::appendMenu(PyObject *args)
PyObject* item = PyList_GetItem(pItems, i);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(item);
const char* pItem = PyUnicode_AsUTF8(item);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
@@ -123,7 +123,7 @@ PyObject* PythonWorkbenchPy::appendMenu(PyObject *args)
}
} else if (PyUnicode_Check(pItems)) {
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(pItems);
const char* pItem = PyUnicode_AsUTF8(pItems);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(pItems, "utf-8", 0);
@@ -199,7 +199,7 @@ PyObject* PythonWorkbenchPy::appendContextMenu(PyObject *args)
PyObject* item = PyList_GetItem(pPath, j);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(item);
const char* pItem = PyUnicode_AsUTF8(item);
path.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
@@ -216,7 +216,7 @@ PyObject* PythonWorkbenchPy::appendContextMenu(PyObject *args)
}
} else if (PyUnicode_Check(pPath)) {
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(pPath);
const char* pItem = PyUnicode_AsUTF8(pPath);
path.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(pPath, "utf-8", 0);
@@ -241,7 +241,7 @@ PyObject* PythonWorkbenchPy::appendContextMenu(PyObject *args)
PyObject* item = PyList_GetItem(pItems, i);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(item);
const char* pItem = PyUnicode_AsUTF8(item);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
@@ -258,7 +258,7 @@ PyObject* PythonWorkbenchPy::appendContextMenu(PyObject *args)
}
} else if (PyUnicode_Check(pItems)) {
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(pItems);
const char* pItem = PyUnicode_AsUTF8(pItems);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(pItems, "utf-8", 0);
@@ -313,7 +313,7 @@ PyObject* PythonWorkbenchPy::appendToolbar(PyObject *args)
PyObject* item = PyList_GetItem(pObject, i);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(item);
const char* pItem = PyUnicode_AsUTF8(item);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);
@@ -389,7 +389,7 @@ PyObject* PythonWorkbenchPy::appendCommandbar(PyObject *args)
PyObject* item = PyList_GetItem(pObject, i);
if (PyUnicode_Check(item)) {
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(item);
const char* pItem = PyUnicode_AsUTF8(item);
items.push_back(pItem);
#else
PyObject* unicode = PyUnicode_AsEncodedString(item, "utf-8", 0);

View File

@@ -1437,7 +1437,7 @@ Py::Object PyResource::setValue(const Py::Tuple& args)
#endif
continue;
#if PY_MAJOR_VERSION >= 3
char* pItem = PyUnicode_AsUTF8(item);
const char* pItem = PyUnicode_AsUTF8(item);
#else
char* pItem = PyString_AsString(item);
#endif

View File

@@ -190,7 +190,7 @@ TopoShapePyOld::~TopoShapePyOld() // Everything handled in parent
//--------------------------------------------------------------------------
// TopoShapePyOld Attributes
//--------------------------------------------------------------------------
PyObject *TopoShapePyOld::_getattr(char *attr) // __getattr__ function: note only need to handle new state
PyObject *TopoShapePyOld::_getattr(const char *attr) // __getattr__ function: note only need to handle new state
{
try{
// Access the number of attributes at this label
@@ -205,7 +205,7 @@ PyObject *TopoShapePyOld::_getattr(char *attr) // __getattr__ function: note
}
}
int TopoShapePyOld::_setattr(char *attr, PyObject *value) // __setattr__ function: note only need to handle new state
int TopoShapePyOld::_setattr(const char *attr, PyObject *value) // __setattr__ function: note only need to handle new state
{
if (Base::streq(attr, "Real")) // settable new state
;
@@ -712,4 +712,4 @@ PyObject *TopoShapePyOld::exportSTL(PyObject *args)
Py_Return;
}
#endif
#endif

View File

@@ -72,9 +72,9 @@ public:
//---------------------------------------------------------------------
virtual PyObject *_repr(void); // the representation
PyObject *_getattr(char *attr); // __getattr__ function
PyObject *_getattr(const char *attr); // __getattr__ function
// getter setter
int _setattr(char *attr, PyObject *value); // __setattr__ function
int _setattr(const char *attr, PyObject *value); // __setattr__ function
// methods
PYFUNCDEF_D (TopoShapePyOld,hasChild);

View File

@@ -224,8 +224,8 @@ public:
/// setter for special attributes (e.g. dynamic ones)
/// Output: Success=1, Failure=-1, Ignore=0
int setCustomAttributes(const char* attr, PyObject *obj);
PyObject *_getattr(char *attr); // __getattr__ function
int _setattr(char *attr, PyObject *value); // __setattr__ function
PyObject *_getattr(const char *attr); // __getattr__ function
int _setattr(const char *attr, PyObject *value); // __setattr__ function
-
/// getter for the object handled by this class
@@ -727,7 +727,7 @@ PyObject *@self.export.Name@::_repr(void)
//--------------------------------------------------------------------------
// @self.export.Name@ Attributes
//--------------------------------------------------------------------------
PyObject *@self.export.Name@::_getattr(char *attr) // __getattr__ function: note only need to handle new state
PyObject *@self.export.Name@::_getattr(const char *attr) // __getattr__ function: note only need to handle new state
{
try {
// getter method for special Attributes (e.g. dynamic ones)
@@ -795,7 +795,7 @@ PyObject *@self.export.Name@::_getattr(char *attr) // __getattr__ function: n
return @self.export.Father@::_getattr(attr);
}
int @self.export.Name@::_setattr(char *attr, PyObject *value) // __setattr__ function: note only need to handle new state
int @self.export.Name@::_setattr(const char *attr, PyObject *value) // __setattr__ function: note only need to handle new state
{
try {
// setter for special Attributes (e.g. dynamic ones)