mirror of https://github.com/swig/swig
Fix C default arguments with -builtin and -fastunpack and -modernargs.
Problem occurred when there is just one (defaulted) parameter in the parameter list. Closes #1126
This commit is contained in:
parent
142d4062df
commit
18383340e9
|
@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.0.0 (in progress)
|
||||
===========================
|
||||
|
||||
2018-10-04: wsfulton
|
||||
[Python] #1126 Fix C default arguments with -builtin and -fastunpack and -modernargs.
|
||||
Problem occurred when there is just one (defaulted) parameter in the parameter list.
|
||||
|
||||
2018-09-24: wsfulton
|
||||
[Python] #1319 C++11 hash tables implementation is finished now (including for -builtin):
|
||||
std::unordered_map
|
||||
|
|
|
@ -20,3 +20,30 @@ int foo43(int x) {
|
|||
return x;
|
||||
}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
struct FooStruct {};
|
||||
%}
|
||||
%extend FooStruct {
|
||||
void no_arg() {}
|
||||
void one_req(int *required) {}
|
||||
void one_opt(int *optional = NULL) {}
|
||||
void two_arg(int *required, int *optional = NULL) {}
|
||||
}
|
||||
|
||||
%inline %{
|
||||
struct StaticStruct {};
|
||||
%}
|
||||
%extend StaticStruct {
|
||||
static void no_arg() {}
|
||||
static void one_req(int *required) {}
|
||||
static void one_opt(int *optional = NULL) {}
|
||||
static void two_arg(int *required, int *optional = NULL) {}
|
||||
}
|
||||
|
||||
%{
|
||||
void global_opts1(int *optional) {}
|
||||
void global_opts2(int *required, int *optional) {}
|
||||
%}
|
||||
void global_opts1(int *optional = NULL) {}
|
||||
void global_opts2(int *required, int *optional = NULL) {}
|
||||
|
|
|
@ -4,3 +4,23 @@ if default_args_c.foo1() != 1:
|
|||
raise RuntimeError("failed")
|
||||
if default_args_c.foo43() != 43:
|
||||
raise RuntimeError("failed")
|
||||
|
||||
f = default_args_c.FooStruct()
|
||||
f.no_arg()
|
||||
f.one_req(None)
|
||||
f.one_opt()
|
||||
f.one_opt(None)
|
||||
f.two_arg(None)
|
||||
f.two_arg(None, None)
|
||||
|
||||
default_args_c.StaticStruct.no_arg()
|
||||
default_args_c.StaticStruct.one_req(None)
|
||||
default_args_c.StaticStruct.one_opt()
|
||||
default_args_c.StaticStruct.one_opt(None)
|
||||
default_args_c.StaticStruct.two_arg(None)
|
||||
default_args_c.StaticStruct.two_arg(None, None)
|
||||
|
||||
default_args_c.global_opts1()
|
||||
default_args_c.global_opts1(None)
|
||||
default_args_c.global_opts2(None)
|
||||
default_args_c.global_opts2(None, None)
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <stdlib.h>
|
||||
#include "pydoc.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
|
||||
#define PYSHADOW_MEMBER 0x2
|
||||
|
@ -2865,11 +2864,13 @@ public:
|
|||
int noargs = funpack && (tuple_required == 0 && tuple_arguments == 0);
|
||||
int onearg = funpack && (tuple_required == 1 && tuple_arguments == 1);
|
||||
|
||||
if (builtin && funpack && !overname && !builtin_ctor &&
|
||||
!(GetFlag(n, "feature:compactdefaultargs") && (tuple_arguments > tuple_required || varargs))) {
|
||||
String *argattr = NewStringf("%d", tuple_arguments);
|
||||
Setattr(n, "python:argcount", argattr);
|
||||
Delete(argattr);
|
||||
if (builtin && funpack && !overname && !builtin_ctor) {
|
||||
int compactdefargs = ParmList_is_compactdefargs(l);
|
||||
if (!(compactdefargs && (tuple_arguments > tuple_required || varargs))) {
|
||||
String *argattr = NewStringf("%d", tuple_arguments);
|
||||
Setattr(n, "python:argcount", argattr);
|
||||
Delete(argattr);
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate code for argument marshalling */
|
||||
|
|
Loading…
Reference in New Issue