Improve director unwrap detection for the return type

Resolve the return type to correctly determine if the type is a pointer or
reference to a director class.

SwigType_refptr_count_return() recently added as a simpler fix is no
longer needed.

The conventional approach of using the "type" rather than "decl" to
analyse the return type is used instead too.

Issue #1823
This commit is contained in:
William S Fulton 2022-10-10 08:27:44 +01:00
commit 2f55379687
10 changed files with 76 additions and 90 deletions

View file

@ -140,7 +140,6 @@ extern "C" {
extern String *SwigType_pop(SwigType *t);
extern void SwigType_push(SwigType *t, String *s);
extern SwigType *SwigType_last(SwigType *t);
extern int SwigType_refptr_count_return(const SwigType *t);
extern List *SwigType_parmlist(const SwigType *p);
extern String *SwigType_parm(const SwigType *p);
extern String *SwigType_str(const SwigType *s, const_String_or_char_ptr id);

View file

@ -249,49 +249,6 @@ SwigType *SwigType_last(SwigType *t) {
return result;
}
/* -----------------------------------------------------------------------------
* SwigType_refptr_count_return()
*
* Returns the number of pointer and reference indirections found in the given
* type. For functions this concerns the return type.
* For example:
* r.p. => 2
* q(const).p. => 1
* r.f(int).p.p. => 2
* f().p.q(const).p. => 2
* ----------------------------------------------------------------------------- */
int SwigType_refptr_count_return(const SwigType *t) {
char *c;
char *last;
int sz;
int result = 0;
if (!t)
return 0;
c = Char(t);
last = c;
while (*c) {
last = c;
sz = element_size(c);
c = c + sz;
if (*(c-1) == '.') {
if (((last[0] == 'p') || (last[0] == 'r')) && (last[1] == '.')) {
result++;
} else if (strncmp(last, "f(", 2) == 0) {
/* restart counter if this is a function type */
result = 0;
}
}
if (*c == '.') {
c++;
}
}
return result;
}
/* -----------------------------------------------------------------------------
* SwigType_parm()
*