Commit Graph

53 Commits

Author SHA1 Message Date
David Malcolm 59378e5220 fix the signatures of the METH_NOARGS callbacks
Various Python method callbacks have signatures of the form:

  static PyObject *
  foo(some_object_subclass *obj)

and are registered within the PyMethodDef tables with the METH_NOARGS
flag [1], with a cast to (PyCFunction) due to the PyObject/subclass
mismatch.

However, such callbacks do receive two arguments: they are invoked with
a signature of this form:

  static PyObject *
  foo(some_object_subclass *obj, PyObject *ignored)

The CPython interpreter only uses METH_NOARGS to allow it to pass NULL as the
second parameter: there are still two parameters.  The dispatch code is in
Python's Python/ceval.c:call_function:

            if (flags & METH_NOARGS && na == 0) {
                C_TRACE(x, (*meth)(self,NULL));
            }

The fact that this has ever worked may be a coincidence of the
platform/compiler's calling conventions, and I don't think it's guaranteed to
keep working.

[1] http://docs.python.org/c-api/structures.html#METH_NOARGS

Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
2012-01-02 08:39:39 +01:00
David Malcolm a9e6f2ab9d mark strings extracted from PyArg_Parse* as "const"
- Various places within the bindings use PyArg_ParseTuple[AndKeywords] to
  extract (char*) string arguments. These are pointers to the internal
  representation of a PyStringObject, and shouldn't be modified, hence
  it's safest to explicitly mark these values as (const char*), rather
  than just (char*).

Signed-off-by: Ales Kozumplik <akozumpl@redhat.com>
2011-12-22 10:49:56 +01:00
Panu Matilainen 99f9c67ad4 Python bindings dont need our debug.h for anything 2011-03-09 15:06:11 +02:00
Panu Matilainen e8f777b69d Switch python bindings to use rpm(Dbi)TagVal as appropriate
- None of these are true enum uses as the value typically originates
  from python integers etc.
