273 static PyObject *
274 xattr_get(PyObject *self, PyObject *args, PyObject *keywds)
275 {
276 PyObject *myarg;
277 target_t tgt;
278 int nofollow = 0;
279 char *attrname = NULL, *namebuf;
280 const char *fullname;
281 char *buf;
282 char *ns = NULL;
283 ssize_t nalloc, nret;
284 PyObject *res;
285 static char *kwlist[] = {"item", "name", "nofollow", "namespace", NULL};
286
287 /* Parse the arguments */
288 if (!PyArg_ParseTupleAndKeywords(args, keywds, "Oet|iz", kwlist,
when _PyArg_ParseTupleAndKeywords_SizeT() succeeds
taking False path
289 &myarg, NULL, &attrname, &nofollow, &ns))
290 return NULL;
291 if(!convertObj(myarg, &tgt, nofollow)) {
when considering value == (int)0 from xattr.c:291
taking True path
292 res = NULL;
293 goto freearg;
294 }
295
296 fullname = merge_ns(ns, attrname, &namebuf);
297
298 /* Find out the needed size of the buffer */
299 if((nalloc = _get_obj(&tgt, fullname, NULL, 0)) == -1) {
300 res = PyErr_SetFromErrno(PyExc_IOError);
301 goto freetgt;
302 }
303
304 /* Try to allocate the memory, using Python's allocator */
305 if((buf = PyMem_Malloc(nalloc)) == NULL) {
306 res = PyErr_NoMemory();
307 goto freenamebuf;
308 }
309
310 /* Now retrieve the attribute value */
311 if((nret = _get_obj(&tgt, fullname, buf, nalloc)) == -1) {
312 res = PyErr_SetFromErrno(PyExc_IOError);
313 goto freebuf;
314 }
315
316 /* Create the string which will hold the result */
317 res = PyBytes_FromStringAndSize(buf, nret);
318
319 /* Free the buffers, they are no longer needed */
320 freebuf:
321 PyMem_Free(buf);
322 freenamebuf:
323 PyMem_Free(namebuf);
324 freetgt:
325 free_tgt(&tgt);
326 freearg:
327 PyMem_Free(attrname);
328
329 /* Return the result */
330 return res;
331 }
returning (PyObject*)NULL without setting an exception