title: c: Python API - re-write value in the argument variable
body: <p>There's a C function I want to wrap in the python package. However there's a constraint - instead of this C function to return anything, I need the result of a calculation to be written into the argument variable supplied to the function. Here's an example:</p>
  
  <pre><code>#include &lt;Python.h&gt;
  void mock_rep(int n, int *res){
      PySys_WriteStdout("LOLO %i", n);
      *res = n + 2;
  }
  </code></pre>
  
  <p>Can Python API directly interface with the memory of <code>res</code> like an R API does (in the R code this function is called with <code>.C(func, args)</code>?
  Or there's something fundamental I miss about the calling by reference in C?</p>
  
  <p>Rest of the wrapper:</p>
  
  <pre><code>
  static PyObject* mock(PyObject *self, PyObject *args){
      int n;
      int res;
      if (!PyArg_ParseTuple(args,"ii", &amp;n, &amp;res))
          return NULL;
      //return Py_BuildValue("i",res);' //commented out
      return Py_BuildValue("");
  }
  
  static PyMethodDef mainMethods[] = {
          {"mock",mock,METH_VARARGS,"Mock func"},
          {NULL,NULL,0,NULL}
  };
  
  static PyModuleDef cmath11 = {
          PyModuleDef_HEAD_INIT,
          "cmath11","Mock stuff",
          -1,
          mainMethods
  };
  
  PyMODINIT_FUNC PyInit_cmath11(void){
      return PyModule_Create(&amp;cmath11);
  }
  </code></pre>
  
  <p>Python:</p>
  
  <pre><code>from cmath11 import mock as mc
  
  res = 10
  n = 2
  mc(n, res)
  print(res)
  </code></pre>
  
  <p>I need output to be 4. So far I get 10.</p>