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
diff --git a/CHANGES.current b/CHANGES.current
index 36712fe..27d000b 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,6 +7,10 @@
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
diff --git a/Examples/test-suite/default_args_c.i b/Examples/test-suite/default_args_c.i
index ed1c4de..504a6b8 100644
--- a/Examples/test-suite/default_args_c.i
+++ b/Examples/test-suite/default_args_c.i
@@ -20,3 +20,30 @@
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) {}
diff --git a/Examples/test-suite/python/default_args_c_runme.py b/Examples/test-suite/python/default_args_c_runme.py
index 5985fd7..65ca917 100644
--- a/Examples/test-suite/python/default_args_c_runme.py
+++ b/Examples/test-suite/python/default_args_c_runme.py
@@ -4,3 +4,23 @@
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)
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 62f6fd4..c2952d6 100755
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -19,7 +19,6 @@
#include <stdlib.h>
#include "pydoc.h"
-#include <iostream>
#include <stdint.h>
#define PYSHADOW_MEMBER 0x2
@@ -2865,11 +2864,13 @@
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 */