2010-10-22 11:57:38 +03:00
Ville Skyttä e50e3d14e5 Document deprecation of mi.count() and ds.Count(). 2010-03-24 10:37:22 +02:00
Panu Matilainen 40f788a7bf Add __bool__() / __nonzero__() method to python rpmmi objects (ticket #153)
- Objects supporting __len__() use (len > 0) for boolean representation,
  which normally makes sense but as the match iterator count is often
  zero despite the iterator actually existing and returning something,
  and breaks existing code (rpmlint at least)
- Adding a __bool__() (known as __nonzero__() in Python < 3) method
  returning true for non-NULL iterator fixes this and gives more
  meaningful answers than pre 4.8.0 which simply always returned True
2010-03-24 09:53:25 +02:00
David Malcolm 4b8e0ebde6 Generalize type object initialization to work with both Python 2.* and Python 3.*
The layout of PyVarObject changed between python 2 and python 3, and this leads
to the existing code for all of the various PyTypeObject initializers failing to
compile with python 3

Change the way we initialize these structs to use PyVarObject_HEAD_INIT directly,
rather than merely PyObject_HEAD_INIT, so that it compiles cleanly with both major
versions of Python
2009-10-19 11:02:13 +03:00
David Malcolm 7b51c4a1eb Generalize access to ob_type so that they work with both Python 2.* and Python 3.*
Python 2's various object structs use macros to implement common fields at the top of each
struct.

Python 3's objects instead embed a PyObject struct as the first member within the more refined
object structs.

Use the Py_TYPE() macro when accessing ob_type in order to encapsulate this difference.
2009-10-19 10:50:24 +03:00
Panu Matilainen dc6946e72e Revert explicit PyErr_NoMemory() returns to just returning NULL
- tp_alloc failing is likely to be OOM but we dont know that for a fact,
  and the failing method is responsible for setting the exception
2009-10-09 11:57:46 +03:00
Panu Matilainen 9c88ea2c87 Deprecation tweaks
- use PyErr_WarnEx() for better control and leave the tracking up to python
- use PendingDeprecationWarning for now
- document the replacing functionality in the deprecation messages
- make hdr.sprintf() just an alias to hdr.format() without deprecating,
  at least for now it'd be only a gratuitous incompatible change on python side
2009-10-01 15:12:06 +03:00
Panu Matilainen 8b704a6bf8 Oops, these are mappings, not dicts... 2009-10-01 14:55:55 +03:00
Panu Matilainen 909982b1b5 Deprecate custom foo.count() methods, support len() instead 2009-09-30 16:45:46 +03:00
Panu Matilainen 2507ab6797 Enable subtyping on the rest of our type-objects
- not very useful atm as various places return hard-wired built-in types
2009-09-24 13:57:55 +03:00
Panu Matilainen 74c1040dbc Call (sub)type tp_free from destructors
- more preliminaries for subtyping
- remove pointless NULL checks
2009-09-24 12:52:32 +03:00
Panu Matilainen 36ada6c116 Make object allocation type agnostic
- pass (sub)type down to wrappers
- call subtype tp_alloc() instead of PyObject_New()
- preliminaries for allowing subtyping
2009-09-24 11:42:17 +03:00
Panu Matilainen 282efb6d4c Turn tagNumFromPyObject() into an object converter interface
- permits direct validation and conversion from arg parsing
2009-09-23 12:28:47 +03:00
Panu Matilainen 39d79f9142 Rename python system.h for disambiguation 2009-09-22 23:02:47 +03:00
Panu Matilainen 14d5aaedcb Lose the empty doxygen markers
- nothing wrong with comments but empty comment placeholders
  are not exactly useful
2009-09-22 22:42:06 +03:00
Panu Matilainen 864220c441 Put some consistency to python object creation
- all type object creation goes through foo_Wrap() which handle OOM
  and all type specific initialization
2009-09-22 21:53:21 +03:00
Panu Matilainen ed557bbcf0 Make all python object creation wrappers return PyObject pointers
- this way the only place where casts are needed are in the wrapper itself
2009-09-22 21:24:55 +03:00
Panu Matilainen 0cb5de3fc0 Lose unnecessary next() methods
- python adds next() methods for objects supporting iterators
2009-09-22 20:50:41 +03:00
Panu Matilainen 0793b2cf23 All rpm-python iterators are self-iterators, just use PyObject_SelfIter 2009-09-22 20:20:07 +03:00
Panu Matilainen da74188fa6 Sanitize python object -> tag number exception handling
- raise exception in tagNumFromPyObject(), not in 12 different callers
- check against RPMTAG_NOT_FOUND consistently instead of -1 and whatnot
- unknown tags are value, not key or type errors
2009-09-22 19:19:02 +03:00
Panu Matilainen 96a1b0a681 Use Py_RETURN_NONE macro for returning None everywhere 2009-09-22 17:49:53 +03:00
Panu Matilainen ca6591e86c Use generic python get/set attribute functions directly where appropriate
- no point in wrapping all this stuff in our own functions
2009-09-22 17:27:44 +03:00
Panu Matilainen ae1fd3fa47 Make the python object structures opaque 2009-09-22 16:47:07 +03:00
Panu Matilainen ae1e7d8389 We dont support ancient python versions... 2009-09-22 16:28:58 +03:00
Panu Matilainen d718b12f5b Mass convert (back) to rpmTag as it's usable everywhere now
- cast away a few cases where the enum usage causes ridiculous amount
  of compiler warnings from unhandled switch-cases
2008-02-05 17:42:19 +02:00
Panu Matilainen 99faa2735b rpmlib.h mass eviction
- explicitly include what's really needed instead
- document remaining uses
2008-01-30 13:53:51 +02:00
Panu Matilainen 7e56c6355b Use rpm_tag_t everywhere for rpm (header) tag type
- typedef'ed as int32_t for now, negative values used in some places for
  error cases
- easy to grep, easy to change...
- add RPMTAG_NOT_FOUND define, used in place of -1 "magic",
2007-12-13 19:32:37 +02:00
Panu Matilainen 9ce13e09ef Switch to <rpm/foo.h> style for public headers
- adjust include paths accordingly
2007-12-08 14:02:32 +02:00
Ralf Corsépius abeea80a38 Use #include <x.h> syntax to include public headers. 2007-11-23 06:46:19 +01:00
Ralf Corsépius f25c04c1e4 Include "rpmlib.h" instead of <rpmlib.h>. 2007-10-28 06:47:31 +01:00
Ralf Corsépius 759e91bf4a Include "rpmdb.h" instead of <rpmdb.h>. 2007-10-28 06:42:55 +01:00
Ralf Corsépius 3aad15624e Remove split tags. 2007-09-11 15:28:26 +02:00
Panu Matilainen 48048a3930 Ts/db reference counting for match-iterators in python (rhbz#241751)
Adds additional refcounting to the python level ts/db object to avoid
anonymous ts/db from getting deleted while still iterating over it.
2007-06-07 21:51:59 +03:00
pauln 24e6f8633e Add kwargs everywhere - courtesy of pjones@redhat.com
CVS patchset: 7582
CVS date: 2004/11/17 17:05:39
2004-11-17 17:05:39 +00:00
jbj 0deeb05eed - python: include Python.h before glibc features.h.
CVS patchset: 7055
CVS date: 2004/01/01 16:34:10
2004-01-01 16:34:10 +00:00
jbj 5e20d90422 splint fiddles, no warnings.
CVS patchset: 6961
CVS date: 2003/12/01 19:15:38
2003-12-01 19:15:38 +00:00
jbj 3dcfeb3f9a Merge changes from rpm-4.2.1 development.
CVS patchset: 6959
CVS date: 2003/11/23 19:50:52
2003-11-23 19:50:52 +00:00
jbj 3db8afedc0 Use getattro/setattro throughout.
Convert to mpfprintlin from diddled mpprintln.

CVS patchset: 6811
CVS date: 2003/05/04 17:34:53
2003-05-04 17:34:53 +00:00
jbj c6156e0abd Doxygen doco markup.
CVS patchset: 6760
CVS date: 2003/04/17 17:17:27
2003-04-17 17:17:27 +00:00
jbj 2452c14619 Add rpmfts-py.[ch] bindings for fts(3) from rpmio.
splint fiddles.

CVS patchset: 5932
CVS date: 2002/12/11 00:12:17
2002-12-11 00:12:17 +00:00
jbj fe6043016c Add tp_{init,alloc,new,free} methods to rpmts.
Use PyObject_{New,Del} consistently throughout.

CVS patchset: 5931
CVS date: 2002/12/10 19:46:03
2002-12-10 19:46:03 +00:00
jbj a2e69e7622 python: gilding lilies.
CVS patchset: 5915
CVS date: 2002/12/04 02:01:47
2002-12-04 02:01:47 +00:00
jbj 644401875d - python: include instance in IDTXload, filename in IDTXglob, return
- python: argument to ts.addErase (if integer) deletes that instance.
- python: rpmmi methods to return this instance, and number of members.

CVS patchset: 5620
CVS date: 2002/08/09 23:14:10
2002-08-09 23:14:10 +00:00
jbj 5211039a20 - python: the death of rpmdb-py.[ch], use ts.fooDB() methods instead.
- python: the death of rpm.headerFromPackage(), use ts.hdrFromFdno().
- python: permit direct ts.dbMatch() python iterations.
- python: the death of rpm.checksig(), use ts.hdrFromFdno() instead.

CVS patchset: 5603
CVS date: 2002/08/05 21:46:50
2002-08-05 21:46:50 +00:00
jbj 81fef98480 - python: add ts.hdrCheck(), ts.rebuildDB() methods.
- python: iterating on an ts object returns transaction elements now.
- add yellowdog as vendor.

CVS patchset: 5570
CVS date: 2002/07/25 00:13:25
2002-07-25 00:13:25 +00:00
jbj c499cd119c Remove foo.iter() method, use tp_iter mechanism, for rpmmi/rpmds/rpmfi.
CVS patchset: 5559
CVS date: 2002/07/19 20:26:38
2002-07-19 20:26:38 +00:00
jbj 3ea74aa3c7 - python: sanity check fixes on rpmts/rpmte methods.
CVS patchset: 5554
CVS date: 2002/07/14 21:23:29
2002-07-14 21:23:29 +00:00