(original) (raw)
On Tue, Jan 14, 2014 at 3:12 PM, Antoine Pitrou <solipsis@pitrou.net> wrote:
On Tue, 14 Jan 2014 12:22:12 -0800I'm +1 on the sidefile approach. +0 on the various buffer approaches.
Larry Hastings <larry@hastings.org> wrote:
>
> � � https://bitbucket.org/larry/clinic-buffer-samples/src
>
> In it I converted Modules/_pickle.c four different ways. �There's a
> README, please read it.
\-0.5 on the current "sprinkled everywhere" approach.
the file. �Although, I do wonder if we can simplify things a bit for the "sideline" file
by using macros and headers. �You could write the original definition like:
� /\*\[clinic input begin\]
� \_pickle.PicklerMemoProxy.copy
��
� � self: PicklerMemoProxyObject
��
� Copy the memo to a new object.
� \[clinic input end\]\*/
� static PyObject \*
� \_PICKLE\_PICKLERMEMOPROXY\_COPY(PyObject \*self, PyObject \*Py\_UNUSED(ignored))
� {
� � � ...
� }
and then generate a header like:
� PyDoc\_STRVAR(\_pickle\_PicklerMemoProxy\_copy\_\_doc\_\_,
� "copy()\\n"
� "Copy the memo to a new object.");
� #define \_PICKLE\_PICKLERMEMOPROXY\_COPY\_METHODDEF � �\\
� � � {"copy", (PyCFunction)\_pickle\_PicklerMemoProxy\_copy, METH\_NOARGS, \_pickle\_PicklerMemoProxy\_copy\_\_doc\_\_},
� static PyObject \*
� \_pickle\_PicklerMemoProxy\_copy\_impl(PicklerMemoProxyObject \*self);
� #define \_PICKLE\_PICKLERMEMOPROXY\_COPY(a, b) \\
� \_pickle\_PicklerMemoProxy\_copy(PyObject \*self, PyObject \*Py\_UNUSED(ignored)) \\
� { \\
� � � PyObject \*return\_value = NULL; \\
� � � � � � � � � � � � � � � � � � �\\
� � � return\_value = \_pickle\_PicklerMemoProxy\_copy\_impl((PicklerMemoProxyObject \*)self); \\
� � � � � � � � � � � � � � � � � � �\\
� � � return return\_value; \\
� } \\
� � \\
� static PyObject \* \\
� \_pickle\_PicklerMemoProxy\_copy\_impl(PicklerMemoProxyObject \*self) \\
This way the docstring, method def, and argument parsing code is out of the way, but
you still retain the helpful comments in the implementation file. �I am pretty sure this
gets around the "where do I inject the side file part" too. �You also don't have to do
much more editing than the original scheme: write the clinic comment, #iinclude a
header, and then apply the macro.
That being said, this is somewhat half baked and some folks don't like macros. �I just
wanted to throw it out there since it seems like a reasonable compromise.
FWIW, I have worked on several large programs that generate C header and implementation
files on the side and it has never bothered me that much. �Well, unless, something goes
wrong :-)
# Meador