Ejemplo n.º 1
0
static PyObject *get_devices(PyObject *self, PyObject *args) {
    /* allocates memory for the various internal structure
    that are going to be used to retrieve device information */
    size_t index;
    size_t devices_s;
    PyObject *element;
    PyObject *item;
    struct device_t *device;
    struct device_t *devices;
    PyObject *result = PyList_New(0);

    /* retrieves the complete set of available printing
    devices and then iterates over them to convert their
    internal structure into dictionaries to be returned */
    pdevices(&devices, &devices_s);
    for(index = 0; index < devices_s; index++) {
        device = &devices[index];
        element = PyDict_New();
        item = PyString_Decode(
            device->name,
            device->name_s,
            "utf-8",
            NULL
        );
        PyDict_SetItemString(element, "name", item);
        item = PyBool_FromLong((long) device->is_default);
        PyDict_SetItemString(element, "is_default", item);
        item = PyString_Decode(
            device->media,
            device->media_s,
            "utf-8",
            NULL
        );
        PyDict_SetItemString(element, "media", item);
        item = PyFloat_FromDouble((double) device->width);
        PyDict_SetItemString(element, "width", item);
        item = PyFloat_FromDouble((double) device->length);
        PyDict_SetItemString(element, "length", item);
        PyList_Append(result, element);
    }

    /* releases the memory that was allocated for the
    device structures sequence (avoids memory leak) */
    free(devices);

    /* returns the list that has been constructed for the
    values that are going to be returned to the caller */
    return result;
}
Ejemplo n.º 2
0
/* -interp, +buf */
static inline PyObject *CReader_readStr(CReader_Buffer *buffer, char unicode)
 {
  char start[3];
  char startlen = 1;
  size_t len = 0;
  PyObject *res;

  if (!buffer->type->extend(buffer, 2)) return NULL;
  start[0] = start[1] = start[2] = buffer->buf[buffer->pos];
  if (!buffer->type->advance(buffer, 1)) return NULL;
  if (buffer->type->contains(buffer, start, 2, 0))
   {
    startlen = 3;
    if (!buffer->type->advance(buffer, 2)) return NULL;
   }
  if ((len = CReader_readStr_read(buffer, start, startlen, NULL)) == -1) return NULL;
  {
   char buf[len + 1];

   if (CReader_readStr_read(buffer, start, startlen, buf) == -1) return NULL;
   buf[len] = '\0';

   CReader_Buffer_lockInterpreter(buffer);   
   if (unicode)
    res = PyUnicode_Decode(buf, len, "utf", "strict");
   else
    res = PyString_Decode(buf, len, "ascii", "strict");
   CReader_Buffer_releaseInterpreter(buffer);
   return res;
  }
 }
Ejemplo n.º 3
0
Archivo: python.c Proyecto: ILyoan/gdb
/* Transform a gdb parameters's value into a Python value.  May return
   NULL (and set a Python exception) on error.  Helper function for
   get_parameter.  */
