Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9232481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:19:29+00:00 2026-06-18T06:19:29+00:00

I am testing a module that I rewrote from C to Python and having

  • 0

I am testing a module that I rewrote from C to Python and having one of the stranger bugs I’ve seen in my career. The offending Python code with tests is just three lines:

# MATCHERS is a list of compiled regular expression objects defined as a
# global in the top level of the module
print dir(MATCHERS[0])
# diff.Differ is a class implemented in C with thed Python API; zoneA/B Words are
# lists and CompareLines, isJunk, and SetStaticLine are functions
differ = diff.Differ(zoneAWords, zoneBWords, CompareLines, isJunk, SetStaticLine)
# Causes a TypeError
dir(MATCHERS[0])

These three lines produce the following output:

['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'findall', 'finditer', 'flags', 'groupindex', 'groups', 'match', 'pattern', 'scanner', 'search', 'split', 'sub', 'subn']
Traceback (most recent call last):
  File "Diff.py", line 1032, in <module>
    main()
  File "Diff.py", line 1019, in main
    diffs = CompareFiles(sys.argv[1], sys.argv[2])
  File "Diff.py", line 584, in CompareFiles
    print dir(MATCHERS[0])
TypeError: eqTest must be a function

Printing the dir() of the compiled regular expression object works fine before the object written in C is created, but afterward simply taking the dir() causes a TypeError. As far as I know, there is no way for dir() to cause a TypeError. The TypeError and message associated with it are from my code as part of the customized setter function for the object’s eqTest field, but a call to dir() does not, of course, try to set eqTest to anything; it has already been successfully set in the previous line.

This all leads me to believe that something went wrong in the C code to produce such strange behavior. My current hypothesis is a buffer overflow; writing past the bounds of an array changed something that is causing these errors. (Asking MATCHERS[0] to match a string simply crashes Python with no error message) I’ve been going over the initialization code for a while and just thought I would check if there is anything else that could be causing this.

My code is too long to include here and is on Pastebin here; you can ignore everything after line 434 as it hasn’t been executed yet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:19:30+00:00Added an answer on June 18, 2026 at 6:19 am

    The problem may be that your Differ_init function does not return -1 when the initialization in setup_differ fails.

    Your setup_differ calls py_differ_set_eqTest:

    static int py_differ_set_eqTest(DIFFER* self, PyObject* value, void* closure)
    {
        PyObject* tmp;
    
        TYPE_CHECK(PyFunction_Check, "eqTest must be a function");
        ASSIGN_MEMBER_NAME(self, value, eqTest);
        return 0;
    }
    

    Where the TYPE_CHECK macro is:

    #define TYPE_CHECK(typeChecker, msg) if (value != Py_None && !typeChecker(value)) \
        {PyErr_SetString(PyExc_TypeError, msg); return -1;}
    

    The problem is that the setup_differ does not check whether py_differ_set_eqTest succeeds or fails, and your Differ_init returns 0 even if it failed.

    Now when you call dir, it correctly prints the attributes but before returning it probably checks for exceptions, and sees the TypeError that was raised by TYPE_CHECK and raises it.

    to fix this every function should return a value so that you can determine if an exception was raised or not, and the Differ_init should return -1 if setup_differ failed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one testing module that I want to use for android testing. I
I'm testing distributing a Python extension module as an egg created with setuptools. Here
In testing an app, I keep getting errors that occur sporadically on only one
I'm writing a Python module that wraps out a certain web service API. It's
I have created a Perl module from a .pl file and I am testing
I have the following method in a module that calls another method imported from
I have to write a testing module and have c++-Background. That said, I am
Is it OK to write self-tests for a module that depends on user-input, or
I was considering reassigning some functions from a standard library module in my testing
I have a Python 2.x module.py file that looks like this: class A(object): KEYWORD

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.