Rev 4734: A quick note about how I'd *like* to do things. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple

John Arbash Meinel john at arbash-meinel.com
Fri Oct 2 03:21:20 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple

------------------------------------------------------------
revno: 4734
revision-id: john at arbash-meinel.com-20091002022112-w4ispnaes2t78pty
parent: john at arbash-meinel.com-20091001213436-d7vbe0xr17eave03
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-static-tuple
timestamp: Thu 2009-10-01 21:21:12 -0500
message:
  A quick note about how I'd *like* to do things.
  
  Basically, if I could procedurally declare my API, then all of the boilerplate
  could be easily generated from that. However, it needs to be 'static' in a C
  header file, and to get that you'd have to generate it from some other source
  or have a *lot* more voodoo in your C pre-processor code. Shame that C sucks so
  much. Note that Pyrex gets this right, where doing all the boilerplate amounts
  to adding 'api' to your definition. Aka
      cdef api object myfunc(int foo)
  Is enough to generate all the boilerplate C headers, etc you would need.
  It is unfortunate I can't really use that here, because I want a pure C class
  to avoid the python garbage collector.
-------------- next part --------------
=== modified file 'bzrlib/_export_c_api.h'
--- a/bzrlib/_export_c_api.h	2009-10-01 21:34:36 +0000
+++ b/bzrlib/_export_c_api.h	2009-10-02 02:21:12 +0000
@@ -68,4 +68,34 @@
     return -1;
 }
 
+/* Note:
+ *  It feels like more could be done here. Specifically, if you look at
+ *  _static_tuple_c.h you can see some boilerplate where we have:
+ * #ifdef STATIC_TUPLE_MODULE  // are we exporting or importing
+ * static RETVAL FUNCNAME PROTO;
+ * #else
+ * static RETVAL (*FUNCNAME) PROTO;
+ * #endif
+ * 
+ * And then in _static_tuple_c.c we have
+ * int setup_c_api()
+ * {
+ *   _export_function(module, #FUNCNAME, FUNCNAME, #PROTO);
+ * }
+ *
+ * And then in _static_tuple_c.h import_##MODULE
+ * struct function_definition functions[] = {
+ *   {#FUNCNAME, (void **)&FUNCNAME, #RETVAL #PROTO},
+ *   ...
+ *   {NULL}};
+ *
+ * And some similar stuff for types. However, this would mean that we would
+ * need a way for the C preprocessor to build up a list of definitions to be
+ * generated, and then expand that list at the appropriate time.
+ * I would guess there would be a way to do this, but probably not without a
+ * lot of magic, and the end result probably wouldn't be very pretty to
+ * maintain. Perhaps python's dynamic nature has left me jaded about writing
+ * boilerplate....
+ */
+
 #endif // _EXPORT_C_API_H_



More information about the bazaar-commits mailing list