Commits

larry committed 9f7a2da

Minor bugfixes: s* and z*, and [python] works again.

Comments (0)

Files changed (3)

Modules/posixmodule.c

 
 #endif /* __APPLE__ */
 
+/*[python]
+
+class Clinic:
+  pass
+
+clinic = Clinic()
+
+clinic.write_impl_file()
+
+[python]*/
+
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
     #define OS_STAT_DIR_FD_CONVERTER dir_fd_unavailable
 #endif
 
+/*[python]
+
+class Clinic:
+  def register_type(self, t):
+    def registerer(cls):
+      return cls
+    return registerer
+
+clinic = Clinic()
+
+# register path type
+
+class ClinicExtension:
+  pass
+
+@clinic.register_type('path_t')
+class ClinicPath(ClinicExtension):
+
+  format_unit = "O&"
+
+  def __init__(self, name):
+    super().__init__(name)
+    self.flags['converter'] = path_converter
+
+  def default(self, s):
+    self.allow_fds = int(default)
+    return "".join([
+        "PATH_T_INITIALIZE(",
+        repr(self.function.name),
+        ", ",
+        "1" if self.nullable else "0",
+        ", ",
+        str(self.allow_fds),
+        ")"
+        ])
+
+  def cleanup(self):
+    return "path_cleanup(&" + self.name + ");"
+
+[python]*/
+
+/*[python end:adc83b19e793491b1c6ea0fd8b46cd9f32e592fc]*/
+
 /*[clinic]
 os.stat -> stat result
 
 Py_buffer (bytes bytearray buffer) = y*
 const char * length (bytes buffer) = y#
 
-Py_buffer * zeroes (str bytes bytearray buffer) = s*
-Py_buffer * nullable zeroes (str bytes bytearray buffer) = z*
+Py_buffer zeroes (str bytes bytearray buffer) = s*
+Py_buffer nullable zeroes (str bytes bytearray buffer) = z*
 const char * length zeroes (str bytes buffer) = s#
 const char * length nullable zeroes (str bytes buffer) = z#
 
 		builtins.print = old_print
 
 		output = "".join(faux.output)
-		if output[-1] == '\n':
+		if output and output[-1] == '\n':
 			output = output[:-1]
 		self.output.append(output)
 		data = output.encode('utf-8') + b'\n'
 Clinic DSL start     | /*[clinic]
 Function declaration | module.function_name -> return_annotation
 Function flags       | flag flag2 flag3=value
-Argument declaration |       type name = default
-Argument flags       |       flag flag2 flag3=value
-Argument docstring   |           Lorem ipsum dolor sit amet, consectetur
+Parameter declaration|       type name = default
+Parameter flags      |       flag flag2 flag3=value
+Parameter docstring  |           Lorem ipsum dolor sit amet, consectetur
                      |           adipisicing elit, sed do eiusmod tempor
 Function docstring   | Lorem ipsum dolor sit amet, consectetur adipisicing
                      | elit, sed do eiusmod tempor incididunt ut labore et
   Like Python itself, whitespace is significant in the Argument Clinic DSL.
   The first line  of the "function" section is the declaration; all subsequent
   lines at the same indent are function flags.  Once you indent, the first
-  line is an argument declaration; subsequent lines at that indent are
-  argument flags.  Indent one more time for the lines of the argument
+  line is a parameter declaration; subsequent lines at that indent are
+  parameter flags.  Indent one more time for the lines of the parameter
   docstring.  Finally, outdent back to the same level as the function
   declaration for the function docstring.
 
 
   The return annotation is optional.
 
-Argument Declaration
+Parameter Declaration
 ====================
 
   The "type" is a C type.  If it's a pointer type, you must specify
   The "name" must be a legal C identifier.
 
   The "default" is a Python value.  Default values are optional;
-  if not specified you must omit the equals sign too.  Arguments
+  if not specified you must omit the equals sign too.  Parameters
   which don't have a default are required.  The default value is
-  dynamically assigned, "live" in the generated C code.
+  dynamically assigned, "live" in the generated C code, and although
+  it's specified as a Python value, it's translated into a native
+  C value in the generated C code.
 
-  It's explicitly permitted to end the argument declaration line
-  with a semicolon.
+  It's explicitly permitted to end the parameter declaration line
+  with a semicolon.  The semicolon is optional; it's permitted to
+  allow cutting and pasting from C code.  The preferred style is
+  without the semicolon.
 
 Flags
 =====
                       By default this is the name of the function from
                       the DSL, only with periods replaced by underscores.
 
-  positional-only   : This function only supports positional arguments,
-                      not keyword arguments.  See "Functions With Positional-
-                      Only Arguments" section below.
+  positional-only   : This function only supports positional parameters,
+                      not keyword parameters.  See "Functions With
+                      Positional-Only Parameters" section below.
 
-  Supported flags for arguments:
+  Supported flags for parameters:
 
   bitwise      : If the Python integer passed in is signed, copy the
                  bits directly even if it is negative.  Only valid
                  for unsigned integer types.
 
-  converter    : Backwards-compatibility support for argument "converter"
+  converter    : Backwards-compatibility support for parameter "converter"
                  functions.  The value should be the name of the converter
-                 function in C.  Only valid when the type of the argument
+                 function in C.  Only valid when the type of the parameter
                  is void *.
 
   default      : The Python value to use in place of the parameter's actual
                  default.
 
 	encoding     : Encoding to use when encoding a Unicode string to a char *.
-	               Only valid when the type of the argument is char *.
+	               Only valid when the type of the parameter is char *.
 
-  group=       : This argument is part of a group of options that must either
-                 all be specified or none specified.  Arguments in the same
+  group=       : This parameter is part of a group of options that must either
+                 all be specified or none specified.  parameters in the same
                  "group" must be contiguous.  The value of the group flag
                  is the name used for the group.  Only valid for functions
                  marked "positional-only"; see "Functions With Positional-
-                 Only Arguments" section below.
+                 Only Parameters" section below.
 
 	immutable    : Only accept immutable values.
 
-	keyword-only : This parameter (and all following parameters) is keyword-only.
-                 Keyword-only parameters must also be optional.  Not valid for
-                 positional-only functions.
+	keyword-only : This parameter (and all subsequent parameters) is
+                 keyword-only.  Keyword-only parameters must also be
+                 optional.  Not valid for positional-only functions.
 
 	length       : This is an iterable type, and we also want its length.  The
                  DSL will generate a second Py_ssize_t variable; its name will
-                 be this argument's name appended with "_length".
+                 be this parameter's name appended with "_length".
 
-	nullable     : None is a legal value for this parameter.  If None is
+	nullable     : None is a legal argument for this parameter.  If None is
                  supplied on the Python side, this C parameter will be NULL.
                  Only valid for pointer types.
 
-  required     : Normally any parameter that has a default value is automatically
-                 optional.  A parameter that has "required" set will be
-                 considered required (non-optional) even if it has a default
-                 value.  The generated documentation will also not show any
-                 default value.
+  required     : Normally any parameter that has a default value is
+                 automatically optional.  A parameter that has "required"
+                 set will be considered required (non-optional) even if
+                 it has a default value.  The generated documentation
+                 will also not show any default value.
 
 	types        : Space-separated list of acceptable Python types for this
                  object.  There are also four special-case types which
 
 	zeroes       : This parameter is a string type, and its value should be
                  allowed to have embedded zeroes.  Not valid for all
-                 varieties of string arguments.
+                 varieties of string parameters.
 
 
 Output
 of the builtin in the body there.  (It's a bit strange, but oddly
 convenient.)
 
-Argument Clinic will define the arguments of the impl function for you.
+Argument Clinic will define the parameters of the impl function for you.
 The function will take the "self" parameter passed in originally, all
-the arguments you define, and possibly some extra arguments ("length"
-arguments, and/or "group" arguments, see next section).
+the parameters you define, and possibly some extra generated parameters
+("length" and/or "group" parameters, see next section).
 
 Argument Clinic also writes a checksum for the output section.  This
 is a valuable safety feature: if you modify the output by hand, Clinic
 will notice that the checksum doesn't match, and will refuse to
 overwrite the file.  (You can force Clinic to overwrite with the "-f"
-command-line parameter; Clinic will also ignore the checksums when
-using the "-o" command-line parameter.)
+command-line argument; Clinic will also ignore the checksums when
+using the "-o" command-line argument.)
 
 
-Functions With Positional-Only Arguments
-========================================
+Functions With Positional-Only Parameters
+=========================================
 
 A significant fraction of Python builtins implemented in C use the
 older positional-only API for processing arguments (PyArg_ParseTuple).
 In some instances, these builtins parse their arguments differently
 based on how many arguments were passed in.  This can provide some
-bewildering flexibility: there may be groups of optional arguments,
+bewildering flexibility: there may be groups of optional parameters,
 which must either all be specified or none specified.  And occasionally
 these groups are on the *left*!  (For example: curses.window.addch().)
 
-Argument Clinic supports these legacy use-cases with a slightly altered
-mode of operation.  First, set the flag "positional-only" on the entire
-function.  Then, for every group of arguments that is collectively
-optional, add a "group=" flag with a unique string to all the arguments
-in that group.  Note that these groups can be to the left or right of
-any required arguments!
+Argument Clinic supports these legacy use-cases with a special set
+of flags.  First, set the flag "positional-only" on the entire
+function.  Then, for every group of parameters that is collectively
+optional, add a "group=" flag with a unique string to all the
+parameters in that group.  Note that these groups are permitted on
+the right *or left* of any required parameters!  However, all groups
+(including the group of required parameters) must be contiguous.
 
 The impl function generated by Clinic will add an extra parameter for
-every group, "int <group>_group".  This parameter will be nonzero if
+every group, "int <group>_group".  This argument will be nonzero if
 the group was specified on this call, and zero if it was not.
 
-Note that when operating in this mode, you cannot specify defaults to
-parameters.  You can simulate defaults by putting default arguments
-in individual groups--but generally speaking it's better to simply not
+Note that when operating in this mode, you cannot specify default
+arguments.  You can simulate defaults by putting parameters in
+individual groups and detecting whether or not they were
+specified--but generally speaking it's better to simply not
 use "positional-only" where it isn't absolutely necessary.  (TBD: It
 might be possible to relax this restriction.  But adding default
 arguments into the mix of groups would seemingly make calculating which
   in the middle of the output, something like this:
 
    /*[clinic]
-     ... prototype and arguments (including docstrings for arguments) goes here
+     ... prototype and parameters (including parameter docstrings) go here
    [clinic]*/
    ... some output ...
    /*[clinic docstring start]*/