Complete the Python 2 and 3 compatiblity port

Bug #1015320 reported by Sapphira Armageddos
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-pam (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

I added a few more changes to the source code of the module to allow compiling for both Python 2 and 3. I was going to file it under just the active development branch, but the only place to put it is here it seems.

Related branches

Revision history for this message
Sapphira Armageddos (shadowkyogre) wrote :
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "Allows it to compile and import for both Python 2 and 3 (updated)" of this bug report has been identified as being a patch. The ubuntu-reviewers team has been subscribed to the bug report so that they can review the patch. In the event that this is in fact not a patch you can resolve this situation by removing the tag 'patch' from the bug report and editing the attachment so that it is not flagged as a patch. Additionally, if you are member of the ubuntu-reviewers team please also unsubscribe the team from this bug report.

[This is an automated message performed by a Launchpad user owned by Brian Murray. Please contact him regarding any issues with the action taken in this bug report.]

tags: added: patch
Revision history for this message
Barry Warsaw (barry) wrote :

Sapphira, thanks for the additional patch. I've approved Steve's branch, and will merge that into trunk and also apply your patch (with some minor changes). I'll sponsor the upload.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package python-pam - 0.4.2-12.2ubuntu5

---------------
python-pam (0.4.2-12.2ubuntu5) quantal; urgency=low

  [ Steve Langasek ]
  * Port to python3; dead project upstream so not forwarding anywhere.
    - replace 'staticforward' with 'static'.
    - replace ob_type with Py_TYPE(ob).
    - drop tp_getattr function, we just need to set tp_methods instead.
    - fix PyTypeObject definition.
    - use PyUnicode_FromString, not PyString_FromString
    - use PyLong_FromLong when building for python3.
    - use PyModule_Create instead of Py_InitModule for python3
    - LP: #1015320
  * Modernize packaging to dh and debhelper 9.

  [ Sapphira Armageddos ]
  * Additional patch to better support Python 2 and Python 3.
 -- Steve Langasek <email address hidden> Thu, 24 May 2012 22:56:26 +0000

Changed in python-pam (Ubuntu):
status: New → Fix Released
Revision history for this message
Sapphira Armageddos (shadowkyogre) wrote :

@Barry: Thank you very much :). I built the new version that was pushed, but noticed some odd behavior with not setting getattro under python3. Attached is both an interactive session and a non-interactive session, along with the pam-test.py code that I was using to test the changes.

If the getattro or getattr isn't defined, it causes some very weird behavior in a non-interactive session, like it thinking there are no properties on the PAM.pam object. This is why there were no macros around getattro function setting in my patch, although I do not know if it behaves similarly on your system with the conditional macro.

Revision history for this message
Barry Warsaw (barry) wrote : Re: [Bug 1015320] Re: Complete the Python 2 and 3 compatiblity port

On Jun 23, 2012, at 12:33 AM, Sapphira Armageddos wrote:

>@Barry: Thank you very much :). I built the new version that was pushed,
>but noticed some odd behavior with not setting getattro under python3.
>Attached is both an interactive session and a non-interactive session,
>along with the pam-test.py code that I was using to test the changes.
>
>If the getattro or getattr isn't defined, it causes some very weird behavior
>in a non-interactive session, like it thinking there are no properties on the
>PAM.pam object. This is why there were no macros around getattro function
>setting in my patch, although I do not know if it behaves similarly on your
>system with the conditional macro.

Thanks for the feedback. I think the right thing to do is to just use
PyObject_GenericGetAttr() in both cases. Here's the diff, which seems to work
for me:

=== modified file 'PAMmodule.c'
--- PAMmodule.c 2012-05-24 22:56:26 +0000
+++ PAMmodule.c 2012-06-25 15:00:09 +0000
@@ -490,11 +490,6 @@
     PyObject_FREE(self);
 }

-static PyObject * PyPAM_getattro(PyPAMObject *self, PyObject *name)
-{
- return PyObject_GenericGetAttr((PyObject *) self, name);
-}
-
 static PyObject * PyPAM_repr(PyPAMObject *self)
 {
     char buf[1024];
@@ -521,9 +516,7 @@
     0, /*hash*/
     0, /*ternary*/
     0, /*another repr*/
-#if PY_MAJOR_VERSION < 3
- (getattrofunc)PyPAM_getattro,
-#endif
+ (getattrofunc)PyObject_GenericGetAttr,
 };

 static PyMethodDef PyPAM_Methods[] = {

I'll upload this now.

Cheers.

Revision history for this message
Sapphira Armageddos (shadowkyogre) wrote :

Tested the change you pushed with the same source code that I used to test that, along with running interactive sessions. It works fine here as well.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.