192 static PyObject *
193 pygetxattr(PyObject *self, PyObject *args)
194 {
195 PyObject *myarg;
196 target_t tgt;
197 int nofollow = 0;
198 char *attrname = NULL;
199 char *buf;
200 ssize_t nalloc, nret;
201 PyObject *res;
202
203 /* Parse the arguments */
204 if (!PyArg_ParseTuple(args, "Oet|i", &myarg, NULL, &attrname, &nofollow))
when _PyArg_ParseTuple_SizeT() succeeds
taking False path
205 return NULL;
206 if(!convertObj(myarg, &tgt, nofollow)) {
when considering value == (int)0 from xattr.c:206
taking True path
207 res = NULL;
208 goto freearg;
209 }
210
211 /* Find out the needed size of the buffer */
212 if((nalloc = _get_obj(&tgt, attrname, NULL, 0)) == -1) {
213 res = PyErr_SetFromErrno(PyExc_IOError);
214 goto freetgt;
215 }
216
217 /* Try to allocate the memory, using Python's allocator */
218 if((buf = PyMem_Malloc(nalloc)) == NULL) {
219 res = PyErr_NoMemory();
220 goto freetgt;
221 }
222
223 /* Now retrieve the attribute value */
224 if((nret = _get_obj(&tgt, attrname, buf, nalloc)) == -1) {
225 res = PyErr_SetFromErrno(PyExc_IOError);
226 goto freebuf;
227 }
228
229 /* Create the string which will hold the result */
230 res = PyBytes_FromStringAndSize(buf, nret);
231
232 freebuf:
233 /* Free the buffer, now it is no longer needed */
234 PyMem_Free(buf);
235 freetgt:
236 free_tgt(&tgt);
237 freearg:
238 PyMem_Free(attrname);
239
240 /* Return the result */
241 return res;
242 }
returning (PyObject*)NULL without setting an exception