PyObject *
gdbpy_parameter_value (enum var_types type, void *var)
{
  switch (type)
    {
    case var_string:
    case var_string_noescape:
    case var_optional_filename:
    case var_filename:
    case var_enum:
      {
	char *str = * (char **) var;

	if (! str)
	  str = "";
	return PyString_Decode (str, strlen (str), host_charset (), NULL);
      }

    case var_boolean:
      {
	if (* (int *) var)
	  Py_RETURN_TRUE;
	else
	  Py_RETURN_FALSE;
      }

    case var_auto_boolean:
      {
	enum auto_boolean ab = * (enum auto_boolean *) var;

	if (ab == AUTO_BOOLEAN_TRUE)
	  Py_RETURN_TRUE;
	else if (ab == AUTO_BOOLEAN_FALSE)
	  Py_RETURN_FALSE;
	else
	  Py_RETURN_NONE;
      }

    case var_integer:
      if ((* (int *) var) == INT_MAX)
	Py_RETURN_NONE;
      /* Fall through.  */
    case var_zinteger:
      return PyLong_FromLong (* (int *) var);

    case var_uinteger:
      {
	unsigned int val = * (unsigned int *) var;

	if (val == UINT_MAX)
	  Py_RETURN_NONE;
	return PyLong_FromUnsignedLong (val);
      }
    }

  return PyErr_Format (PyExc_RuntimeError, 
		       _("Programmer error: unhandled type."));
}
Ejemplo n.º 4
0
/* An Objfile method which returns the objfile's file name, or None.  */
static PyObject *
objfpy_get_filename (PyObject *self, void *closure)
{
    objfile_object *obj = (objfile_object *) self;
    if (obj->objfile && obj->objfile->name)
        return PyString_Decode (obj->objfile->name, strlen (obj->objfile->name),
                                host_charset (), NULL);
    Py_RETURN_NONE;
}
Ejemplo n.º 5
0
static PyObject *
stpy_fullname (PyObject *self, PyObject *args)
{
  const char *fullname;
  struct symtab *symtab = NULL;

  STPY_REQUIRE_VALID (self, symtab);

  fullname = symtab_to_fullname (symtab);

  return PyString_Decode (fullname, strlen (fullname), host_charset (), NULL);
}
Ejemplo n.º 6
0
static PyObject *
stpy_get_filename (PyObject *self, void *closure)
{
    PyObject *str_obj;
    struct symtab *symtab = NULL;

    STPY_REQUIRE_VALID (self, symtab);

    str_obj = PyString_Decode (symtab->filename,
                               strlen (symtab->filename),
                               host_charset (), NULL);
    return str_obj;
}
Ejemplo n.º 7
0
/* Python function to get the condition expression of a breakpoint.  */
static PyObject *
bppy_get_condition (PyObject *self, void *closure)
{
  char *str;
  breakpoint_object *obj = (breakpoint_object *) self;

  BPPY_REQUIRE_VALID (obj);

  str = obj->bp->cond_string;
  if (! str)
    Py_RETURN_NONE;

  return PyString_Decode (str, strlen (str), host_charset (), NULL);
}
Ejemplo n.º 8
0
static PyObject *
stpy_get_filename (PyObject *self, void *closure)
{
  PyObject *str_obj;
  struct symtab *symtab = NULL;
  const char *filename;

  STPY_REQUIRE_VALID (self, symtab);
  filename = symtab_to_filename_for_display (symtab);

  str_obj = PyString_Decode (filename, strlen (filename),
			     host_charset (), NULL);
  return str_obj;
}
Ejemplo n.º 9
0
static PyObject *
pspy_get_filename (PyObject *self, void *closure)
{
  pspace_object *obj = (pspace_object *) self;

  if (obj->pspace)
    {
      struct objfile *objfile = obj->pspace->symfile_object_file;

      if (objfile)
	return PyString_Decode (objfile->name, strlen (objfile->name),
				host_charset (), NULL);
    }
  Py_RETURN_NONE;
}
Ejemplo n.º 10
0
static PyObject *
objfpy_get_username (PyObject *self, void *closure)
{
    objfile_object *obj = (objfile_object *) self;

    if (obj->objfile)
    {
        const char *username = obj->objfile->original_name;

        return PyString_Decode (username, strlen (username),
                                host_charset (), NULL);
    }

    Py_RETURN_NONE;
}
Ejemplo n.º 11
0
static PyObject *
stpy_get_producer (PyObject *self, void *closure)
{
  struct symtab *symtab = NULL;
  struct compunit_symtab *cust;

  STPY_REQUIRE_VALID (self, symtab);
  cust = SYMTAB_COMPUNIT (symtab);
  if (COMPUNIT_PRODUCER (cust) != NULL)
    {
      const char *producer = COMPUNIT_PRODUCER (cust);

      return PyString_Decode (producer, strlen (producer),
			      host_charset (), NULL);
    }

  Py_RETURN_NONE;
}
Ejemplo n.º 12
0
/* Python function to get the breakpoint expression.  */
static PyObject *
bppy_get_expression (PyObject *self, void *closure)
{
  char *str;
  breakpoint_object *obj = (breakpoint_object *) self;

  BPPY_REQUIRE_VALID (obj);

  if (obj->bp->type != bp_watchpoint
      && obj->bp->type != bp_hardware_watchpoint  
      && obj->bp->type != bp_read_watchpoint
      && obj->bp->type != bp_access_watchpoint)
    Py_RETURN_NONE;

  str = obj->bp->exp_string;
  if (! str)
    str = "";

  return PyString_Decode (str, strlen (str), host_charset (), NULL);
}
Ejemplo n.º 13
0
PyObject *
host_string_to_python_string (const char *str)
{
  return PyString_Decode (str, strlen (str), host_charset (), NULL);
}
Ejemplo n.º 14
0
    TRY
    {
        build_id = build_id_bfd_get (objfile->obfd);
    }
    CATCH (except, RETURN_MASK_ALL)
    {
        GDB_PY_HANDLE_EXCEPTION (except);
    }
    END_CATCH

    if (build_id != NULL)
    {
        char *hex_form = make_hex_string (build_id->data, build_id->size);
        PyObject *result;

        result = PyString_Decode (hex_form, strlen (hex_form),
                                  host_charset (), NULL);
        xfree (hex_form);
        return result;
    }

    Py_RETURN_NONE;
}

/* An Objfile method which returns the objfile's progspace, or None.  */

static PyObject *
objfpy_get_progspace (PyObject *self, void *closure)
{
    objfile_object *obj = (objfile_object *) self;

    if (obj->objfile)