cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-94808:Improve coverage of PyObject_Print

Open MonadChains opened this issue 2 years ago • 3 comments

This PR improves the coverage of the function PyObject_Print: https://github.com/python/cpython/blob/29b391b1378577825a658b14764a8ff3e0b5c958/Objects/object.c#L256 The coverage achieved is the following: CoveragePyObjectPrint I couldn't hit line 294, I'm open for discussion on how to do this.

  • Issue: gh-94808

MonadChains avatar Oct 26 '22 23:10 MonadChains

Hi @nanjekyejoannah, The test that fails is the address sanitizer one with the following error: SUMMARY: AddressSanitizer: heap-use-after-free Modules/_testcapimodule.c:2083 in pyobject_print_noref_object

This happens in this function: https://github.com/python/cpython/blob/25c24e4e724680b438e78e2e40498c9688c737bd/Modules/_testcapimodule.c#L2055-L2083 This function tests the behaviour of PyObject_Print in case it receives a object with reference counter set to 0: https://github.com/python/cpython/blob/bded5edd9abf7ae6b2874916d70ec29ad209217c/Objects/object.c#L274-L278

I guess the address sanitizer doesn't like that a deallocated object is used after Py_DECREF. Do you have any tips on solving this problem?

MonadChains avatar Oct 28 '22 16:10 MonadChains

Hi @nanjekyejoannah, the pipeline now is working. I've fixed the failing test so the overall coverage achieved by PR is still the same.

MonadChains avatar Nov 01 '22 23:11 MonadChains

@MonadChains I will thoroughly look in a day or two.

nanjekyejoannah avatar Nov 07 '22 18:11 nanjekyejoannah

After a year, I've rebased onto the current main branch, moved the tests to where they'd be added today, and fixed a few things I would have pointed out in a review.

Does this look good?

encukou avatar Mar 25 '24 14:03 encukou

:warning::warning::warning: Buildbot failure :warning::warning::warning:

Hi! The buildbot ARM64 MacOS M1 Refleaks NoGIL 3.x has failed when building commit 90c3c68a658db6951b77a5be50088ec2f6adc8eb.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1368/builds/630) and take a look at the build logs.
  4. Check if the failure is related to this commit (90c3c68a658db6951b77a5be50088ec2f6adc8eb) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1368/builds/630

Failed tests:

  • test_capi

Test leaking resources:

  • test_capi: memory blocks
  • test_capi: references

Summary of the results of the build (if available):

==

