#Issue 20456: Several improvements and bugfixes for Argument Clinic,
including correctly generating code for Clinic blocks inside C
preprocessor conditional blocks.
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 915a780..494f02e 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -584,7 +584,7 @@
 [clinic start generated code]*/
 
 PyDoc_STRVAR(curses_window_addch__doc__,
-"addch(self, [x, y,] ch, [attr])\n"
+"addch([x, y,] ch, [attr])\n"
 "Paint character ch at (y, x) with attributes attr.\n"
 "\n"
 "  x\n"
@@ -651,7 +651,7 @@
 
 static PyObject *
 curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr)
-/*[clinic end generated code: output=e1cdbd4f4e42fc6b input=fe7e3711d5bbf1f6]*/
+/*[clinic end generated code: output=43acb91a5c98f615 input=fe7e3711d5bbf1f6]*/
 {
     PyCursesWindowObject *cwself = (PyCursesWindowObject *)self;
     int coordinates_group = group_left_1;
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
index 9f63c8a..abeb799 100644
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -52,10 +52,11 @@
 /*[python input]
 class dbmobject_converter(self_converter):
     type = "dbmobject *"
-    def converter_init(self):
+    def pre_render(self):
+        super().pre_render()
         self.name = 'dp'
 [python start generated code]*/
-/*[python end generated code: output=da39a3ee5e6b4b0d input=8a69ac1827811128]*/
+/*[python end generated code: output=da39a3ee5e6b4b0d input=6ad536357913879a]*/
 
 static PyObject *
 newdbmobject(const char *file, int flags, int mode)
@@ -270,23 +271,21 @@
     self: dbmobject
 
     key: str(length=True)
-    [
-    default: object
-    ]
+    default: object = None
     /
 
 Return the value for key if present, otherwise default.
 [clinic start generated code]*/
 
 PyDoc_STRVAR(dbm_dbm_get__doc__,
-"get(self, key, [default])\n"
+"sig=($self, key, default=None)\n"
 "Return the value for key if present, otherwise default.");
 
 #define DBM_DBM_GET_METHODDEF    \
     {"get", (PyCFunction)dbm_dbm_get, METH_VARARGS, dbm_dbm_get__doc__},
 
 static PyObject *
-dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, int group_right_1, PyObject *default_value);
+dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, PyObject *default_value);
 
 static PyObject *
 dbm_dbm_get(dbmobject *dp, PyObject *args)
@@ -294,37 +293,24 @@
     PyObject *return_value = NULL;
     const char *key;
     Py_ssize_clean_t key_length;
-    int group_right_1 = 0;
-    PyObject *default_value = NULL;
+    PyObject *default_value = Py_None;
 
-    switch (PyTuple_GET_SIZE(args)) {
-        case 1:
-            if (!PyArg_ParseTuple(args, "s#:get", &key, &key_length))
-                goto exit;
-            break;
-        case 2:
-            if (!PyArg_ParseTuple(args, "s#O:get", &key, &key_length, &default_value))
-                goto exit;
-            group_right_1 = 1;
-            break;
-        default:
-            PyErr_SetString(PyExc_TypeError, "dbm.dbm.get requires 1 to 2 arguments");
-            goto exit;
-    }
-    return_value = dbm_dbm_get_impl(dp, key, key_length, group_right_1, default_value);
+    if (!PyArg_ParseTuple(args,
+        "s#|O:get",
+        &key, &key_length, &default_value))
+        goto exit;
+    return_value = dbm_dbm_get_impl(dp, key, key_length, default_value);
 
 exit:
     return return_value;
 }
 
 static PyObject *
-dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, int group_right_1, PyObject *default_value)
-/*[clinic end generated code: output=31d5180d6b36f1ea input=43a561dc2bd1db3b]*/
+dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, PyObject *default_value)
+/*[clinic end generated code: output=2bbaf9a187f9b6bf input=aecf5efd2f2b1a3b]*/
 {
     datum dbm_key, val;
 
-    if (!group_right_1)
-        default_value = Py_None;
     dbm_key.dptr = (char *)key;
     dbm_key.dsize = key_length;
     check_dbmobject_open(dp);
diff --git a/Modules/_opcode.c b/Modules/_opcode.c
index 1597e3d..30eeeef 100644
--- a/Modules/_opcode.c
+++ b/Modules/_opcode.c
@@ -11,49 +11,35 @@
 _opcode.stack_effect -> int
 
   opcode: int
-
-  [
-  oparg: int
-  ]
+  oparg: object = None
   /
 
 Compute the stack effect of the opcode.
 [clinic start generated code]*/
 
 PyDoc_STRVAR(_opcode_stack_effect__doc__,
-"stack_effect(module, opcode, [oparg])\n"
+"sig=($module, opcode, oparg=None)\n"
 "Compute the stack effect of the opcode.");
 
 #define _OPCODE_STACK_EFFECT_METHODDEF    \
     {"stack_effect", (PyCFunction)_opcode_stack_effect, METH_VARARGS, _opcode_stack_effect__doc__},
 
 static int
-_opcode_stack_effect_impl(PyModuleDef *module, int opcode, int group_right_1, int oparg);
+_opcode_stack_effect_impl(PyModuleDef *module, int opcode, PyObject *oparg);
 
 static PyObject *
 _opcode_stack_effect(PyModuleDef *module, PyObject *args)
 {
     PyObject *return_value = NULL;
     int opcode;
-    int group_right_1 = 0;
-    int oparg = 0;
+    PyObject *oparg = Py_None;
     int _return_value;
 
-    switch (PyTuple_GET_SIZE(args)) {
-        case 1:
-            if (!PyArg_ParseTuple(args, "i:stack_effect", &opcode))
-                goto exit;
-            break;
-        case 2:
-            if (!PyArg_ParseTuple(args, "ii:stack_effect", &opcode, &oparg))
-                goto exit;
-            group_right_1 = 1;
-            break;
-        default:
-            PyErr_SetString(PyExc_TypeError, "_opcode.stack_effect requires 1 to 2 arguments");
-            goto exit;
-    }
-    _return_value = _opcode_stack_effect_impl(module, opcode, group_right_1, oparg);
+    if (!PyArg_ParseTuple(args,
+        "i|O:stack_effect",
+        &opcode, &oparg))
+        goto exit;
+    _return_value = _opcode_stack_effect_impl(module, opcode, oparg);
     if ((_return_value == -1) && PyErr_Occurred())
         goto exit;
     return_value = PyLong_FromLong((long)_return_value);
@@ -63,23 +49,31 @@
 }
 
 static int
-_opcode_stack_effect_impl(PyModuleDef *module, int opcode, int group_right_1, int oparg)
-/*[clinic end generated code: output=4689140ffda2494a input=056816407c3d4284]*/
+_opcode_stack_effect_impl(PyModuleDef *module, int opcode, PyObject *oparg)
+/*[clinic end generated code: output=4fe636f5db87c0a9 input=2d0a9ee53c0418f5]*/
 {
     int effect;
+    int oparg_int = 0;
     if (HAS_ARG(opcode)) {
-        if (!group_right_1) {
+        PyObject *i_object;
+        if (oparg == Py_None) {
             PyErr_SetString(PyExc_ValueError,
                     "stack_effect: opcode requires oparg but oparg was not specified");
             return -1;
         }
+        i_object = PyNumber_Index(oparg);
+        if (!i_object)
+            return -1;
+        oparg_int = (int)PyLong_AsLong(oparg);
+        if ((oparg_int == -1) && PyErr_Occurred())
+            return -1;
     }
-    else if (group_right_1) {
+    else if (oparg != Py_None) {
         PyErr_SetString(PyExc_ValueError,
                 "stack_effect: opcode does not permit oparg but oparg was specified");
         return -1;
     }
-    effect = PyCompile_OpcodeStackEffect(opcode, oparg);
+    effect = PyCompile_OpcodeStackEffect(opcode, oparg_int);
     if (effect == PY_INVALID_STACK_EFFECT) {
             PyErr_SetString(PyExc_ValueError,
                     "invalid opcode or oparg");
diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h
index 86fd796..02911ba 100644
--- a/Modules/clinic/zlibmodule.c.h
+++ b/Modules/clinic/zlibmodule.c.h
@@ -276,6 +276,8 @@
     return return_value;
 }
 
+#if defined(HAVE_ZLIB_COPY)
+
 PyDoc_STRVAR(zlib_Compress_copy__doc__,
 "sig=($self)\n"
 "Return a copy of the compression object.");
@@ -292,6 +294,14 @@
     return zlib_Compress_copy_impl(self);
 }
 
+#endif /* defined(HAVE_ZLIB_COPY) */
+
+#ifndef ZLIB_COMPRESS_COPY_METHODDEF
+    #define ZLIB_COMPRESS_COPY_METHODDEF
+#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
+
+#if defined(HAVE_ZLIB_COPY)
+
 PyDoc_STRVAR(zlib_Decompress_copy__doc__,
 "sig=($self)\n"
 "Return a copy of the decompression object.");
@@ -308,6 +318,12 @@
     return zlib_Decompress_copy_impl(self);
 }
 
+#endif /* defined(HAVE_ZLIB_COPY) */
+
+#ifndef ZLIB_DECOMPRESS_COPY_METHODDEF
+    #define ZLIB_DECOMPRESS_COPY_METHODDEF
+#endif /* !defined(ZLIB_DECOMPRESS_COPY_METHODDEF) */
+
 PyDoc_STRVAR(zlib_Decompress_flush__doc__,
 "sig=($self, length=DEF_BUF_SIZE)\n"
 "Return a bytes object containing any remaining decompressed data.\n"
@@ -408,4 +424,4 @@
 
     return return_value;
 }
-/*[clinic end generated code: output=ad23316b49faf7e6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=21556008559f839c input=a9049054013a1b77]*/
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index fca852d..0646043f 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2366,21 +2366,26 @@
     converter = 'path_converter'
 
     def converter_init(self, *, allow_fd=False, nullable=False):
-        def strify(value):
-            return str(int(bool(value)))
-
         # right now path_t doesn't support default values.
         # to support a default value, you'll need to override initialize().
+        if self.default is not unspecified:
+            fail("Can't specify a default to the path_t converter!")
 
-        assert self.default is unspecified
+        if self.c_default is not None:
+            fail("Can't specify a c_default to the path_t converter!")
 
         self.nullable = nullable
         self.allow_fd = allow_fd
 
+    def pre_render(self):
+        def strify(value):
+            return str(int(bool(value)))
+
+        # add self.py_name here when merging with posixmodule conversion
         self.c_default = 'PATH_T_INITIALIZE("{}", {}, {})'.format(
             self.function.name,
-            strify(nullable),
-            strify(allow_fd),
+            strify(self.nullable),
+            strify(self.allow_fd),
             )
 
     def cleanup(self):
@@ -2397,7 +2402,7 @@
 
 
 [python start generated code]*/
-/*[python end generated code: output=da39a3ee5e6b4b0d input=d702d58a8469cc7d]*/
+/*[python end generated code: output=da39a3ee5e6b4b0d input=5c9f456f53244fc3]*/
 
 /*[clinic input]
 
@@ -11122,6 +11127,15 @@
 #endif   /* MS_WINDOWS */
 
 
+/*[clinic input]
+dump buffer
+[clinic start generated code]*/
+
+#ifndef OS_TTYNAME_METHODDEF
+    #define OS_TTYNAME_METHODDEF
+#endif /* !defined(OS_TTYNAME_METHODDEF) */
+/*[clinic end generated code: output=5d071bbc8f49ea12 input=524ce2e021e4eba6]*/
+
 
 static PyMethodDef posix_methods[] = {