GSoC: want to take part in `Extend the static analysis pass for CPython Extension`

2023-04-01 Thread Sun Steven via Gcc
Hello,

I want to take part in this project.

b. Write a plugin to add checking for usage of the CPython API (e.g. 
reference-counting); see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107646


I know the deadline is arriving, but this idea just came to me now.

Self-intro:
I am a fan of C++, and have expertise in writing low-latency codes. I 
previously worked at a high-frequency trading company, mainly writing C++ and 
Python on Linux.

Familiarity with GCC:
I get an overall idea of how the compiler works. I have debugged several GCC 
c++ frontend bugs. (eg. 108218,  99686, 99019,...) But I only checked the c++ 
frontend codes in detail, not the middle or backend codes. I have the ability 
to work with large codebases.

Familiarity with CPython:
I use a lot of CPython. Recently, I am contributing to the CPython interpreter 
on PEP 701 (mainly on the parser, which I am familiar with)


I have always been wanting to contribute major changes to GCC, but just don't 
know if that project exists. I understand how middle-end works, but never 
really interact with the GIMPLE. This project allows me to take a real look at 
how GCC's middle end works.

I want to know if anyone was already on this project. I would prefer a 
large-sized object (350hrs).

If b. was already taken, I also accept a. and c. By the way, I don't really 
care about the GSoC. If we miss the deadline, we can still push forward this 
project without the support of GSoC, as long as I get coached.




Re: [GSoC] Interest and initial proposal for project on reimplementing cpychecker as -fanalyzer plugin

2023-04-02 Thread Sun Steven via Gcc
Hi, Eric, Malcom,

Sorry that I didn't check this thread before.

It sounds like there are a lot of things to do. I want to offer some help.

Let me add some backgrounds of memory management in python here.


## Intro (for people unfamiliar with CPython)

Unlike programs written in C++, where the compiler automatically adds
destructors on all exit paths, CPython requires manual memory management
on PyObject*.

The current CPython has 2 major memory management mechanisms,
including reference counting and a mark-and-sweep gc for cyclic references.
The former acts as the major mechanism. PyObject gets destructed when
the refcount drops to zero.

## CPython has made great efforts to reduce memory errors.

With specific compile flags on, the CPython interpreter records the total
refcount, also it aborts when refcount drops below zero (being double freed).
This helps to discover memory leaks. PEP 683 (implemented in 3.12) also
introduced "immortal objects" with initial refcount 9, prevent it from
being accidentally freed (such as small integers).

Even with these features, CPython extension management is still a problem,
since most errors occur on "error-handling path", which is less likely to be
covered. And most users will not use a debug-build cpython, making the error
more under the surface.

## Why I want to participate in?

I am currently working on the initial implementations of PEP 701 (a new
f-string​ parser). During the testing, I discovered (and fixed) 3 memory leaks.
As you can see, even the most experienced CPython developers sometimes
forget to properly decrease refs. I think it will be inspiring if a new analysis
tool was made available as a compiler builtin. It will lead to a better CPython.


I do not know if GSoC allows collaborations. Maybe the headcount is limited,
or maybe I am too senior for GSoC. But I think I am still a rookie in front of
GCC.


I want to contribute, no matter the forms.

Yours