2010-04-08 20:42:20 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2011-01-07 04:44:19 +03:00
|
|
|
# bug_gc.py - test for refcounting/GC bug
|
|
|
|
#
|
2019-02-17 04:34:52 +03:00
|
|
|
# Copyright (C) 2010-2019 Federico Di Gregorio <fog@debian.org>
|
2011-01-07 04:44:19 +03:00
|
|
|
#
|
|
|
|
# psycopg2 is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Lesser General Public License as published
|
|
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# In addition, as a special exception, the copyright holders give
|
|
|
|
# permission to link this program with the OpenSSL library (or with
|
|
|
|
# modified versions of OpenSSL that use the same license as OpenSSL),
|
|
|
|
# and distribute linked combinations including the two.
|
|
|
|
#
|
|
|
|
# You must obey the GNU Lesser General Public License in all respects for
|
|
|
|
# all of the code used other than OpenSSL.
|
|
|
|
#
|
|
|
|
# psycopg2 is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
# License for more details.
|
|
|
|
|
2010-04-08 20:42:20 +04:00
|
|
|
import psycopg2
|
|
|
|
import psycopg2.extensions
|
|
|
|
import unittest
|
|
|
|
import gc
|
|
|
|
|
2017-12-04 05:47:19 +03:00
|
|
|
from .testutils import ConnectingTestCase, skip_if_no_uuid
|
2011-01-18 04:46:10 +03:00
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2013-04-07 03:23:30 +04:00
|
|
|
class StolenReferenceTestCase(ConnectingTestCase):
|
2011-01-18 04:46:10 +03:00
|
|
|
@skip_if_no_uuid
|
2010-04-08 20:42:20 +04:00
|
|
|
def test_stolen_reference_bug(self):
|
|
|
|
def fish(val, cur):
|
|
|
|
gc.collect()
|
|
|
|
return 42
|
|
|
|
UUID = psycopg2.extensions.new_type((2950,), "UUID", fish)
|
2011-01-18 04:46:10 +03:00
|
|
|
psycopg2.extensions.register_type(UUID, self.conn)
|
|
|
|
curs = self.conn.cursor()
|
2010-04-08 20:42:20 +04:00
|
|
|
curs.execute("select 'b5219e01-19ab-4994-b71e-149225dc51e4'::uuid")
|
|
|
|
curs.fetchone()
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2010-04-08 20:42:20 +04:00
|
|
|
def test_suite():
|
|
|
|
return unittest.TestLoader().loadTestsFromName(__name__)
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2010-04-08 20:42:20 +04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|