Click to see traceback logs
remote: Enumerating objects: 55, done.        
remote: Counting objects:   1% (1/55)        
remote: Counting objects:   3% (2/55)        
remote: Counting objects:   5% (3/55)        
remote: Counting objects:   7% (4/55)        
remote: Counting objects:   9% (5/55)        
remote: Counting objects:  10% (6/55)        
remote: Counting objects:  12% (7/55)        
remote: Counting objects:  14% (8/55)        
remote: Counting objects:  16% (9/55)        
remote: Counting objects:  18% (10/55)        
remote: Counting objects:  20% (11/55)        
remote: Counting objects:  21% (12/55)        
remote: Counting objects:  23% (13/55)        
remote: Counting objects:  25% (14/55)        
remote: Counting objects:  27% (15/55)        
remote: Counting objects:  29% (16/55)        
remote: Counting objects:  30% (17/55)        
remote: Counting objects:  32% (18/55)        
remote: Counting objects:  34% (19/55)        
remote: Counting objects:  36% (20/55)        
remote: Counting objects:  38% (21/55)        
remote: Counting objects:  40% (22/55)        
remote: Counting objects:  41% (23/55)        
remote: Counting objects:  43% (24/55)        
remote: Counting objects:  45% (25/55)        
remote: Counting objects:  47% (26/55)        
remote: Counting objects:  49% (27/55)        
remote: Counting objects:  50% (28/55)        
remote: Counting objects:  52% (29/55)        
remote: Counting objects:  54% (30/55)        
remote: Counting objects:  56% (31/55)        
remote: Counting objects:  58% (32/55)        
remote: Counting objects:  60% (33/55)        
remote: Counting objects:  61% (34/55)        
remote: Counting objects:  63% (35/55)        
remote: Counting objects:  65% (36/55)        
remote: Counting objects:  67% (37/55)        
remote: Counting objects:  69% (38/55)        
remote: Counting objects:  70% (39/55)        
remote: Counting objects:  72% (40/55)        
remote: Counting objects:  74% (41/55)        
remote: Counting objects:  76% (42/55)        
remote: Counting objects:  78% (43/55)        
remote: Counting objects:  80% (44/55)        
remote: Counting objects:  81% (45/55)        
remote: Counting objects:  83% (46/55)        
remote: Counting objects:  85% (47/55)        
remote: Counting objects:  87% (48/55)        
remote: Counting objects:  89% (49/55)        
remote: Counting objects:  90% (50/55)        
remote: Counting objects:  92% (51/55)        
remote: Counting objects:  94% (52/55)        
remote: Counting objects:  96% (53/55)        
remote: Counting objects:  98% (54/55)        
remote: Counting objects: 100% (55/55)        
remote: Counting objects: 100% (55/55), done.        
remote: Compressing objects:   5% (1/18)        
remote: Compressing objects:  11% (2/18)        
remote: Compressing objects:  16% (3/18)        
remote: Compressing objects:  22% (4/18)        
remote: Compressing objects:  27% (5/18)        
remote: Compressing objects:  33% (6/18)        
remote: Compressing objects:  38% (7/18)        
remote: Compressing objects:  44% (8/18)        
remote: Compressing objects:  50% (9/18)        
remote: Compressing objects:  55% (10/18)        
remote: Compressing objects:  61% (11/18)        
remote: Compressing objects:  66% (12/18)        
remote: Compressing objects:  72% (13/18)        
remote: Compressing objects:  77% (14/18)        
remote: Compressing objects:  83% (15/18)        
remote: Compressing objects:  88% (16/18)        
remote: Compressing objects:  94% (17/18)        
remote: Compressing objects: 100% (18/18)        
remote: Compressing objects: 100% (18/18), done.        
remote: Total 31 (delta 26), reused 15 (delta 13), pack-reused 0        
From https://github.com/python/cpython
 * branch                  main       -> FETCH_HEAD
Note: switching to '90c3c68a658db6951b77a5be50088ec2f6adc8eb'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 90c3c68a65 gh-94808:Improve coverage of PyObject_Print (GH-98749)
Switched to and reset branch 'main'

In file included from ./Modules/_tkinter.c:52:
In file included from /opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/tk.h:99:
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:131:21: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        int (*free_private)();  /* called to free private storage */
                           ^
                            void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:334:33: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        struct _XImage *(*create_image)();
                                       ^
                                        void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:453:23: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        XID (*resource_alloc)(); /* allocator function */
                             ^
                              void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:471:20: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        int (*synchandler)();   /* Synchronization handler */
                          ^
                           void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:496:24: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        Bool (*event_vec[128])();  /* vector for wire to event */
                              ^
                               void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:497:25: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        Status (*wire_vec[128])(); /* vector for event to wire */
                               ^
                                void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:509:20: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        Bool (**error_vec)();      /* vector for wire to error */
                          ^
                           void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:522:25: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        int (*savedsynchandler)(); /* user synchandler when Xlib usurps */
                               ^
                                void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:1053:24: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
typedef void (*XIMProc)();
                       ^
                        void
In file included from ./Modules/tkappinit.c:17:
In file included from /opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/tk.h:99:
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:131:21: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        int (*free_private)();  /* called to free private storage */
                           ^
                            void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:334:33: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        struct _XImage *(*create_image)();
                                       ^
                                        void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:453:23: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        XID (*resource_alloc)(); /* allocator function */
                             ^
                              void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:471:20: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        int (*synchandler)();   /* Synchronization handler */
                          ^
                           void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:496:24: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        Bool (*event_vec[128])();  /* vector for wire to event */
                              ^
                               void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:497:25: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        Status (*wire_vec[128])(); /* vector for event to wire */
                               ^
                                void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:509:20: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        Bool (**error_vec)();      /* vector for wire to error */
                          ^
                           void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:522:25: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
        int (*savedsynchandler)(); /* user synchandler when Xlib usurps */
                               ^
                                void
/opt/homebrew/Cellar/tcl-tk/8.6.13_5/include/tcl-tk/X11/Xlib.h:1053:24: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
typedef void (*XIMProc)();
                       ^
                        void
9 warnings generated.
9 warnings generated.

make: *** [buildbottest] Error 2

bedevere-bot avatar Apr 01 '24 13:04 bedevere-bot