Skip to content

Commit

Permalink
Remove python2 block pertaining to PyString_
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Apr 25, 2024
1 parent 1f0d8cf commit 687e0f5
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/utilities/core/Path.i
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ namespace openstudio {
}
}

%typemap(in, fragment="SWIG_openstudio_path") (path) {
%typemap(in, fragment="SWIG_openstudio_path") path {

// check if input is a path already
void *vptr = 0;
Expand All @@ -326,13 +326,8 @@ namespace openstudio {
SWIG_exception_fail(SWIG_ValueError, "Invalid null reference openstudio::path");
}
} else if(PyUnicode_Check($input)) {
// Python 3
std::string s(PyUnicode_AsUTF8($input));
$1 = openstudio::toPath(s);
} else if(PyString_Check($input)) {
// Python2, PyString_Check does PyBytes_Check
std::string s(PyString_AsString($input));
$1 = openstudio::toPath(s);
} else if (isPathInstance($input)) {
PyObject * str_obj = PyObject_Str($input); // New reference
const char * s = PyUnicode_AsUTF8(str_obj); // This stores the UTF-8 representation buffer within str_obj
Expand All @@ -343,8 +338,8 @@ namespace openstudio {
}
}

%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING, fragment="SWIG_openstudio_path") (path) {
bool stringOrPathlibType = PyString_Check($input) || PyUnicode_Check($input) || isPathInstance($input);
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING, fragment="SWIG_openstudio_path") path {
bool stringOrPathlibType = PyUnicode_Check($input) || isPathInstance($input);
bool pathType = false;
if (stringOrPathlibType){
void *vptr = 0;
Expand Down Expand Up @@ -372,7 +367,7 @@ namespace openstudio {
%apply path { const path };

// handle const path& separately
%typemap(in, fragment="SWIG_openstudio_path") (const path&) {
%typemap(in, fragment="SWIG_openstudio_path") const path& {
$1=NULL;

// check if input is a path already
Expand All @@ -387,13 +382,8 @@ namespace openstudio {
SWIG_exception_fail(SWIG_ValueError, "Invalid null reference openstudio::path const &");
}
} else if(PyUnicode_Check($input)) {
// Python 3
std::string s(PyUnicode_AsUTF8($input));
$1 = new openstudio::path(openstudio::toPath(s));
} else if(PyString_Check($input)) {
// Python2, PyString_Check does PyBytes_Check
std::string s(PyString_AsString($input));
$1 = new openstudio::path(openstudio::toPath(s));
} else if (isPathInstance($input)) {
PyObject * str_obj = PyObject_Str($input); // New reference
const char * s = PyUnicode_AsUTF8(str_obj);
Expand All @@ -404,8 +394,8 @@ namespace openstudio {
}
}

%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING, fragment="SWIG_openstudio_path") (const path&) {
bool stringOrPathlibType = PyString_Check($input) || PyUnicode_Check($input) || isPathInstance($input);
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING, fragment="SWIG_openstudio_path") const path& {
bool stringOrPathlibType = PyUnicode_Check($input) || isPathInstance($input);
bool pathType = false;
if (stringOrPathlibType) {
void *vptr = 0;
Expand All @@ -415,8 +405,8 @@ namespace openstudio {
$1 = (stringOrPathlibType || pathType) ? 1 : 0;
}

%typemap(freearg) (const path&) {
if ($1){
%typemap(freearg) const path& {
if ($1) {
delete $1;
}
}
Expand Down

0 comments on commit 687e0f5

Please sign in to comment.