arXiv:2608.29851cs.SEAug 2026

Manuscript Offprint

arXiv:2608.29851

A Comprehensive Study of Native Code Bugs in Python Applications

Haoran Yang, Haipeng Cai

HAORAN YANG, Washington State University, USA

HAIPENG CAI, Washington State University, USA

The impact of Python applications has been evidenced by their widespread presence in some of the most impactful software domains, such as machine learning frameworks and scientific computing platforms. These applications often integrate native code components written in a lower-level programming language like C. This multilingual construction brings various benefits such as greater performance efficiency and easier interoperability with diverse runtime environments. However, bugs in the native code (i.e., native code bugs), which are usually stealthy, also constitute a major additional challenge to the quality of the Python applications as a whole. Yet despite existing relevant studies, there remains a lack of comprehensive understanding of native code bugs in Python applications. In this paper, we aim to mitigate this knowledge gap through the first in-depth study of such bugs, dissecting their common symptoms, introducing locations, manifestation characteristics, root causes, and fixes. Based on our extensive automated and manual analyses of 216 native code bugs in real-world Python projects on GitHub, we obtained novel findings about and new insights into the occurrence mechanisms and resolution strategies of those bugs. Among others, we observed that (1) Python native bugs are most commonly introduced at foreign function callsites while symptomized primarily as crashes and abnormal system termination, (2) these bugs are often manifested in user-level memory management related operations, while predominantly caused by memory safety and type errors associated with foreign data objects, and (3) those bugs are commonly fixed through correcting memory (e.g., reference count) management or incorporating necessary input/boundary checking and validations, often at foreign function callsites or branching control structures. We also identified the semantics differences and interactions between the native and host languages as the primary challenge to native code bug detection, followed by the complex ways native code interacts with the foreign language.

These results further led to actionable suggestions on practical approaches to native code bug prevention, detection, testing/debugging, and fixing. For instance, (1) automatic API recommendations focusing on foreign function usage can be of peculiar merits to developers of native Python applications, (2) native code behaviors for memory management, foreign object manipulation, and cross-language exception handling should be main testing/debugging targets to exercise for testers of those applications, while (3) foreign function callsites may be particularly attended when identifying fixes of bugs appearing at those locations, whereas bugs occurring at assignment statements are most likely not to be fixed at those statements.

ACM Reference Format:

Haoran Yang and Haipeng Cai. 2024. A Comprehensive Study of Native Code Bugs in Python Applications. ACM Trans. Softw. Eng. Methodol. 1, 1 (September 2024), 27 pages. https://doi.org/10.1145/nnnnnnn.nnnnnnn