GDB (API)
/home/stan/gdb/src/gdb/python/py-newobjfileevent.c
Go to the documentation of this file.
00001 /* Python interface to new object file loading events.
00002 
00003    Copyright (C) 2011-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "py-event.h"
00022 
00023 static PyTypeObject new_objfile_event_object_type
00024     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
00025 
00026 static PyObject *
00027 create_new_objfile_event_object (struct objfile *objfile)
00028 {
00029   PyObject *objfile_event;
00030   PyObject *py_objfile;
00031 
00032   objfile_event = create_event_object (&new_objfile_event_object_type);
00033   if (!objfile_event)
00034     goto fail;
00035 
00036   /* Note that objfile_to_objfile_object returns a borrowed reference,
00037      so we don't need a decref here.  */
00038   py_objfile = objfile_to_objfile_object (objfile);
00039   if (!py_objfile || evpy_add_attribute (objfile_event,
00040                                          "new_objfile",
00041                                          py_objfile) < 0)
00042     goto fail;
00043 
00044   return objfile_event;
00045 
00046  fail:
00047   Py_XDECREF (objfile_event);
00048   return NULL;
00049 }
00050 
00051 /* Callback function which notifies observers when a new objfile event occurs.
00052    This function will create a new Python new_objfile event object.
00053    Return -1 if emit fails.  */
00054 
00055 int
00056 emit_new_objfile_event (struct objfile *objfile)
00057 {
00058   PyObject *event;
00059 
00060   if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
00061     return 0;
00062 
00063   event = create_new_objfile_event_object (objfile);
00064   if (event)
00065     return evpy_emit_event (event, gdb_py_events.new_objfile);
00066   return -1;
00067 }
00068 
00069 GDBPY_NEW_EVENT_TYPE (new_objfile,
00070                       "gdb.NewObjFileEvent",
00071                       "NewObjFileEvent",
00072                       "GDB new object file event object",
00073                       event_object_type,
00074                       static);
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines