[Python-Dev] Need help with C - problem in sqlite3 module

"Martin v. Löwis" martin at v.loewis.de
Sat Sep 23 22:18:32 CEST 2006


Gerhard Häring schrieb:
> Apparently at least gcc on Linux exports all symbols by default that are
> not static.

Correct. Various factors influence run-time symbol binding, though.

> This creates problems with Python extensions that export
> symbols that are also used in other contexts. For example some people use
> Python and the sqlite3 module under Apache, and the sqlite3 module exports
> a symbol cache_init, but cache_init is also used by Apache's mod_cache
> module. Thus there are crashes when using the sqlite3 module that only
> occur in the mod_python context.
> 
> Can somebody with more knowledge about C tell me how to fix the sqlite3
> module or compiler settings for distutils so that this does not happen?

The only reliable way is to do renaming. This was one of the primary
reasons of the "grand renaming" in Python, where the Py prefix was
introduced.

> Of course this only happens because the sqlite3 module is distributed among
> multiple .c files and thus I couldn't make everything "static".

In the specific case, I can't understand that reason. cache_init is
declared in cache.c, and only used in cache.c (to fill a tp_init slot).
So just make the symbol static.

As a lesson learned, you should go through the module and make
all functions static, then see what functions really need to be
extern. You should then rename these functions, say by adding
a PySQLite prefix. All dynamic symbols remaining should then
either have the PySQLite prefix, except for init_sqlite3.

In fact, since most operations in Python go through function
pointers, there is typically very little need for extern
functions in a Python extension module, even if that module
consists of multiple C files.

Regards,
Martin

P.S. Currently, on my system, the following symbols are extern in
this module

00005890 T _authorizer_callback
0000dec0 A __bss_start
00007600 T _build_column_name
00005df0 T _build_py_params
00007ee0 T build_row_cast_map
00004880 T cache_dealloc
00004990 T cache_display
00004b90 T cache_get
00004da0 T cache_init
00004930 T cache_setup_types
0000d4a0 D CacheType
00004e80 T check_connection
00009f60 T check_remaining_sql
00005420 T check_thread
00006430 T _connection_begin
00005cb0 T connection_call
000068d0 T connection_close
000061c0 T connection_commit
000059b0 T connection_create_aggregate
00005ab0 T connection_create_function
000057a0 T connection_cursor
00006530 T connection_dealloc
00005320 T connection_execute
00005220 T connection_executemany
00005120 T connection_executescript
00006970 T connection_init
00006700 T connection_rollback
000056d0 T connection_set_authorizer
000050e0 T connection_setup_types
0000d5e0 D ConnectionType
0000ded8 B converters
000094d0 T converters_init
00007110 T cursor_close
00007190 T cursor_dealloc
00008d90 T cursor_execute
00008d50 T cursor_executemany
000072e0 T cursor_executescript
00007c90 T cursor_fetchall
00007d30 T cursor_fetchmany
00007e10 T cursor_fetchone
000070b0 T cursor_getiter
00007530 T cursor_init
00007b50 T cursor_iternext
000070e0 T cursor_setup_types
0000d980 D CursorType
0000decc B DatabaseError
0000ded4 B DataError
00005bb0 T _drop_unused_statement_references
0000dec0 A _edata
0000def0 B _enable_callback_tracebacks
0000defc A _end
0000dee8 B Error
00007710 T _fetch_one_row
00006cb0 T _final_callback
0000aac4 T _fini
00006830 T flush_statement_cache
00006fa0 T _func_callback
00007e60 T _get_converter
00003bd4 T _init
00009520 T init_sqlite3
0000deec B IntegrityError
0000ded0 B InterfaceError
0000dedc B InternalError
00008dd0 T microprotocols_adapt
00009040 T microprotocols_add
000090e0 T microprotocols_init
000047a0 T new_node
00004810 T node_dealloc
0000d3e0 D NodeType
0000def8 B NotSupportedError
0000dee4 B OperationalError
0000dee0 B OptimizedUnicode
00009ae0 T prepare_protocol_dealloc
00009ac0 T prepare_protocol_init
00009b10 T prepare_protocol_setup_types
0000dec8 B ProgrammingError
0000dec4 B psyco_adapters
00008fc0 T psyco_microprotocols_adapt
000070c0 T pysqlite_noop
00008110 T _query_execute
00006690 T reset_all_statements
0000dd20 D row_as_mapping
00009b50 T row_dealloc
00009e40 T row_init
00009bd0 T row_length
00009c40 T row_setup_types
00009c80 T row_subscript
0000dd40 D RowType
0000a910 T _seterror
00005fc0 T _set_result
00006c70 T _sqlite3_result_error
0000dc60 D SQLitePrepareProtocolType
0000aa30 T _sqlite_step_with_busyhandler
0000a2a0 T statement_bind_parameter
0000a530 T statement_bind_parameters
0000a7f0 T statement_create
0000a0f0 T statement_dealloc
0000a080 T statement_finalize
00009f30 T statement_mark_dirty
0000a210 T statement_recompile
0000a190 T statement_reset
0000a040 T statement_setup_types
0000de00 D StatementType
000076a0 T unicode_from_string
0000def4 B Warning



More information about the Python-Dev mailing list