title: True *args and **kwargs in Python C extension
body: <p>I am developing Python 3 C extension.</p>
  
  <p>Can I get the equivalent or arbitrary positional or keyword arguments?</p>
  
  <p>For instance, in Python, I can write:</p>
  
  <pre class="lang-py prettyprint-override"><code>def fun(name, parent, *args, **kwargs):
      # do something with name and parent
      # do something with args and kwargs
      pass
  </code></pre>
  
  <p>But I cannot find of a simple equivalent in C. While we can perfectly write functions with <code>PyObject* args</code> and <code>PyObject* kwargs</code>, I cannot easily "parse out" name and parent from whichever (args/kwargs) it came.</p>
  
  <p>Take:</p>
  
  
  
  <pre class="lang-c prettyprint-override"><code>static PyObject* myFunction(PyObject* self, PyObject* args, PyObject* kwargs) {
      char* kwds[] = {"parent", "name", NULL};
      PyObject* name = NULL;
      PyObject* parent = NULL;
      if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO", kwds, &amp;parent, &amp;name)) {
          goto errorParseTupleAndKeywords;
      }
      /* Do something with name and parent */
      /* parent and name maybe have appeared either in args or kwargs */
      /* But I don't have any extra positional (*args) or keyword (**kwargs) here */    
  }
  </code></pre>
  
  <p>A "manual" approach that I could think of looks roughly like:</p>
  
  <pre class="lang-c prettyprint-override"><code>static PyObject* myFunction(PyObject* self, PyObject* args, PyObject* kwargs) {
      PyObject* name = NULL;
      PyObject* parent = NULL;
      int inKwargs = 0;
      // Pretend to do something with parent
      if (PyDict_GetItemString(kwargs, "parent")) {
          inKwargs++;
          PyDict_DelItemString(kwargs, "parent");
      }
      // Pretend to do something with name
      if (PyDict_GetItemString(kwargs, "name")) {
          inKwargs++;
          PyDict_DelItemString(kwargs, "name");
      }
      // Not sure if -1 works here
      PyObject* newArgs = PyTuple_GetSlice(args, inKwargs, -1); // this is *args
      // the remaining kwargs can be used as **kwargs
  }
  </code></pre>