Bug 452920

Summary: Segmentation Fault when working adding Widget into Grid
Product: [Fedora] Fedora Reporter: Greg Swift <gregswift>
Component: newtAssignee: Miroslav Lichvar <mlichvar>
Status: CLOSED NEXTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: rawhide   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
URL: http://www.wanware.com/tsgdocs/snack.html
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-07-30 13:29:59 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Greg Swift 2008-06-25 21:15:53 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008052912 Firefox/3.0

Description of problem:
I found a tutorial about using Newt in Python.  The first example under Forms and Grids segfaults. If I change their use of Widget to any of the classes based on Widget it seems to work fine.  I realize that this may just mean that you should never use Widget directly, but it should handle it without a segfault, IMHO.

Version-Release number of selected component (if applicable):
newt-python-0.52.9-1.fc9

How reproducible:
Always


Steps to Reproduce:
1. Run this script (built my stripping down the example code at listed URL):

#!/usr/bin/env python

from snack import *

s = SnackScreen()
g = Grid(1,1)
w = Widget()
g.setField(w,0,0)
s.gridWrappedWindow(g, "title")
s.popWindow()
s.finish()

Actual Results:
Segmentation Fault

Expected Results:
Nothing special if anything, but at the very least an exception being raised based on invalid object.

Additional info:
I've tried this on the following rpms:

newt-python-0.52.7-4.fc8.i386
newt-python-0.52.9-1.fc9.i386

Comment 1 Miroslav Lichvar 2008-06-26 15:14:35 UTC
I'm not sure the example has ever worked. Widget just provides the setCallback
function and isn't supposed to be used as a real widget.

Any suggestions where the exception should be raised? Checking in all functions
if w == None wouldn't be very nice.

Comment 2 Greg Swift 2008-06-26 15:45:33 UTC
Okay.. I'll concede that checking that in every function is not nice.  After
your response and having browsed through the source would these 2 assumptions be
true:

1: You shouldn't be using Widget directly, ever?
2: Whenever inheriting Widget you should override the __init__ method

If so You could always do this:

class Widget:
    """Base class for NEWT toolkit - Do not use directly

    methods:

     - Widget(self)
     - setCallback(self, obj, data = None) :
          The callback for when object activated.
          data is passed to obj.
    """
    def setCallback(self, obj, data = None):
        if data:
            self.w.setCallback(obj, data)
        else:
            self.w.setCallback(obj)

    def __init__(self):
        raise NotImplementedError

This was per the definition located at Python's Module Exception page[1], which
states:
"exception NotImplementedError
    This exception is derived from RuntimeError. In user defined base classes,
abstract methods should raise this exception when they require derived classes
to override the method. New in version 1.5.2. "

Of course if the above 2 assumptions are not true, I'm going to have to think
about it a bit more.

[1]http://docs.python.org/lib/module-exceptions.html

Comment 3 John Poelstra 2008-06-27 02:58:59 UTC
triaged

Comment 4 Miroslav Lichvar 2008-06-27 11:45:46 UTC
Ok, I've put the fix in upstream git. Will be in the next release.

Thanks.

Comment 5 Greg Swift 2008-06-27 15:30:21 UTC
awesome.  thanks.

Comment 6 Miroslav Lichvar 2008-07-30 13:29:59 UTC
Fixed in newt-0.52.10-1.fc10.

Comment 7 Fedora Update System 2008-07-30 13:42:36 UTC
newt-0.52.10-1.fc9 has been submitted as an update for Fedora 9

Comment 8 Fedora Update System 2008-09-10 07:05:41 UTC
newt-0.52.10-1.fc9 has been pushed to the Fedora 9 stable repository.  If problems still persist, please make note of it in this bug report.