Skip to main content

Finding Reference-Counting Errors in Python/C Programs with Affine Analysis

  • Conference paper
ECOOP 2014 – Object-Oriented Programming (ECOOP 2014)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 8586))

Included in the following conference series:

Abstract

Python is a popular programming language that uses reference counting to manage heap objects. Python also has a Foreign Function Interface (FFI) that allows Python extension modules to be written in native code such as C and C++. Native code, however, is outside Python’s system of memory management; therefore extension programmers are responsible for making sure these objects are reference counted correctly. This is an error prone process when code becomes complex. In this paper, we propose Pungi, a system that statically checks whether Python objects’ reference counts are adjusted correctly in Python/C interface code. Pungi transforms Python/C interface code into affine programs with respect to our proposed abstractions of reference counts. Our system performs static analysis on transformed affine programs and reports possible reference counting errors. Our prototype implementation found over 150 errors in a set of Python/C programs.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Meyerovich, L.A., Rabkin, A.S.: Empirical analysis of programming language adoption. In: ACM Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pp. 1–18 (2013)

    Google Scholar 

  2. Python/C API reference manual (2013), http://docs.python.org/3.3/c-api/index.html

  3. Lal, A., Ramalingam, G.: Reference count analysis with shallow aliasing. Information Processing Letters 111(2), 57–63 (2010)

    Article  MATH  MathSciNet  Google Scholar 

  4. Emmi, M., Jhala, R., Kohler, E., Majumdar, R.: Verifying reference counting implementations. In: Kowalewski, S., Philippou, A. (eds.) TACAS 2009. LNCS, vol. 5505, pp. 352–367. Springer, Heidelberg (2009)

    Chapter  Google Scholar 

  5. Malcom, D.: Cpychecker, https://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html

  6. Beazley, D.M.: SWIG Users Manual: Version 1.1 (June 1997)

    Google Scholar 

  7. Cython, http://cython.org/

  8. Furr, M., Foster, J.S.: Polymorphic type inference for the JNI. In: Sestoft, P. (ed.) ESOP 2006. LNCS, vol. 3924, pp. 309–324. Springer, Heidelberg (2006)

    Chapter  Google Scholar 

  9. Tan, G., Morrisett, G.: ILEA: Inter-language analysis across Java and C. In: ACM Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pp. 39–56 (2007)

    Google Scholar 

  10. Kondoh, G., Onodera, T.: Finding bugs in Java Native Interface programs. In: ISSTA 2008: Proceedings of the 2008 International Symposium on Software Testing and Analysis, pp. 109–118. ACM, New York (2008)

    Google Scholar 

  11. Li, S., Tan, G.: Finding bugs in exceptional situations of JNI programs. In: 16th ACM Conference on Computer and Communications Security (CCS), pp. 442–452 (2009)

    Google Scholar 

  12. Lee, B., Hirzel, M., Grimm, R., Wiedermann, B., McKinley, K.S.: Jinn: Synthesizing a dynamic bug detector for foreign language interfaces. In: ACM Conference on Programming Language Design and Implementation (PLDI), pp. 36–49 (2010)

    Google Scholar 

  13. Li, S., Liu, Y.D., Tan, G.: Native code atomicity for Java. In: Jhala, R., Igarashi, A. (eds.) APLAS 2012. LNCS, vol. 7705, pp. 2–17. Springer, Heidelberg (2012)

    Chapter  Google Scholar 

  14. Siefers, J., Tan, G., Morrisett, G.: Robusta: Taming the native beast of the JVM. In: 17th ACM Conference on Computer and Communications Security (CCS), pp. 201–211 (2010)

    Google Scholar 

  15. Tan, G., Appel, A., Chakradhar, S., Raghunathan, A., Ravi, S., Wang, D.: Safe Java Native Interface. In: Proceedings of IEEE International Symposium on Secure Software Engineering, pp. 97–106 (2006)

    Google Scholar 

  16. Hirzel, M., Grimm, R.: Jeannie: Granting Java Native Interface developers their wishes. In: ACM Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pp. 19–38 (2007)

    Google Scholar 

  17. Furr, M., Foster, J.: Checking type safety of foreign function calls. In: ACM Conference on Programming Language Design and Implementation (PLDI), pp. 62–72 (2005)

    Google Scholar 

  18. Li, S., Tan, G.: JET: Exception checking in the Java Native Interface. In: ACM Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA), pp. 345–358 (2011)

    Google Scholar 

  19. Gulwani, S., Necula, G.C.: Discovering affine equalities using random interpretation. In: 30th ACM Symposium on Principles of Programming Languages (POPL), pp. 74–84 (2003)

    Google Scholar 

  20. Müller-Olm, M., Seidl, H.: Precise interprocedural analysis through linear algebra. In: 31st ACM Symposium on Principles of Programming Languages (POPL), pp. 330–341 (2004)

    Google Scholar 

  21. Karr, M.: Affine relationships among variables of a program. Acta Informatica 6, 133–151 (1976)

    Article  MATH  MathSciNet  Google Scholar 

  22. Müller-Olm, M., Rüthing, O.: On the complexity of constant propagation. In: Sands, D. (ed.) ESOP 2001. LNCS, vol. 2028, pp. 190–205. Springer, Heidelberg (2001)

    Chapter  Google Scholar 

  23. Elder, M., Lim, J., Sharma, T., Andersen, T., Reps, T.: Abstract domains of affine relations. In: Yahav, E. (ed.) Static Analysis. LNCS, vol. 6887, pp. 198–215. Springer, Heidelberg (2011)

    Chapter  Google Scholar 

  24. Johnsson, T.: Lambda lifting: Transforming programs to recursive equations. In: Jouannaud, J.-P. (ed.) FPCA 1985. LNCS, vol. 201, pp. 190–203. Springer, Heidelberg (1985)

    Chapter  Google Scholar 

  25. Das, M., Lerner, S., Seigle, M.: ESP: path-sensitive program verification in polynomial time. In: ACM Conference on Programming Language Design and Implementation (PLDI), pp. 57–68 (2002)

    Google Scholar 

  26. Necula, G.C., McPeak, S., Rahul, S.P., Weimer, W.: CIL: Intermediate language and tools for analysis and transformation of C programs. In: Nigel Horspool, R. (ed.) CC 2002. LNCS, vol. 2304, pp. 213–228. Springer, Heidelberg (2002)

    Chapter  Google Scholar 

  27. Aycock, J.: Simple generation of static single-assignment form. In: Watt, D.A. (ed.) CC 2000. LNCS, vol. 1781, pp. 110–124. Springer, Heidelberg (2000)

    Chapter  Google Scholar 

  28. Shaham, R., Yahav, E., Kolodner, E.K., Sagiv, M.: Establishing local temporal heap safety properties with applications to compile-time memory management. In: Cousot, R. (ed.) SAS 2003. LNCS, vol. 2694, pp. 483–503. Springer, Heidelberg (2003)

    Chapter  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2014 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Li, S., Tan, G. (2014). Finding Reference-Counting Errors in Python/C Programs with Affine Analysis. In: Jones, R. (eds) ECOOP 2014 – Object-Oriented Programming. ECOOP 2014. Lecture Notes in Computer Science, vol 8586. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-662-44202-9_4

Download citation

  • DOI: https://doi.org/10.1007/978-3-662-44202-9_4

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-662-44201-2

  • Online ISBN: 978-3-662-44202-9

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics