<s> from __future__ import absolute_import <EOL> import cython <EOL> cython . declare ( Naming = object , Options = object , PyrexTypes = object , TypeSlots = object , <EOL> error = object , warning = object , py_object_type = object , UtilityCode = object , <EOL> EncodedString = object ) <EOL> import json <EOL> import os <EOL> import operator <EOL> from . PyrexTypes import CPtrType <EOL> from . import Future <EOL> from . import Annotate <EOL> from . import Code <EOL> from . import Naming <EOL> from . import Nodes <EOL> from . import Options <EOL> from . import TypeSlots <EOL> from . import PyrexTypes <EOL> from . Errors import error , warning <EOL> from . PyrexTypes import py_object_type <EOL> from . . Utils import open_new_file , replace_suffix , decode_filename <EOL> from . Code import UtilityCode <EOL> from . StringEncoding import EncodedString <EOL> def check_c_declarations_pxd ( module_node ) : <EOL> module_node . scope . check_c_classes_pxd ( ) <EOL> return module_node <EOL> def check_c_declarations ( module_node ) : <EOL> module_node . scope . check_c_classes ( ) <EOL> module_node . scope . check_c_functions ( ) <EOL> return module_node <EOL> def generate_c_code_config ( env , options ) : <EOL> if Options . annotate or options . annotate : <EOL> emit_linenums = False <EOL> else : <EOL> emit_linenums = options . emit_linenums <EOL> return Code . CCodeConfig ( <EOL> emit_linenums = emit_linenums , <EOL> emit_code_comments = env . directives [ '<STR_LIT>' ] , <EOL> c_line_in_traceback = options . c_line_in_traceback ) <EOL> class ModuleNode ( Nodes . Node , Nodes . BlockNode ) : <EOL> child_attrs = [ "<STR_LIT:body>" ] <EOL> directives = None <EOL> def merge_in ( self , tree , scope , merge_scope = False ) : <EOL> assert isinstance ( self . body , Nodes . StatListNode ) <EOL> if isinstance ( tree , Nodes . StatListNode ) : <EOL> self . body . stats . extend ( tree . stats ) <EOL> else : <EOL> self . body . stats . append ( tree ) <EOL> self . scope . utility_code_list . extend ( scope . utility_code_list ) <EOL> def extend_if_not_in ( L1 , L2 ) : <EOL> for x in L2 : <EOL> if x not in L1 : <EOL> L1 . append ( x ) <EOL> extend_if_not_in ( self . scope . include_files , scope . include_files ) <EOL> extend_if_not_in ( self . scope . included_files , scope . included_files ) <EOL> extend_if_not_in ( self . scope . python_include_files , <EOL> scope . python_include_files ) <EOL> if merge_scope : <EOL> for entry in scope . c_class_entries : <EOL> entry . type . module_name = self . full_module_name <EOL> entry . type . scope . directives [ "<STR_LIT>" ] = True <EOL> self . scope . merge_in ( scope ) <EOL> def analyse_declarations ( self , env ) : <EOL> if not Options . docstrings : <EOL> env . doc = self . doc = None <EOL> elif Options . embed_pos_in_docstring : <EOL> env . doc = EncodedString ( u'<STR_LIT>' % Nodes . relative_position ( self . pos ) ) <EOL> if not self . doc is None : <EOL> env . doc = EncodedString ( env . doc + u'<STR_LIT:\n>' + self . doc ) <EOL> env . doc . encoding = self . doc . encoding <EOL> else : <EOL> env . doc = self . doc <EOL> env . directives = self . directives <EOL> self . body . analyse_declarations ( env ) <EOL> def prepare_utility_code ( self ) : <EOL> env = self . scope <EOL> if env . has_import_star : <EOL> self . create_import_star_conversion_utility_code ( env ) <EOL> def process_implementation ( self , options , result ) : <EOL> env = self . scope <EOL> env . return_type = PyrexTypes . c_void_type <EOL> self . referenced_modules = [ ] <EOL> self . find_referenced_modules ( env , self . referenced_modules , { } ) <EOL> self . sort_cdef_classes ( env ) <EOL> self . generate_c_code ( env , options , result ) <EOL> self . generate_h_code ( env , options , result ) <EOL> self . generate_api_code ( env , options , result ) <EOL> def has_imported_c_functions ( self ) : <EOL> for module in self . referenced_modules : <EOL> for entry in module . cfunc_entries : <EOL> if entry . defined_in_pxd : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def generate_h_code ( self , env , options , result ) : <EOL> def h_entries ( entries , api = <NUM_LIT:0> , pxd = <NUM_LIT:0> ) : <EOL> return [ entry for entry in entries <EOL> if ( ( entry . visibility == '<STR_LIT>' ) or <EOL> ( api and entry . api ) or <EOL> ( pxd and entry . defined_in_pxd ) ) ] <EOL> h_types = h_entries ( env . type_entries , api = <NUM_LIT:1> ) <EOL> h_vars = h_entries ( env . var_entries ) <EOL> h_funcs = h_entries ( env . cfunc_entries ) <EOL> h_extension_types = h_entries ( env . c_class_entries ) <EOL> if h_types or h_vars or h_funcs or h_extension_types : <EOL> result . h_file = replace_suffix ( result . c_file , "<STR_LIT>" ) <EOL> h_code = Code . CCodeWriter ( ) <EOL> c_code_config = generate_c_code_config ( env , options ) <EOL> Code . GlobalState ( h_code , self , c_code_config ) <EOL> if options . generate_pxi : <EOL> result . i_file = replace_suffix ( result . c_file , "<STR_LIT>" ) <EOL> i_code = Code . PyrexCodeWriter ( result . i_file ) <EOL> else : <EOL> i_code = None <EOL> h_code . put_generated_by ( ) <EOL> h_guard = Naming . h_guard_prefix + self . api_name ( env ) <EOL> h_code . put_h_guard ( h_guard ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> self . generate_type_header_code ( h_types , h_code ) <EOL> if options . capi_reexport_cincludes : <EOL> self . generate_includes ( env , [ ] , h_code ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> api_guard = Naming . api_guard_prefix + self . api_name ( env ) <EOL> h_code . putln ( "<STR_LIT>" % api_guard ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> self . generate_extern_c_macro_definition ( h_code ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> self . generate_dl_import_macro ( h_code ) <EOL> if h_extension_types : <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> for entry in h_extension_types : <EOL> self . generate_cclass_header_code ( entry . type , h_code ) <EOL> if i_code : <EOL> self . generate_cclass_include_code ( entry . type , i_code ) <EOL> if h_funcs : <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> for entry in h_funcs : <EOL> self . generate_public_declaration ( entry , h_code , i_code ) <EOL> if h_vars : <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> for entry in h_vars : <EOL> self . generate_public_declaration ( entry , h_code , i_code ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" % api_guard ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" % env . module_name ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" % env . module_name ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" % h_guard ) <EOL> f = open_new_file ( result . h_file ) <EOL> try : <EOL> h_code . copyto ( f ) <EOL> finally : <EOL> f . close ( ) <EOL> def generate_public_declaration ( self , entry , h_code , i_code ) : <EOL> h_code . putln ( "<STR_LIT>" % ( <EOL> Naming . extern_c_macro , <EOL> entry . type . declaration_code ( <EOL> entry . cname , dll_linkage = "<STR_LIT>" ) ) ) <EOL> if i_code : <EOL> i_code . putln ( "<STR_LIT>" % ( <EOL> entry . type . declaration_code ( entry . cname , pyrex = <NUM_LIT:1> ) ) ) <EOL> def api_name ( self , env ) : <EOL> return env . qualified_name . replace ( "<STR_LIT:.>" , "<STR_LIT>" ) <EOL> def generate_api_code ( self , env , options , result ) : <EOL> def api_entries ( entries , pxd = <NUM_LIT:0> ) : <EOL> return [ entry for entry in entries <EOL> if entry . api or ( pxd and entry . defined_in_pxd ) ] <EOL> api_vars = api_entries ( env . var_entries ) <EOL> api_funcs = api_entries ( env . cfunc_entries ) <EOL> api_extension_types = api_entries ( env . c_class_entries ) <EOL> if api_vars or api_funcs or api_extension_types : <EOL> result . api_file = replace_suffix ( result . c_file , "<STR_LIT>" ) <EOL> h_code = Code . CCodeWriter ( ) <EOL> c_code_config = generate_c_code_config ( env , options ) <EOL> Code . GlobalState ( h_code , self , c_code_config ) <EOL> h_code . put_generated_by ( ) <EOL> api_guard = Naming . api_guard_prefix + self . api_name ( env ) <EOL> h_code . put_h_guard ( api_guard ) <EOL> h_code . putln ( '<STR_LIT>' ) <EOL> if result . h_file : <EOL> h_code . putln ( '<STR_LIT>' % os . path . basename ( result . h_file ) ) <EOL> if api_extension_types : <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> for entry in api_extension_types : <EOL> type = entry . type <EOL> h_code . putln ( "<STR_LIT>" % type . typeptr_cname ) <EOL> h_code . putln ( "<STR_LIT>" % ( <EOL> type . typeobj_cname , type . typeptr_cname ) ) <EOL> if api_funcs : <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> for entry in api_funcs : <EOL> type = CPtrType ( entry . type ) <EOL> cname = env . mangle ( Naming . func_prefix_api , entry . name ) <EOL> h_code . putln ( "<STR_LIT>" % type . declaration_code ( cname ) ) <EOL> h_code . putln ( "<STR_LIT>" % ( entry . name , cname ) ) <EOL> if api_vars : <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> for entry in api_vars : <EOL> type = CPtrType ( entry . type ) <EOL> cname = env . mangle ( Naming . varptr_prefix_api , entry . name ) <EOL> h_code . putln ( "<STR_LIT>" % type . declaration_code ( cname ) ) <EOL> h_code . putln ( "<STR_LIT>" % ( entry . name , cname ) ) <EOL> h_code . put ( UtilityCode . load_as_string ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:0> ] ) <EOL> h_code . put ( UtilityCode . load_as_string ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:1> ] ) <EOL> if api_vars : <EOL> h_code . put ( UtilityCode . load_as_string ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:1> ] ) <EOL> if api_funcs : <EOL> h_code . put ( UtilityCode . load_as_string ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:1> ] ) <EOL> if api_extension_types : <EOL> h_code . put ( UtilityCode . load_as_string ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:1> ] ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" % self . api_name ( env ) ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( '<STR_LIT>' % env . qualified_name ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> for entry in api_funcs : <EOL> cname = env . mangle ( Naming . func_prefix_api , entry . name ) <EOL> sig = entry . type . signature_string ( ) <EOL> h_code . putln ( <EOL> '<STR_LIT>' <EOL> % ( entry . name , cname , sig ) ) <EOL> for entry in api_vars : <EOL> cname = env . mangle ( Naming . varptr_prefix_api , entry . name ) <EOL> sig = entry . type . empty_declaration_code ( ) <EOL> h_code . putln ( <EOL> '<STR_LIT>' <EOL> % ( entry . name , cname , sig ) ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> for entry in api_extension_types : <EOL> self . generate_type_import_call ( <EOL> entry . type , h_code , <EOL> "<STR_LIT>" % entry . type . typeptr_cname ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT:}>" ) <EOL> h_code . putln ( "<STR_LIT>" ) <EOL> h_code . putln ( "<STR_LIT>" % api_guard ) <EOL> f = open_new_file ( result . api_file ) <EOL> try : <EOL> h_code . copyto ( f ) <EOL> finally : <EOL> f . close ( ) <EOL> def generate_cclass_header_code ( self , type , h_code ) : <EOL> h_code . putln ( "<STR_LIT>" % ( <EOL> Naming . extern_c_macro , <EOL> PyrexTypes . public_decl ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> type . typeobj_cname ) ) <EOL> def generate_cclass_include_code ( self , type , i_code ) : <EOL> i_code . putln ( "<STR_LIT>" % ( <EOL> type . module_name , type . name ) ) <EOL> i_code . indent ( ) <EOL> var_entries = type . scope . var_entries <EOL> if var_entries : <EOL> for entry in var_entries : <EOL> i_code . putln ( "<STR_LIT>" % ( <EOL> entry . type . declaration_code ( entry . cname , pyrex = <NUM_LIT:1> ) ) ) <EOL> else : <EOL> i_code . putln ( "<STR_LIT>" ) <EOL> i_code . dedent ( ) <EOL> def generate_c_code ( self , env , options , result ) : <EOL> modules = self . referenced_modules <EOL> if Options . annotate or options . annotate : <EOL> rootwriter = Annotate . AnnotationCCodeWriter ( ) <EOL> else : <EOL> rootwriter = Code . CCodeWriter ( ) <EOL> c_code_config = generate_c_code_config ( env , options ) <EOL> globalstate = Code . GlobalState ( <EOL> rootwriter , self , <EOL> code_config = c_code_config , <EOL> common_utility_include_dir = options . common_utility_include_dir , <EOL> ) <EOL> globalstate . initialize_main_c_code ( ) <EOL> h_code = globalstate [ '<STR_LIT>' ] <EOL> self . generate_module_preamble ( env , options , modules , result . embedded_metadata , h_code ) <EOL> globalstate . module_pos = self . pos <EOL> globalstate . directives = self . directives <EOL> globalstate . use_utility_code ( refnanny_utility_code ) <EOL> code = globalstate [ '<STR_LIT>' ] <EOL> code . putln ( '<STR_LIT>' % self . full_module_name ) <EOL> code . putln ( "<STR_LIT>" % ( Naming . module_is_main , self . full_module_name . replace ( '<STR_LIT:.>' , '<STR_LIT>' ) ) ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % env . qualified_name ) <EOL> code = globalstate [ '<STR_LIT>' ] <EOL> self . generate_cached_builtins_decls ( env , code ) <EOL> self . generate_lambda_definitions ( env , code ) <EOL> self . generate_variable_definitions ( env , code ) <EOL> self . body . generate_function_definitions ( env , code ) <EOL> code . mark_pos ( None ) <EOL> self . generate_typeobj_definitions ( env , code ) <EOL> self . generate_method_table ( env , code ) <EOL> if env . has_import_star : <EOL> self . generate_import_star ( env , code ) <EOL> self . generate_pymoduledef_struct ( env , code ) <EOL> self . generate_module_init_func ( modules [ : - <NUM_LIT:1> ] , env , globalstate [ '<STR_LIT>' ] ) <EOL> self . generate_module_cleanup_func ( env , globalstate [ '<STR_LIT>' ] ) <EOL> if Options . embed : <EOL> self . generate_main_method ( env , globalstate [ '<STR_LIT>' ] ) <EOL> self . generate_filename_table ( globalstate [ '<STR_LIT>' ] ) <EOL> self . generate_declarations_for_modules ( env , modules , globalstate ) <EOL> h_code . write ( '<STR_LIT:\n>' ) <EOL> for utilcode in env . utility_code_list [ : ] : <EOL> globalstate . use_utility_code ( utilcode ) <EOL> globalstate . finalize_main_c_code ( ) <EOL> f = open_new_file ( result . c_file ) <EOL> try : <EOL> rootwriter . copyto ( f ) <EOL> finally : <EOL> f . close ( ) <EOL> result . c_file_generated = <NUM_LIT:1> <EOL> if options . gdb_debug : <EOL> self . _serialize_lineno_map ( env , rootwriter ) <EOL> if Options . annotate or options . annotate : <EOL> self . _generate_annotations ( rootwriter , result , options ) <EOL> def _generate_annotations ( self , rootwriter , result , options ) : <EOL> self . annotate ( rootwriter ) <EOL> coverage_xml_filename = Options . annotate_coverage_xml or options . annotate_coverage_xml <EOL> if coverage_xml_filename and os . path . exists ( coverage_xml_filename ) : <EOL> try : <EOL> import xml . etree . cElementTree as ET <EOL> except ImportError : <EOL> import xml . etree . ElementTree as ET <EOL> coverage_xml = ET . parse ( coverage_xml_filename ) . getroot ( ) <EOL> for el in coverage_xml . getiterator ( ) : <EOL> el . tail = None <EOL> else : <EOL> coverage_xml = None <EOL> rootwriter . save_annotation ( result . main_source_file , result . c_file , coverage_xml = coverage_xml ) <EOL> if not self . scope . included_files : <EOL> return <EOL> search_include_file = self . scope . context . search_include_directories <EOL> target_dir = os . path . abspath ( os . path . dirname ( result . c_file ) ) <EOL> for included_file in self . scope . included_files : <EOL> target_file = os . path . abspath ( os . path . join ( target_dir , included_file ) ) <EOL> target_file_dir = os . path . dirname ( target_file ) <EOL> if not target_file_dir . startswith ( target_dir ) : <EOL> continue <EOL> source_file = search_include_file ( included_file , "<STR_LIT>" , self . pos , include = True ) <EOL> if not source_file : <EOL> continue <EOL> if target_file_dir != target_dir and not os . path . exists ( target_file_dir ) : <EOL> try : <EOL> os . makedirs ( target_file_dir ) <EOL> except OSError as e : <EOL> import errno <EOL> if e . errno != errno . EEXIST : <EOL> raise <EOL> rootwriter . save_annotation ( source_file , target_file , coverage_xml = coverage_xml ) <EOL> def _serialize_lineno_map ( self , env , ccodewriter ) : <EOL> tb = env . context . gdb_debug_outputwriter <EOL> markers = ccodewriter . buffer . allmarkers ( ) <EOL> d = { } <EOL> for c_lineno , cython_lineno in enumerate ( markers ) : <EOL> if cython_lineno > <NUM_LIT:0> : <EOL> d . setdefault ( cython_lineno , [ ] ) . append ( c_lineno + <NUM_LIT:1> ) <EOL> tb . start ( '<STR_LIT>' ) <EOL> for cython_lineno , c_linenos in sorted ( d . items ( ) ) : <EOL> attrs = { <EOL> '<STR_LIT>' : '<STR_LIT:U+0020>' . join ( map ( str , c_linenos ) ) , <EOL> '<STR_LIT>' : str ( cython_lineno ) , <EOL> } <EOL> tb . start ( '<STR_LIT>' , attrs ) <EOL> tb . end ( '<STR_LIT>' ) <EOL> tb . end ( '<STR_LIT>' ) <EOL> tb . serialize ( ) <EOL> def find_referenced_modules ( self , env , module_list , modules_seen ) : <EOL> if env not in modules_seen : <EOL> modules_seen [ env ] = <NUM_LIT:1> <EOL> for imported_module in env . cimported_modules : <EOL> self . find_referenced_modules ( imported_module , module_list , modules_seen ) <EOL> module_list . append ( env ) <EOL> def sort_types_by_inheritance ( self , type_dict , type_order , getkey ) : <EOL> type_list = [ ] <EOL> for i , key in enumerate ( type_order ) : <EOL> new_entry = type_dict [ key ] <EOL> hierarchy = set ( ) <EOL> base = new_entry <EOL> while base : <EOL> base_type = base . type . base_type <EOL> if not base_type : <EOL> break <EOL> base_key = getkey ( base_type ) <EOL> hierarchy . add ( base_key ) <EOL> base = type_dict . get ( base_key ) <EOL> new_entry . base_keys = hierarchy <EOL> for j in range ( i ) : <EOL> entry = type_list [ j ] <EOL> if key in entry . base_keys : <EOL> type_list . insert ( j , new_entry ) <EOL> break <EOL> else : <EOL> type_list . append ( new_entry ) <EOL> return type_list <EOL> def sort_type_hierarchy ( self , module_list , env ) : <EOL> vtab_dict , vtab_dict_order = { } , [ ] <EOL> vtabslot_dict , vtabslot_dict_order = { } , [ ] <EOL> for module in module_list : <EOL> for entry in module . c_class_entries : <EOL> if entry . used and not entry . in_cinclude : <EOL> type = entry . type <EOL> key = type . vtabstruct_cname <EOL> if not key : <EOL> continue <EOL> if key in vtab_dict : <EOL> from . UtilityCode import NonManglingModuleScope <EOL> assert isinstance ( entry . scope , NonManglingModuleScope ) , str ( entry . scope ) <EOL> assert isinstance ( vtab_dict [ key ] . scope , NonManglingModuleScope ) , str ( vtab_dict [ key ] . scope ) <EOL> else : <EOL> vtab_dict [ key ] = entry <EOL> vtab_dict_order . append ( key ) <EOL> all_defined_here = module is env <EOL> for entry in module . type_entries : <EOL> if entry . used and ( all_defined_here or entry . defined_in_pxd ) : <EOL> type = entry . type <EOL> if type . is_extension_type and not entry . in_cinclude : <EOL> type = entry . type <EOL> key = type . objstruct_cname <EOL> assert key not in vtabslot_dict , key <EOL> vtabslot_dict [ key ] = entry <EOL> vtabslot_dict_order . append ( key ) <EOL> def vtabstruct_cname ( entry_type ) : <EOL> return entry_type . vtabstruct_cname <EOL> vtab_list = self . sort_types_by_inheritance ( <EOL> vtab_dict , vtab_dict_order , vtabstruct_cname ) <EOL> def objstruct_cname ( entry_type ) : <EOL> return entry_type . objstruct_cname <EOL> vtabslot_list = self . sort_types_by_inheritance ( <EOL> vtabslot_dict , vtabslot_dict_order , objstruct_cname ) <EOL> return ( vtab_list , vtabslot_list ) <EOL> def sort_cdef_classes ( self , env ) : <EOL> key_func = operator . attrgetter ( '<STR_LIT>' ) <EOL> entry_dict , entry_order = { } , [ ] <EOL> for entry in env . c_class_entries : <EOL> key = key_func ( entry . type ) <EOL> assert key not in entry_dict , key <EOL> entry_dict [ key ] = entry <EOL> entry_order . append ( key ) <EOL> env . c_class_entries [ : ] = self . sort_types_by_inheritance ( <EOL> entry_dict , entry_order , key_func ) <EOL> def generate_type_definitions ( self , env , modules , vtab_list , vtabslot_list , code ) : <EOL> for entry in vtabslot_list : <EOL> self . generate_objstruct_predeclaration ( entry . type , code ) <EOL> vtabslot_entries = set ( vtabslot_list ) <EOL> for module in modules : <EOL> definition = module is env <EOL> if definition : <EOL> type_entries = module . type_entries <EOL> else : <EOL> type_entries = [ ] <EOL> for entry in module . type_entries : <EOL> if entry . defined_in_pxd : <EOL> type_entries . append ( entry ) <EOL> type_entries = [ t for t in type_entries if t not in vtabslot_entries ] <EOL> self . generate_type_header_code ( type_entries , code ) <EOL> for entry in vtabslot_list : <EOL> self . generate_objstruct_definition ( entry . type , code ) <EOL> self . generate_typeobj_predeclaration ( entry , code ) <EOL> for entry in vtab_list : <EOL> self . generate_typeobj_predeclaration ( entry , code ) <EOL> self . generate_exttype_vtable_struct ( entry , code ) <EOL> self . generate_exttype_vtabptr_declaration ( entry , code ) <EOL> self . generate_exttype_final_methods_declaration ( entry , code ) <EOL> def generate_declarations_for_modules ( self , env , modules , globalstate ) : <EOL> typecode = globalstate [ '<STR_LIT>' ] <EOL> typecode . putln ( "<STR_LIT>" ) <EOL> typecode . putln ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in [ m . qualified_name for m in modules ] : <EOL> typecode . putln ( '<STR_LIT>' ) <EOL> typecode . putln ( '<STR_LIT>' ) <EOL> typecode . putln ( '<STR_LIT>' ) <EOL> typecode . putln ( '<STR_LIT>' ) <EOL> vtab_list , vtabslot_list = self . sort_type_hierarchy ( modules , env ) <EOL> self . generate_type_definitions ( <EOL> env , modules , vtab_list , vtabslot_list , typecode ) <EOL> modulecode = globalstate [ '<STR_LIT>' ] <EOL> for module in modules : <EOL> defined_here = module is env <EOL> modulecode . putln ( "<STR_LIT>" ) <EOL> modulecode . putln ( "<STR_LIT>" % module . qualified_name ) <EOL> self . generate_c_class_declarations ( module , modulecode , defined_here ) <EOL> self . generate_cvariable_declarations ( module , modulecode , defined_here ) <EOL> self . generate_cfunction_declarations ( module , modulecode , defined_here ) <EOL> def _put_setup_code ( self , code , name ) : <EOL> code . put ( UtilityCode . load_as_string ( name , "<STR_LIT>" ) [ <NUM_LIT:1> ] ) <EOL> def generate_module_preamble ( self , env , options , cimported_modules , metadata , code ) : <EOL> code . put_generated_by ( ) <EOL> if metadata : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( json . dumps ( metadata , indent = <NUM_LIT:4> , sort_keys = True ) ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> for filename in env . python_include_files : <EOL> code . putln ( '<STR_LIT>' % filename ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . globalstate [ "<STR_LIT:end>" ] . putln ( "<STR_LIT>" ) <EOL> from . . import __version__ <EOL> code . putln ( '<STR_LIT>' % __version__ . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) ) <EOL> self . _put_setup_code ( code , "<STR_LIT>" ) <EOL> if env . context . options . cplus : <EOL> self . _put_setup_code ( code , "<STR_LIT>" ) <EOL> else : <EOL> self . _put_setup_code ( code , "<STR_LIT>" ) <EOL> self . _put_setup_code ( code , "<STR_LIT>" ) <EOL> if options . c_line_in_traceback : <EOL> cinfo = "<STR_LIT>" % ( Naming . clineno_cname , Naming . line_c_macro ) <EOL> else : <EOL> cinfo = "<STR_LIT>" <EOL> code . put ( """<STR_LIT>""" % ( Naming . filename_cname , Naming . filetable_cname , Naming . lineno_cname , cinfo ) ) <EOL> code . put ( """<STR_LIT>""" ) <EOL> if Future . division in env . context . future_directives : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> else : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> self . generate_extern_c_macro_definition ( code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % Naming . h_guard_prefix + self . api_name ( env ) ) <EOL> code . putln ( "<STR_LIT>" % Naming . api_guard_prefix + self . api_name ( env ) ) <EOL> self . generate_includes ( env , cimported_modules , code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if env . directives [ '<STR_LIT>' ] : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . put ( UtilityCode . load_as_string ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:0> ] ) <EOL> c_string_type = env . directives [ '<STR_LIT>' ] <EOL> c_string_encoding = env . directives [ '<STR_LIT>' ] <EOL> if c_string_type not in ( '<STR_LIT>' , '<STR_LIT>' ) and not c_string_encoding : <EOL> error ( self . pos , "<STR_LIT>" ) <EOL> code . putln ( '<STR_LIT>' % int ( c_string_encoding == '<STR_LIT:ascii>' ) ) <EOL> if c_string_encoding == '<STR_LIT:default>' : <EOL> code . putln ( '<STR_LIT>' ) <EOL> else : <EOL> code . putln ( '<STR_LIT>' ) <EOL> code . putln ( '<STR_LIT>' % c_string_encoding ) <EOL> if c_string_type == '<STR_LIT>' : <EOL> c_string_func_name = '<STR_LIT>' <EOL> else : <EOL> c_string_func_name = c_string_type . title ( ) <EOL> code . putln ( '<STR_LIT>' % c_string_func_name ) <EOL> code . putln ( '<STR_LIT>' % c_string_func_name ) <EOL> code . put ( UtilityCode . load_as_string ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:0> ] ) <EOL> PyrexTypes . c_long_type . create_to_py_utility_code ( env ) <EOL> PyrexTypes . c_long_type . create_from_py_utility_code ( env ) <EOL> PyrexTypes . c_int_type . create_from_py_utility_code ( env ) <EOL> code . put ( Nodes . branch_prediction_macros ) <EOL> code . putln ( '<STR_LIT>' ) <EOL> code . putln ( '<STR_LIT>' % env . module_cname ) <EOL> code . putln ( '<STR_LIT>' % env . module_dict_cname ) <EOL> code . putln ( '<STR_LIT>' % Naming . builtins_cname ) <EOL> code . putln ( '<STR_LIT>' % Naming . empty_tuple ) <EOL> code . putln ( '<STR_LIT>' % Naming . empty_bytes ) <EOL> code . putln ( '<STR_LIT>' % Naming . empty_unicode ) <EOL> if Options . pre_import is not None : <EOL> code . putln ( '<STR_LIT>' % Naming . preimport_cname ) <EOL> code . putln ( '<STR_LIT>' % Naming . lineno_cname ) <EOL> code . putln ( '<STR_LIT>' % Naming . clineno_cname ) <EOL> code . putln ( '<STR_LIT>' % ( Naming . cfilenm_cname , Naming . file_c_macro ) ) <EOL> code . putln ( '<STR_LIT>' % Naming . filename_cname ) <EOL> def generate_extern_c_macro_definition ( self , code ) : <EOL> name = Naming . extern_c_macro <EOL> code . putln ( "<STR_LIT>" % name ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( '<STR_LIT>' % name ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % name ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> def generate_dl_import_macro ( self , code ) : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> def generate_includes ( self , env , cimported_modules , code ) : <EOL> includes = [ ] <EOL> for filename in env . include_files : <EOL> byte_decoded_filenname = str ( filename ) <EOL> if byte_decoded_filenname [ <NUM_LIT:0> ] == '<STR_LIT:<>' and byte_decoded_filenname [ - <NUM_LIT:1> ] == '<STR_LIT:>>' : <EOL> code . putln ( '<STR_LIT>' % byte_decoded_filenname ) <EOL> else : <EOL> code . putln ( '<STR_LIT>' % byte_decoded_filenname ) <EOL> code . putln_openmp ( "<STR_LIT>" ) <EOL> def generate_filename_table ( self , code ) : <EOL> import os . path as path <EOL> full_module_path = path . join ( * self . full_module_name . split ( '<STR_LIT:.>' ) ) <EOL> module_abspath = path . splitext ( path . abspath ( <EOL> self . compilation_source . source_desc . get_filenametable_entry ( ) ) ) [ <NUM_LIT:0> ] <EOL> root_path = module_abspath [ : - len ( full_module_path ) ] <EOL> workdir = path . abspath ( os . getcwd ( ) ) + os . sep <EOL> if root_path . startswith ( workdir ) : <EOL> root_path = workdir <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % Naming . filetable_cname ) <EOL> if code . globalstate . filename_list : <EOL> for source_desc in code . globalstate . filename_list : <EOL> file_abspath = path . abspath ( source_desc . get_filenametable_entry ( ) ) <EOL> if file_abspath . startswith ( root_path ) : <EOL> filename = file_abspath [ len ( root_path ) : ] <EOL> else : <EOL> filename = path . basename ( file_abspath ) <EOL> escaped_filename = filename . replace ( "<STR_LIT:\\>" , "<STR_LIT>" ) . replace ( '<STR_LIT:">' , r'<STR_LIT>' ) <EOL> code . putln ( '<STR_LIT>' % escaped_filename ) <EOL> else : <EOL> code . putln ( "<STR_LIT:0>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> def generate_type_predeclarations ( self , env , code ) : <EOL> pass <EOL> def generate_type_header_code ( self , type_entries , code ) : <EOL> for entry in type_entries : <EOL> if not entry . in_cinclude : <EOL> type = entry . type <EOL> if type . is_typedef : <EOL> pass <EOL> elif type . is_struct_or_union or type . is_cpp_class : <EOL> self . generate_struct_union_predeclaration ( entry , code ) <EOL> elif type . is_ctuple and entry . used : <EOL> self . generate_struct_union_predeclaration ( entry . type . struct_entry , code ) <EOL> elif type . is_extension_type : <EOL> self . generate_objstruct_predeclaration ( type , code ) <EOL> for entry in type_entries : <EOL> if not entry . in_cinclude : <EOL> type = entry . type <EOL> if type . is_typedef : <EOL> self . generate_typedef ( entry , code ) <EOL> elif type . is_enum : <EOL> self . generate_enum_definition ( entry , code ) <EOL> elif type . is_struct_or_union : <EOL> self . generate_struct_union_definition ( entry , code ) <EOL> elif type . is_ctuple and entry . used : <EOL> self . generate_struct_union_definition ( entry . type . struct_entry , code ) <EOL> elif type . is_cpp_class : <EOL> self . generate_cpp_class_definition ( entry , code ) <EOL> elif type . is_extension_type : <EOL> self . generate_objstruct_definition ( type , code ) <EOL> def generate_gcc33_hack ( self , env , code ) : <EOL> code . putln ( "<STR_LIT>" ) <EOL> for entry in env . c_class_entries : <EOL> type = entry . type <EOL> if not type . typedef_flag : <EOL> name = type . objstruct_cname <EOL> if name . startswith ( "<STR_LIT>" ) : <EOL> tail = name [ <NUM_LIT:6> : ] <EOL> else : <EOL> tail = name <EOL> code . putln ( "<STR_LIT>" % ( <EOL> name , tail ) ) <EOL> def generate_typedef ( self , entry , code ) : <EOL> base_type = entry . type . typedef_base_type <EOL> if base_type . is_numeric : <EOL> try : <EOL> writer = code . globalstate [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> writer = code <EOL> else : <EOL> writer = code <EOL> writer . mark_pos ( entry . pos ) <EOL> writer . putln ( "<STR_LIT>" % base_type . declaration_code ( entry . cname ) ) <EOL> def sue_predeclaration ( self , type , kind , name ) : <EOL> if type . typedef_flag : <EOL> return "<STR_LIT>" % ( <EOL> kind , name , <EOL> kind , name , name ) <EOL> else : <EOL> return "<STR_LIT>" % ( kind , name ) <EOL> def generate_struct_union_predeclaration ( self , entry , code ) : <EOL> type = entry . type <EOL> if type . is_cpp_class and type . templates : <EOL> code . putln ( "<STR_LIT>" % "<STR_LIT>" . join ( <EOL> [ T . empty_declaration_code ( ) for T in type . templates ] ) ) <EOL> code . putln ( self . sue_predeclaration ( type , type . kind , type . cname ) ) <EOL> def sue_header_footer ( self , type , kind , name ) : <EOL> header = "<STR_LIT>" % ( kind , name ) <EOL> footer = "<STR_LIT>" <EOL> return header , footer <EOL> def generate_struct_union_definition ( self , entry , code ) : <EOL> code . mark_pos ( entry . pos ) <EOL> type = entry . type <EOL> scope = type . scope <EOL> if scope : <EOL> kind = type . kind <EOL> packed = type . is_struct and type . packed <EOL> if packed : <EOL> kind = "<STR_LIT>" % ( type . kind , "<STR_LIT>" ) <EOL> code . globalstate . use_utility_code ( packed_struct_utility_code ) <EOL> header , footer = self . sue_header_footer ( type , kind , type . cname ) <EOL> if packed : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( header ) <EOL> var_entries = scope . var_entries <EOL> if not var_entries : <EOL> error ( entry . pos , "<STR_LIT>" ) <EOL> for attr in var_entries : <EOL> code . putln ( <EOL> "<STR_LIT>" % attr . type . declaration_code ( attr . cname ) ) <EOL> code . putln ( footer ) <EOL> if packed : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> def generate_cpp_class_definition ( self , entry , code ) : <EOL> code . mark_pos ( entry . pos ) <EOL> type = entry . type <EOL> scope = type . scope <EOL> if scope : <EOL> if type . templates : <EOL> code . putln ( "<STR_LIT>" % "<STR_LIT>" . join ( <EOL> [ T . empty_declaration_code ( ) for T in type . templates ] ) ) <EOL> code . put ( "<STR_LIT>" % type . cname ) <EOL> if type . base_classes : <EOL> base_class_decl = "<STR_LIT>" . join ( <EOL> [ base_class . empty_declaration_code ( ) for base_class in type . base_classes ] ) <EOL> code . put ( "<STR_LIT>" % base_class_decl ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> has_virtual_methods = False <EOL> has_destructor = False <EOL> for attr in scope . var_entries : <EOL> if attr . type . is_cfunction and attr . type . is_static_method : <EOL> code . put ( "<STR_LIT>" ) <EOL> elif attr . type . is_cfunction and attr . name != "<STR_LIT>" : <EOL> code . put ( "<STR_LIT>" ) <EOL> has_virtual_methods = True <EOL> if attr . cname [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> has_destructor = True <EOL> code . putln ( "<STR_LIT>" % attr . type . declaration_code ( attr . cname ) ) <EOL> if has_virtual_methods and not has_destructor : <EOL> code . put ( "<STR_LIT>" % type . cname ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> def generate_enum_definition ( self , entry , code ) : <EOL> code . mark_pos ( entry . pos ) <EOL> type = entry . type <EOL> name = entry . cname or entry . name or "<STR_LIT>" <EOL> header , footer = self . sue_header_footer ( type , "<STR_LIT>" , name ) <EOL> code . putln ( header ) <EOL> enum_values = entry . enum_values <EOL> if not enum_values : <EOL> error ( entry . pos , "<STR_LIT>" ) <EOL> else : <EOL> last_entry = enum_values [ - <NUM_LIT:1> ] <EOL> for value_entry in enum_values : <EOL> if value_entry . value_node is not None : <EOL> value_entry . value_node . generate_evaluation_code ( code ) <EOL> for value_entry in enum_values : <EOL> if value_entry . value_node is None : <EOL> value_code = value_entry . cname <EOL> else : <EOL> value_code = ( "<STR_LIT>" % ( <EOL> value_entry . cname , <EOL> value_entry . value_node . result ( ) ) ) <EOL> if value_entry is not last_entry : <EOL> value_code += "<STR_LIT:U+002C>" <EOL> code . putln ( value_code ) <EOL> code . putln ( footer ) <EOL> if entry . type . typedef_flag : <EOL> code . putln ( "<STR_LIT>" % ( name , name ) ) <EOL> def generate_typeobj_predeclaration ( self , entry , code ) : <EOL> code . putln ( "<STR_LIT>" ) <EOL> name = entry . type . typeobj_cname <EOL> if name : <EOL> if entry . visibility == '<STR_LIT>' and not entry . in_cinclude : <EOL> code . putln ( "<STR_LIT>" % ( <EOL> Naming . extern_c_macro , <EOL> PyrexTypes . public_decl ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> name ) ) <EOL> elif entry . visibility == '<STR_LIT>' : <EOL> code . putln ( "<STR_LIT>" % ( <EOL> Naming . extern_c_macro , <EOL> PyrexTypes . public_decl ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> name ) ) <EOL> def generate_exttype_vtable_struct ( self , entry , code ) : <EOL> if not entry . used : <EOL> return <EOL> code . mark_pos ( entry . pos ) <EOL> type = entry . type <EOL> scope = type . scope <EOL> self . specialize_fused_types ( scope ) <EOL> if type . vtabstruct_cname : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % type . vtabstruct_cname ) <EOL> if type . base_type and type . base_type . vtabstruct_cname : <EOL> code . putln ( "<STR_LIT>" % ( <EOL> type . base_type . vtabstruct_cname , <EOL> Naming . obj_base_cname ) ) <EOL> for method_entry in scope . cfunc_entries : <EOL> if not method_entry . is_inherited : <EOL> code . putln ( "<STR_LIT>" % method_entry . type . declaration_code ( "<STR_LIT>" % method_entry . cname ) ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> def generate_exttype_vtabptr_declaration ( self , entry , code ) : <EOL> if not entry . used : <EOL> return <EOL> code . mark_pos ( entry . pos ) <EOL> type = entry . type <EOL> if type . vtabptr_cname : <EOL> code . putln ( "<STR_LIT>" % ( <EOL> type . vtabstruct_cname , <EOL> type . vtabptr_cname ) ) <EOL> def generate_exttype_final_methods_declaration ( self , entry , code ) : <EOL> if not entry . used : <EOL> return <EOL> code . mark_pos ( entry . pos ) <EOL> type = entry . type <EOL> for method_entry in entry . type . scope . cfunc_entries : <EOL> if not method_entry . is_inherited and method_entry . final_func_cname : <EOL> declaration = method_entry . type . declaration_code ( <EOL> method_entry . final_func_cname ) <EOL> modifiers = code . build_function_modifiers ( method_entry . func_modifiers ) <EOL> code . putln ( "<STR_LIT>" % ( modifiers , declaration ) ) <EOL> def generate_objstruct_predeclaration ( self , type , code ) : <EOL> if not type . scope : <EOL> return <EOL> code . putln ( self . sue_predeclaration ( type , "<STR_LIT>" , type . objstruct_cname ) ) <EOL> def generate_objstruct_definition ( self , type , code ) : <EOL> code . mark_pos ( type . pos ) <EOL> if not type . scope : <EOL> return <EOL> header , footer = self . sue_header_footer ( type , "<STR_LIT>" , type . objstruct_cname ) <EOL> code . putln ( header ) <EOL> base_type = type . base_type <EOL> if base_type : <EOL> basestruct_cname = base_type . objstruct_cname <EOL> if basestruct_cname == "<STR_LIT>" : <EOL> basestruct_cname = "<STR_LIT>" <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) [ base_type . typedef_flag ] , <EOL> basestruct_cname , <EOL> Naming . obj_base_cname ) ) <EOL> else : <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if type . vtabslot_cname and not ( type . base_type and type . base_type . vtabslot_cname ) : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> type . vtabstruct_cname , <EOL> type . vtabslot_cname ) ) <EOL> for attr in type . scope . var_entries : <EOL> if attr . is_declared_generic : <EOL> attr_type = py_object_type <EOL> else : <EOL> attr_type = attr . type <EOL> code . putln ( <EOL> "<STR_LIT>" % attr_type . declaration_code ( attr . cname ) ) <EOL> code . putln ( footer ) <EOL> if type . objtypedef_cname is not None : <EOL> code . putln ( "<STR_LIT>" % ( type . objstruct_cname , type . objtypedef_cname ) ) <EOL> def generate_c_class_declarations ( self , env , code , definition ) : <EOL> for entry in env . c_class_entries : <EOL> if definition or entry . defined_in_pxd : <EOL> code . putln ( "<STR_LIT>" % ( <EOL> entry . type . typeptr_cname ) ) <EOL> def generate_cvariable_declarations ( self , env , code , definition ) : <EOL> if env . is_cython_builtin : <EOL> return <EOL> for entry in env . var_entries : <EOL> if ( entry . in_cinclude or entry . in_closure or <EOL> ( entry . visibility == '<STR_LIT>' and not ( entry . defined_in_pxd or entry . used ) ) ) : <EOL> continue <EOL> storage_class = None <EOL> dll_linkage = None <EOL> init = None <EOL> if entry . visibility == '<STR_LIT>' : <EOL> storage_class = Naming . extern_c_macro <EOL> dll_linkage = "<STR_LIT>" <EOL> elif entry . visibility == '<STR_LIT>' : <EOL> storage_class = Naming . extern_c_macro <EOL> if definition : <EOL> dll_linkage = "<STR_LIT>" <EOL> else : <EOL> dll_linkage = "<STR_LIT>" <EOL> elif entry . visibility == '<STR_LIT>' : <EOL> storage_class = "<STR_LIT>" <EOL> dll_linkage = None <EOL> if entry . init is not None : <EOL> init = entry . type . literal_code ( entry . init ) <EOL> type = entry . type <EOL> cname = entry . cname <EOL> if entry . defined_in_pxd and not definition : <EOL> storage_class = "<STR_LIT>" <EOL> dll_linkage = None <EOL> type = CPtrType ( type ) <EOL> cname = env . mangle ( Naming . varptr_prefix , entry . name ) <EOL> init = <NUM_LIT:0> <EOL> if storage_class : <EOL> code . put ( "<STR_LIT>" % storage_class ) <EOL> code . put ( type . declaration_code ( <EOL> cname , dll_linkage = dll_linkage ) ) <EOL> if init is not None : <EOL> code . put_safe ( "<STR_LIT>" % init ) <EOL> code . putln ( "<STR_LIT:;>" ) <EOL> if entry . cname != cname : <EOL> code . putln ( "<STR_LIT>" % ( entry . cname , cname ) ) <EOL> def generate_cfunction_declarations ( self , env , code , definition ) : <EOL> for entry in env . cfunc_entries : <EOL> if entry . used or ( entry . visibility == '<STR_LIT>' or entry . api ) : <EOL> generate_cfunction_declaration ( entry , env , code , definition ) <EOL> def generate_variable_definitions ( self , env , code ) : <EOL> for entry in env . var_entries : <EOL> if not entry . in_cinclude and entry . visibility == "<STR_LIT>" : <EOL> code . put ( entry . type . declaration_code ( entry . cname ) ) <EOL> if entry . init is not None : <EOL> init = entry . type . literal_code ( entry . init ) <EOL> code . put_safe ( "<STR_LIT>" % init ) <EOL> code . putln ( "<STR_LIT:;>" ) <EOL> def generate_typeobj_definitions ( self , env , code ) : <EOL> full_module_name = env . qualified_name <EOL> for entry in env . c_class_entries : <EOL> if entry . visibility != '<STR_LIT>' : <EOL> type = entry . type <EOL> scope = type . scope <EOL> if scope : <EOL> self . generate_exttype_vtable ( scope , code ) <EOL> self . generate_new_function ( scope , code , entry ) <EOL> self . generate_dealloc_function ( scope , code ) <EOL> if scope . needs_gc ( ) : <EOL> self . generate_traverse_function ( scope , code , entry ) <EOL> if scope . needs_tp_clear ( ) : <EOL> self . generate_clear_function ( scope , code , entry ) <EOL> if scope . defines_any ( [ "<STR_LIT>" ] ) : <EOL> self . generate_getitem_int_function ( scope , code ) <EOL> if scope . defines_any ( [ "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> self . generate_ass_subscript_function ( scope , code ) <EOL> if scope . defines_any ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> warning ( self . pos , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <NUM_LIT:1> ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if scope . defines_any ( [ "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> self . generate_ass_slice_function ( scope , code ) <EOL> if scope . defines_any ( [ "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> self . generate_getattro_function ( scope , code ) <EOL> if scope . defines_any ( [ "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> self . generate_setattro_function ( scope , code ) <EOL> if scope . defines_any ( [ "<STR_LIT>" ] ) : <EOL> self . generate_descr_get_function ( scope , code ) <EOL> if scope . defines_any ( [ "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> self . generate_descr_set_function ( scope , code ) <EOL> self . generate_property_accessors ( scope , code ) <EOL> self . generate_method_table ( scope , code ) <EOL> self . generate_getset_table ( scope , code ) <EOL> self . generate_typeobj_definition ( full_module_name , entry , code ) <EOL> def generate_exttype_vtable ( self , scope , code ) : <EOL> type = scope . parent_type <EOL> if type . vtable_cname : <EOL> code . putln ( "<STR_LIT>" % ( <EOL> type . vtabstruct_cname , <EOL> type . vtable_cname ) ) <EOL> def generate_self_cast ( self , scope , code ) : <EOL> type = scope . parent_type <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> type . declaration_code ( "<STR_LIT:p>" ) , <EOL> type . empty_declaration_code ( ) ) ) <EOL> def generate_new_function ( self , scope , code , cclass_entry ) : <EOL> tp_slot = TypeSlots . ConstructorSlot ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> slot_func = scope . mangle_internal ( "<STR_LIT>" ) <EOL> type = scope . parent_type <EOL> base_type = type . base_type <EOL> have_entries , ( py_attrs , py_buffers , memoryview_slices ) = scope . get_refcounted_entries ( ) <EOL> is_final_type = scope . parent_type . is_final_type <EOL> if scope . is_internal : <EOL> py_attrs = [ ] <EOL> cpp_class_attrs = [ entry for entry in scope . var_entries <EOL> if entry . type . is_cpp_class ] <EOL> new_func_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> if base_type or ( new_func_entry and new_func_entry . is_special <EOL> and not new_func_entry . trivial_signature ) : <EOL> unused_marker = '<STR_LIT>' <EOL> else : <EOL> unused_marker = '<STR_LIT>' <EOL> if base_type : <EOL> freelist_size = <NUM_LIT:0> <EOL> else : <EOL> freelist_size = scope . directives . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> freelist_name = scope . mangle_internal ( Naming . freelist_name ) <EOL> freecount_name = scope . mangle_internal ( Naming . freecount_name ) <EOL> decls = code . globalstate [ '<STR_LIT>' ] <EOL> decls . putln ( "<STR_LIT>" % <EOL> slot_func ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if freelist_size : <EOL> code . putln ( "<STR_LIT>" % ( <EOL> scope . parent_type . declaration_code ( freelist_name ) , <EOL> freelist_size ) ) <EOL> code . putln ( "<STR_LIT>" % freecount_name ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> slot_func , unused_marker , unused_marker ) ) <EOL> need_self_cast = ( type . vtabslot_cname or <EOL> ( py_buffers or memoryview_slices or py_attrs ) or <EOL> cpp_class_attrs ) <EOL> if need_self_cast : <EOL> code . putln ( "<STR_LIT>" % scope . parent_type . declaration_code ( "<STR_LIT:p>" ) ) <EOL> if base_type : <EOL> tp_new = TypeSlots . get_base_slot_function ( scope , tp_slot ) <EOL> if tp_new is None : <EOL> tp_new = "<STR_LIT>" % base_type . typeptr_cname <EOL> code . putln ( "<STR_LIT>" % tp_new ) <EOL> else : <EOL> code . putln ( "<STR_LIT>" ) <EOL> if freelist_size : <EOL> code . globalstate . use_utility_code ( <EOL> UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> if is_final_type : <EOL> type_safety_check = '<STR_LIT>' <EOL> else : <EOL> type_safety_check = '<STR_LIT>' <EOL> obj_struct = type . declaration_code ( "<STR_LIT>" , deref = True ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> freecount_name , obj_struct , type_safety_check ) ) <EOL> code . putln ( "<STR_LIT>" % ( <EOL> freelist_name , freecount_name ) ) <EOL> code . putln ( "<STR_LIT>" % obj_struct ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if scope . needs_gc ( ) : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if not is_final_type : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if not is_final_type : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % Naming . empty_tuple ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if freelist_size and not base_type : <EOL> code . putln ( '<STR_LIT:}>' ) <EOL> if need_self_cast : <EOL> code . putln ( "<STR_LIT>" % type . cast_code ( "<STR_LIT:o>" ) ) <EOL> if type . vtabslot_cname : <EOL> vtab_base_type = type <EOL> while vtab_base_type . base_type and vtab_base_type . base_type . vtabstruct_cname : <EOL> vtab_base_type = vtab_base_type . base_type <EOL> if vtab_base_type is not type : <EOL> struct_type_cast = "<STR_LIT>" % vtab_base_type . vtabstruct_cname <EOL> else : <EOL> struct_type_cast = "<STR_LIT>" <EOL> code . putln ( "<STR_LIT>" % ( <EOL> type . vtabslot_cname , <EOL> struct_type_cast , type . vtabptr_cname ) ) <EOL> for entry in cpp_class_attrs : <EOL> code . putln ( "<STR_LIT>" % <EOL> ( entry . cname , entry . type . empty_declaration_code ( ) ) ) <EOL> for entry in py_attrs : <EOL> code . put_init_var_to_py_none ( entry , "<STR_LIT>" , nanny = False ) <EOL> for entry in memoryview_slices : <EOL> code . putln ( "<STR_LIT>" % entry . cname ) <EOL> code . putln ( "<STR_LIT>" % entry . cname ) <EOL> for entry in py_buffers : <EOL> code . putln ( "<STR_LIT>" % entry . cname ) <EOL> if cclass_entry . cname == '<STR_LIT>' : <EOL> code . putln ( "<STR_LIT>" ) <EOL> if new_func_entry and new_func_entry . is_special : <EOL> if new_func_entry . trivial_signature : <EOL> cinit_args = "<STR_LIT>" % Naming . empty_tuple <EOL> else : <EOL> cinit_args = "<STR_LIT>" <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> new_func_entry . func_cname , cinit_args ) ) <EOL> code . put_decref_clear ( "<STR_LIT:o>" , py_object_type , nanny = False ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_dealloc_function ( self , scope , code ) : <EOL> tp_slot = TypeSlots . ConstructorSlot ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> slot_func = scope . mangle_internal ( "<STR_LIT>" ) <EOL> base_type = scope . parent_type . base_type <EOL> if tp_slot . slot_code ( scope ) != slot_func : <EOL> return <EOL> slot_func_cname = scope . mangle_internal ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % slot_func_cname ) <EOL> is_final_type = scope . parent_type . is_final_type <EOL> needs_gc = scope . needs_gc ( ) <EOL> weakref_slot = scope . lookup_here ( "<STR_LIT>" ) <EOL> if weakref_slot not in scope . var_entries : <EOL> weakref_slot = None <EOL> _ , ( py_attrs , _ , memoryview_slices ) = scope . get_refcounted_entries ( ) <EOL> cpp_class_attrs = [ entry for entry in scope . var_entries <EOL> if entry . type . is_cpp_class ] <EOL> if py_attrs or cpp_class_attrs or memoryview_slices or weakref_slot : <EOL> self . generate_self_cast ( scope , code ) <EOL> if not is_final_type : <EOL> code . putln ( "<STR_LIT>" ) <EOL> if needs_gc : <EOL> finalised_check = '<STR_LIT>' <EOL> else : <EOL> finalised_check = ( <EOL> '<STR_LIT>' ) <EOL> code . putln ( "<STR_LIT>" % <EOL> finalised_check ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if needs_gc : <EOL> code . putln ( "<STR_LIT>" ) <EOL> self . generate_usr_dealloc_call ( scope , code ) <EOL> if weakref_slot : <EOL> code . putln ( "<STR_LIT>" ) <EOL> for entry in cpp_class_attrs : <EOL> code . putln ( "<STR_LIT>" % entry . cname ) <EOL> for entry in py_attrs : <EOL> code . put_xdecref_clear ( "<STR_LIT>" % entry . cname , entry . type , nanny = False , <EOL> clear_before_decref = True ) <EOL> for entry in memoryview_slices : <EOL> code . put_xdecref_memoryviewslice ( "<STR_LIT>" % entry . cname , <EOL> have_gil = True ) <EOL> if base_type : <EOL> if needs_gc : <EOL> if base_type . scope and base_type . scope . needs_gc ( ) : <EOL> code . putln ( "<STR_LIT>" ) <EOL> else : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> tp_dealloc = TypeSlots . get_base_slot_function ( scope , tp_slot ) <EOL> if tp_dealloc is not None : <EOL> code . putln ( "<STR_LIT>" % tp_dealloc ) <EOL> elif base_type . is_builtin_type : <EOL> code . putln ( "<STR_LIT>" % base_type . typeptr_cname ) <EOL> else : <EOL> base_cname = base_type . typeptr_cname <EOL> code . putln ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( <EOL> base_cname , base_cname , slot_func_cname ) ) <EOL> code . globalstate . use_utility_code ( <EOL> UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> else : <EOL> freelist_size = scope . directives . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> if freelist_size : <EOL> freelist_name = scope . mangle_internal ( Naming . freelist_name ) <EOL> freecount_name = scope . mangle_internal ( Naming . freecount_name ) <EOL> if is_final_type : <EOL> type_safety_check = '<STR_LIT>' <EOL> else : <EOL> type_safety_check = ( <EOL> '<STR_LIT>' ) <EOL> type = scope . parent_type <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> freecount_name , <EOL> freelist_size , <EOL> type . declaration_code ( "<STR_LIT>" , deref = True ) , <EOL> type_safety_check ) ) <EOL> code . putln ( "<STR_LIT>" % ( <EOL> freelist_name , freecount_name , type . cast_code ( "<STR_LIT:o>" ) ) ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if freelist_size : <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_usr_dealloc_call ( self , scope , code ) : <EOL> entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> if not entry : <EOL> return <EOL> code . putln ( "<STR_LIT:{>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % entry . func_cname ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> def generate_traverse_function ( self , scope , code , cclass_entry ) : <EOL> tp_slot = TypeSlots . GCDependentSlot ( "<STR_LIT>" ) <EOL> slot_func = scope . mangle_internal ( "<STR_LIT>" ) <EOL> base_type = scope . parent_type . base_type <EOL> if tp_slot . slot_code ( scope ) != slot_func : <EOL> return <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % slot_func ) <EOL> have_entries , ( py_attrs , py_buffers , memoryview_slices ) = ( <EOL> scope . get_refcounted_entries ( include_gc_simple = False ) ) <EOL> if base_type or py_attrs : <EOL> code . putln ( "<STR_LIT>" ) <EOL> if py_attrs or py_buffers : <EOL> self . generate_self_cast ( scope , code ) <EOL> if base_type : <EOL> static_call = TypeSlots . get_base_slot_function ( scope , tp_slot ) <EOL> if static_call : <EOL> code . putln ( "<STR_LIT>" % static_call ) <EOL> elif base_type . is_builtin_type : <EOL> base_cname = base_type . typeptr_cname <EOL> code . putln ( "<STR_LIT>" % ( <EOL> base_cname , base_cname ) ) <EOL> else : <EOL> base_cname = base_type . typeptr_cname <EOL> code . putln ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( <EOL> base_cname , base_cname , base_cname , slot_func ) ) <EOL> code . globalstate . use_utility_code ( <EOL> UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> for entry in py_attrs : <EOL> var_code = "<STR_LIT>" % entry . cname <EOL> code . putln ( "<STR_LIT>" % var_code ) <EOL> if entry . type . is_extension_type : <EOL> var_code = "<STR_LIT>" % var_code <EOL> code . putln ( "<STR_LIT>" % var_code ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> for entry in py_buffers : <EOL> cname = entry . cname + "<STR_LIT>" <EOL> code . putln ( "<STR_LIT>" % cname ) <EOL> code . putln ( "<STR_LIT>" % cname ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> def generate_clear_function ( self , scope , code , cclass_entry ) : <EOL> tp_slot = TypeSlots . GCDependentSlot ( "<STR_LIT>" ) <EOL> slot_func = scope . mangle_internal ( "<STR_LIT>" ) <EOL> base_type = scope . parent_type . base_type <EOL> if tp_slot . slot_code ( scope ) != slot_func : <EOL> return <EOL> have_entries , ( py_attrs , py_buffers , memoryview_slices ) = ( <EOL> scope . get_refcounted_entries ( include_gc_simple = False ) ) <EOL> if py_attrs or py_buffers or base_type : <EOL> unused = '<STR_LIT>' <EOL> else : <EOL> unused = '<STR_LIT>' <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % ( slot_func , unused ) ) <EOL> if py_attrs and Options . clear_to_none : <EOL> code . putln ( "<STR_LIT>" ) <EOL> if py_attrs or py_buffers : <EOL> self . generate_self_cast ( scope , code ) <EOL> if base_type : <EOL> static_call = TypeSlots . get_base_slot_function ( scope , tp_slot ) <EOL> if static_call : <EOL> code . putln ( "<STR_LIT>" % static_call ) <EOL> elif base_type . is_builtin_type : <EOL> base_cname = base_type . typeptr_cname <EOL> code . putln ( "<STR_LIT>" % ( <EOL> base_cname , base_cname ) ) <EOL> else : <EOL> base_cname = base_type . typeptr_cname <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> base_cname , base_cname , base_cname , slot_func ) ) <EOL> code . globalstate . use_utility_code ( <EOL> UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> if Options . clear_to_none : <EOL> for entry in py_attrs : <EOL> name = "<STR_LIT>" % entry . cname <EOL> code . putln ( "<STR_LIT>" % name ) <EOL> if entry . is_declared_generic : <EOL> code . put_init_to_py_none ( name , py_object_type , nanny = False ) <EOL> else : <EOL> code . put_init_to_py_none ( name , entry . type , nanny = False ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> else : <EOL> for entry in py_attrs : <EOL> code . putln ( "<STR_LIT>" % entry . cname ) <EOL> for entry in py_buffers : <EOL> code . putln ( "<STR_LIT>" % entry . cname ) <EOL> if cclass_entry . cname == '<STR_LIT>' : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> def generate_getitem_int_function ( self , scope , code ) : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> scope . mangle_internal ( "<STR_LIT>" ) ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_ass_subscript_function ( self , scope , code ) : <EOL> base_type = scope . parent_type . base_type <EOL> set_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> del_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> scope . mangle_internal ( "<STR_LIT>" ) ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if set_entry : <EOL> code . putln ( "<STR_LIT>" % set_entry . func_cname ) <EOL> else : <EOL> self . generate_guarded_basetype_call ( <EOL> base_type , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , code ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> '<STR_LIT>' ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if del_entry : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> del_entry . func_cname ) ) <EOL> else : <EOL> self . generate_guarded_basetype_call ( <EOL> base_type , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , code ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> '<STR_LIT>' ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_guarded_basetype_call ( <EOL> self , base_type , substructure , slot , args , code ) : <EOL> if base_type : <EOL> base_tpname = base_type . typeptr_cname <EOL> if substructure : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> base_tpname , substructure , base_tpname , substructure , slot ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> base_tpname , substructure , slot , args ) ) <EOL> else : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> base_tpname , slot ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> base_tpname , slot , args ) ) <EOL> def generate_ass_slice_function ( self , scope , code ) : <EOL> base_type = scope . parent_type . base_type <EOL> set_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> del_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> scope . mangle_internal ( "<STR_LIT>" ) ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if set_entry : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> set_entry . func_cname ) ) <EOL> else : <EOL> self . generate_guarded_basetype_call ( <EOL> base_type , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , code ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> '<STR_LIT>' ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if del_entry : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> del_entry . func_cname ) ) <EOL> else : <EOL> self . generate_guarded_basetype_call ( <EOL> base_type , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , code ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> '<STR_LIT>' ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_getattro_function ( self , scope , code ) : <EOL> def lookup_here_or_base ( n , type = None ) : <EOL> if type is None : <EOL> type = scope . parent_type <EOL> r = type . scope . lookup_here ( n ) <EOL> if r is None and type . base_type is not None : <EOL> return lookup_here_or_base ( n , type . base_type ) <EOL> else : <EOL> return r <EOL> getattr_entry = lookup_here_or_base ( "<STR_LIT>" ) <EOL> getattribute_entry = lookup_here_or_base ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> scope . mangle_internal ( "<STR_LIT>" ) ) ) <EOL> if getattribute_entry is not None : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> getattribute_entry . func_cname ) ) <EOL> else : <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if getattr_entry is not None : <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> getattr_entry . func_cname ) ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_setattro_function ( self , scope , code ) : <EOL> base_type = scope . parent_type . base_type <EOL> set_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> del_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> scope . mangle_internal ( "<STR_LIT>" ) ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if set_entry : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> set_entry . func_cname ) ) <EOL> else : <EOL> self . generate_guarded_basetype_call ( <EOL> base_type , None , "<STR_LIT>" , "<STR_LIT>" , code ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if del_entry : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> del_entry . func_cname ) ) <EOL> else : <EOL> self . generate_guarded_basetype_call ( <EOL> base_type , None , "<STR_LIT>" , "<STR_LIT>" , code ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_descr_get_function ( self , scope , code ) : <EOL> user_get_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> scope . mangle_internal ( "<STR_LIT>" ) ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> user_get_entry . func_cname ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_descr_set_function ( self , scope , code ) : <EOL> base_type = scope . parent_type . base_type <EOL> user_set_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> user_del_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> scope . mangle_internal ( "<STR_LIT>" ) ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if user_set_entry : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> user_set_entry . func_cname ) ) <EOL> else : <EOL> self . generate_guarded_basetype_call ( <EOL> base_type , None , "<STR_LIT>" , "<STR_LIT>" , code ) <EOL> code . putln ( <EOL> '<STR_LIT>' ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if user_del_entry : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> user_del_entry . func_cname ) ) <EOL> else : <EOL> self . generate_guarded_basetype_call ( <EOL> base_type , None , "<STR_LIT>" , "<STR_LIT>" , code ) <EOL> code . putln ( <EOL> '<STR_LIT>' ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_property_accessors ( self , cclass_scope , code ) : <EOL> for entry in cclass_scope . property_entries : <EOL> property_scope = entry . scope <EOL> if property_scope . defines_any ( [ "<STR_LIT>" ] ) : <EOL> self . generate_property_get_function ( entry , code ) <EOL> if property_scope . defines_any ( [ "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> self . generate_property_set_function ( entry , code ) <EOL> def generate_property_get_function ( self , property_entry , code ) : <EOL> property_scope = property_entry . scope <EOL> property_entry . getter_cname = property_scope . parent_scope . mangle ( <EOL> Naming . prop_get_prefix , property_entry . name ) <EOL> get_entry = property_scope . lookup_here ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> property_entry . getter_cname ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> get_entry . func_cname ) ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_property_set_function ( self , property_entry , code ) : <EOL> property_scope = property_entry . scope <EOL> property_entry . setter_cname = property_scope . parent_scope . mangle ( <EOL> Naming . prop_set_prefix , property_entry . name ) <EOL> set_entry = property_scope . lookup_here ( "<STR_LIT>" ) <EOL> del_entry = property_scope . lookup_here ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> property_entry . setter_cname ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if set_entry : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> set_entry . func_cname ) ) <EOL> else : <EOL> code . putln ( <EOL> '<STR_LIT>' ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> if del_entry : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> del_entry . func_cname ) ) <EOL> else : <EOL> code . putln ( <EOL> '<STR_LIT>' ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> code . putln ( <EOL> "<STR_LIT:}>" ) <EOL> def generate_typeobj_definition ( self , modname , entry , code ) : <EOL> type = entry . type <EOL> scope = type . scope <EOL> for suite in TypeSlots . substructures : <EOL> suite . generate_substructure ( scope , code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if entry . visibility == '<STR_LIT>' : <EOL> header = "<STR_LIT>" <EOL> else : <EOL> header = "<STR_LIT>" <EOL> code . putln ( header % type . typeobj_cname ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> self . full_module_name , scope . class_name ) ) <EOL> if type . typedef_flag : <EOL> objstruct = type . objstruct_cname <EOL> else : <EOL> objstruct = "<STR_LIT>" % type . objstruct_cname <EOL> code . putln ( <EOL> "<STR_LIT>" % objstruct ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> for slot in TypeSlots . slot_table : <EOL> slot . generate ( scope , code ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> def generate_method_table ( self , env , code ) : <EOL> if env . is_c_class_scope and not env . pyfunc_entries : <EOL> return <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> env . method_table_cname ) ) <EOL> for entry in env . pyfunc_entries : <EOL> if not entry . fused_cfunction : <EOL> code . put_pymethoddef ( entry , "<STR_LIT:U+002C>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> def generate_getset_table ( self , env , code ) : <EOL> if env . property_entries : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % <EOL> env . getset_table_cname ) <EOL> for entry in env . property_entries : <EOL> doc = entry . doc <EOL> if doc : <EOL> if doc . is_unicode : <EOL> doc = doc . as_utf8_string ( ) <EOL> doc_code = doc . as_c_string_literal ( ) <EOL> else : <EOL> doc_code = "<STR_LIT:0>" <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> entry . name , <EOL> entry . getter_cname or "<STR_LIT:0>" , <EOL> entry . setter_cname or "<STR_LIT:0>" , <EOL> doc_code ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> def create_import_star_conversion_utility_code ( self , env ) : <EOL> for name , entry in sorted ( env . entries . items ( ) ) : <EOL> if entry . is_cglobal and entry . used : <EOL> if not entry . type . is_pyobject : <EOL> entry . type . create_from_py_utility_code ( env ) <EOL> def generate_import_star ( self , env , code ) : <EOL> env . use_utility_code ( UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> code . putln ( ) <EOL> code . enter_cfunc_scope ( ) <EOL> code . putln ( "<STR_LIT>" % Naming . import_star_set ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> for name , entry in sorted ( env . entries . items ( ) ) : <EOL> if entry . is_type : <EOL> code . putln ( '<STR_LIT>' % name ) <EOL> code . putln ( "<STR_LIT:0>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( '<STR_LIT>' ) <EOL> code . putln ( '<STR_LIT>' ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> old_error_label = code . new_error_label ( ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> for name , entry in sorted ( env . entries . items ( ) ) : <EOL> if entry . is_cglobal and entry . used : <EOL> code . putln ( '<STR_LIT>' % name ) <EOL> if entry . type . is_pyobject : <EOL> if entry . type . is_extension_type or entry . type . is_builtin_type : <EOL> code . putln ( "<STR_LIT>" % ( <EOL> entry . type . type_test_code ( "<STR_LIT:o>" ) , <EOL> code . error_goto ( entry . pos ) ) ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . put_decref ( entry . cname , entry . type , nanny = False ) <EOL> code . putln ( "<STR_LIT>" % ( <EOL> entry . cname , <EOL> PyrexTypes . typecast ( entry . type , py_object_type , "<STR_LIT:o>" ) ) ) <EOL> elif entry . type . create_from_py_utility_code ( env ) : <EOL> code . putln ( entry . type . from_py_call_code ( <EOL> '<STR_LIT:o>' , entry . cname , entry . pos , code ) ) <EOL> else : <EOL> code . putln ( '<STR_LIT>' % ( <EOL> name , entry . type ) ) <EOL> code . putln ( code . error_goto ( entry . pos ) ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % Naming . module_cname ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if code . label_used ( code . error_label ) : <EOL> code . put_label ( code . error_label ) <EOL> code . put_add_traceback ( self . full_module_name ) <EOL> code . error_label = old_error_label <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) . impl ) <EOL> code . exit_cfunc_scope ( ) <EOL> def generate_module_init_func ( self , imported_modules , env , code ) : <EOL> code . enter_cfunc_scope ( ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> header2 = "<STR_LIT>" % env . module_name <EOL> header3 = "<STR_LIT>" % env . module_name <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % header2 ) <EOL> code . putln ( header2 ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % header3 ) <EOL> code . putln ( header3 ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT:{>" ) <EOL> tempdecl_code = code . insertion_point ( ) <EOL> profile = code . globalstate . directives [ '<STR_LIT>' ] <EOL> linetrace = code . globalstate . directives [ '<STR_LIT>' ] <EOL> if profile or linetrace : <EOL> code . globalstate . use_utility_code ( UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> code . put_declare_refcount_context ( ) <EOL> if profile or linetrace : <EOL> tempdecl_code . put_trace_declarations ( ) <EOL> code . put_trace_frame_init ( ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . put_setup_refcount_context ( header3 ) <EOL> env . use_utility_code ( UtilityCode . load ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> code . put_error_if_neg ( self . pos , "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % ( <EOL> Naming . empty_tuple , code . error_goto_if_null ( Naming . empty_tuple , self . pos ) ) ) <EOL> code . putln ( "<STR_LIT>" % ( <EOL> Naming . empty_bytes , code . error_goto_if_null ( Naming . empty_bytes , self . pos ) ) ) <EOL> code . putln ( "<STR_LIT>" % ( <EOL> Naming . empty_unicode , code . error_goto_if_null ( Naming . empty_unicode , self . pos ) ) ) <EOL> for ext_type in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> code . putln ( "<STR_LIT>" % ext_type ) <EOL> code . put_error_if_neg ( self . pos , "<STR_LIT>" % ext_type ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> env . generate_library_function_declarations ( code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> self . generate_module_creation_code ( env , code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . put_error_if_neg ( self . pos , "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> code . put_error_if_neg ( self . pos , "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> __main__name = code . globalstate . get_py_string_const ( <EOL> EncodedString ( "<STR_LIT:__main__>" ) , identifier = True ) <EOL> code . putln ( "<STR_LIT>" % ( Naming . module_is_main , self . full_module_name . replace ( '<STR_LIT:.>' , '<STR_LIT>' ) ) ) <EOL> code . put_error_if_neg ( self . pos , '<STR_LIT>' % ( <EOL> env . module_cname , <EOL> __main__name . cname ) ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> self . generate_module_import_setup ( env , code ) <EOL> if Options . cache_builtins : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . put_error_if_neg ( self . pos , "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . put_error_if_neg ( self . pos , "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> self . generate_global_init_code ( env , code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> self . generate_c_variable_export_code ( env , code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> self . generate_c_function_export_code ( env , code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> self . generate_type_init_code ( env , code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> for module in imported_modules : <EOL> self . generate_type_import_code_for_module ( module , env , code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> for module in imported_modules : <EOL> self . generate_c_variable_import_code_for_module ( module , env , code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> for module in imported_modules : <EOL> self . specialize_fused_types ( module ) <EOL> self . generate_c_function_import_code_for_module ( module , env , code ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . mark_pos ( None ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . put_error_if_neg ( self . pos , "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if profile or linetrace : <EOL> code . put_trace_call ( header3 , self . pos , nogil = not code . funcstate . gil_owned ) <EOL> code . funcstate . can_trace = True <EOL> self . body . generate_execution_code ( code ) <EOL> if profile or linetrace : <EOL> code . funcstate . can_trace = False <EOL> code . put_trace_return ( "<STR_LIT>" , nogil = not code . funcstate . gil_owned ) <EOL> code . putln ( ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> self . generate_wrapped_entries_code ( env , code ) <EOL> code . putln ( ) <EOL> if Options . generate_cleanup_code : <EOL> code . globalstate . use_utility_code ( <EOL> UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> code . putln ( "<STR_LIT>" % code . error_goto ( self . pos ) ) <EOL> code . put_goto ( code . return_label ) <EOL> code . put_label ( code . error_label ) <EOL> for cname , type in code . funcstate . all_managed_temps ( ) : <EOL> code . put_xdecref ( cname , type ) <EOL> code . putln ( '<STR_LIT>' % env . module_cname ) <EOL> code . putln ( '<STR_LIT>' % env . module_dict_cname ) <EOL> code . put_add_traceback ( "<STR_LIT>" % env . qualified_name ) <EOL> code . globalstate . use_utility_code ( Nodes . traceback_utility_code ) <EOL> code . putln ( '<STR_LIT:}>' ) <EOL> code . put_decref_clear ( env . module_cname , py_object_type , nanny = False ) <EOL> code . putln ( '<STR_LIT>' ) <EOL> code . putln ( '<STR_LIT>' % env . qualified_name ) <EOL> code . putln ( '<STR_LIT:}>' ) <EOL> code . put_label ( code . return_label ) <EOL> code . put_finish_refcount_context ( ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % env . module_cname ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( '<STR_LIT:}>' ) <EOL> tempdecl_code . put_temp_declarations ( code . funcstate ) <EOL> code . exit_cfunc_scope ( ) <EOL> def generate_module_import_setup ( self , env , code ) : <EOL> module_path = env . directives [ '<STR_LIT>' ] <EOL> if module_path == '<STR_LIT>' : <EOL> module_path = self . pos [ <NUM_LIT:0> ] . filename <EOL> if module_path : <EOL> code . putln ( '<STR_LIT>' % ( <EOL> env . module_cname , <EOL> code . globalstate . get_py_string_const ( <EOL> EncodedString ( decode_filename ( module_path ) ) ) . cname , <EOL> code . error_goto ( self . pos ) ) ) <EOL> if env . is_package : <EOL> temp = code . funcstate . allocate_temp ( py_object_type , True ) <EOL> code . putln ( '<STR_LIT>' % ( <EOL> temp , <EOL> code . globalstate . get_py_string_const ( <EOL> EncodedString ( decode_filename ( <EOL> os . path . dirname ( module_path ) ) ) ) . cname , <EOL> code . error_goto_if_null ( temp , self . pos ) ) ) <EOL> code . put_gotref ( temp ) <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> env . module_cname , temp , code . error_goto ( self . pos ) ) ) <EOL> code . put_decref_clear ( temp , py_object_type ) <EOL> code . funcstate . release_temp ( temp ) <EOL> elif env . is_package : <EOL> package_name , _ = self . full_module_name . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> if '<STR_LIT:.>' in package_name : <EOL> parent_name = '<STR_LIT>' % ( package_name . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] , ) <EOL> else : <EOL> parent_name = '<STR_LIT>' <EOL> code . globalstate . use_utility_code ( UtilityCode . load ( <EOL> "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> code . putln ( code . error_goto_if_neg ( <EOL> '<STR_LIT>' % ( <EOL> parent_name , <EOL> code . globalstate . get_py_string_const ( <EOL> EncodedString ( env . module_name ) ) . cname ) , <EOL> self . pos ) ) <EOL> fq_module_name = self . full_module_name <EOL> if fq_module_name . endswith ( '<STR_LIT>' ) : <EOL> fq_module_name = fq_module_name [ : - len ( '<STR_LIT>' ) ] <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT:{>" ) <EOL> code . putln ( "<STR_LIT>" % <EOL> code . error_goto_if_null ( "<STR_LIT>" , self . pos ) ) <EOL> code . putln ( '<STR_LIT>' % fq_module_name ) <EOL> code . putln ( code . error_goto_if_neg ( '<STR_LIT>' % ( <EOL> fq_module_name , env . module_cname ) , self . pos ) ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> def generate_module_cleanup_func ( self , env , code ) : <EOL> if not Options . generate_cleanup_code : <EOL> return <EOL> code . putln ( '<STR_LIT>' % <EOL> Naming . cleanup_cname ) <EOL> if Options . generate_cleanup_code >= <NUM_LIT:2> : <EOL> code . putln ( "<STR_LIT>" ) <EOL> rev_entries = list ( env . var_entries ) <EOL> rev_entries . reverse ( ) <EOL> for entry in rev_entries : <EOL> if entry . visibility != '<STR_LIT>' : <EOL> if entry . type . is_pyobject and entry . used : <EOL> code . put_xdecref_clear ( <EOL> entry . cname , entry . type , <EOL> clear_before_decref = True , <EOL> nanny = False ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> if Options . generate_cleanup_code >= <NUM_LIT:3> : <EOL> code . putln ( "<STR_LIT>" ) <EOL> for ext_type in sorted ( env . types_imported , key = operator . attrgetter ( '<STR_LIT>' ) ) : <EOL> code . put_xdecref_clear ( <EOL> ext_type . typeptr_cname , ext_type , <EOL> clear_before_decref = True , <EOL> nanny = False ) <EOL> if Options . cache_builtins : <EOL> code . putln ( "<STR_LIT>" ) <EOL> for entry in env . cached_builtins : <EOL> code . put_xdecref_clear ( <EOL> entry . cname , PyrexTypes . py_object_type , <EOL> clear_before_decref = True , <EOL> nanny = False ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . put_decref_clear ( Naming . empty_tuple , <EOL> PyrexTypes . py_object_type , <EOL> clear_before_decref = True , <EOL> nanny = False ) <EOL> for entry in env . c_class_entries : <EOL> cclass_type = entry . type <EOL> if cclass_type . is_external or cclass_type . base_type : <EOL> continue <EOL> if cclass_type . scope . directives . get ( '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> scope = cclass_type . scope <EOL> freelist_name = scope . mangle_internal ( Naming . freelist_name ) <EOL> freecount_name = scope . mangle_internal ( Naming . freecount_name ) <EOL> code . putln ( "<STR_LIT>" % freecount_name ) <EOL> code . putln ( "<STR_LIT>" % ( <EOL> freelist_name , freecount_name ) ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( '<STR_LIT>' ) <EOL> code . putln ( '<STR_LIT>' % Naming . builtins_cname ) <EOL> code . putln ( '<STR_LIT>' ) <EOL> code . put_decref_clear ( env . module_dict_cname , py_object_type , <EOL> nanny = False , clear_before_decref = True ) <EOL> def generate_main_method ( self , env , code ) : <EOL> module_is_main = "<STR_LIT>" % ( Naming . module_is_main , self . full_module_name . replace ( '<STR_LIT:.>' , '<STR_LIT>' ) ) <EOL> if Options . embed == "<STR_LIT>" : <EOL> wmain = "<STR_LIT>" <EOL> else : <EOL> wmain = Options . embed <EOL> main_method = UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> code . globalstate . use_utility_code ( <EOL> main_method . specialize ( <EOL> module_name = env . module_name , <EOL> module_is_main = module_is_main , <EOL> main_method = Options . embed , <EOL> wmain_method = wmain ) ) <EOL> def generate_pymoduledef_struct ( self , env , code ) : <EOL> if env . doc : <EOL> doc = "<STR_LIT:%s>" % code . get_string_const ( env . doc ) <EOL> else : <EOL> doc = "<STR_LIT:0>" <EOL> if Options . generate_cleanup_code : <EOL> cleanup_func = "<STR_LIT>" % Naming . cleanup_cname <EOL> else : <EOL> cleanup_func = '<STR_LIT>' <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % Naming . pymoduledef_cname ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( '<STR_LIT>' % env . module_name ) <EOL> code . putln ( "<STR_LIT>" % doc ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % env . method_table_cname ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % cleanup_func ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> def generate_module_creation_code ( self , env , code ) : <EOL> if env . doc : <EOL> doc = "<STR_LIT:%s>" % code . get_string_const ( env . doc ) <EOL> else : <EOL> doc = "<STR_LIT:0>" <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> env . module_cname , <EOL> env . module_name , <EOL> env . method_table_cname , <EOL> doc , <EOL> env . module_cname ) ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> env . module_cname , <EOL> Naming . pymoduledef_cname ) ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( code . error_goto_if_null ( env . module_cname , self . pos ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> env . module_dict_cname , env . module_cname , <EOL> code . error_goto_if_null ( env . module_dict_cname , self . pos ) ) ) <EOL> code . put_incref ( env . module_dict_cname , py_object_type , nanny = False ) <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> Naming . builtins_cname , <EOL> code . error_goto_if_null ( Naming . builtins_cname , self . pos ) ) ) <EOL> code . putln ( '<STR_LIT>' ) <EOL> code . putln ( '<STR_LIT>' % Naming . builtins_cname ) <EOL> code . putln ( '<STR_LIT>' ) <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> env . module_cname , <EOL> Naming . builtins_cname , <EOL> code . error_goto ( self . pos ) ) ) <EOL> if Options . pre_import is not None : <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> Naming . preimport_cname , <EOL> Options . pre_import , <EOL> code . error_goto_if_null ( Naming . preimport_cname , self . pos ) ) ) <EOL> def generate_global_init_code ( self , env , code ) : <EOL> for entry in env . var_entries : <EOL> if entry . visibility != '<STR_LIT>' : <EOL> if entry . used : <EOL> entry . type . global_init_code ( entry , code ) <EOL> def generate_wrapped_entries_code ( self , env , code ) : <EOL> for name , entry in sorted ( env . entries . items ( ) ) : <EOL> if ( entry . create_wrapper <EOL> and not entry . is_type <EOL> and entry . scope is env ) : <EOL> if not entry . type . create_to_py_utility_code ( env ) : <EOL> error ( entry . pos , "<STR_LIT>" % entry . type ) <EOL> code . putln ( "<STR_LIT:{>" ) <EOL> code . putln ( "<STR_LIT>" % ( <EOL> entry . type . to_py_function , <EOL> entry . cname ) ) <EOL> code . putln ( code . error_goto_if_null ( "<STR_LIT>" , entry . pos ) ) <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> env . module_cname , <EOL> name , <EOL> code . error_goto ( entry . pos ) ) ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> def generate_c_variable_export_code ( self , env , code ) : <EOL> entries = [ ] <EOL> for entry in env . var_entries : <EOL> if ( entry . api <EOL> or entry . defined_in_pxd <EOL> or ( Options . cimport_from_pyx and not entry . visibility == '<STR_LIT>' ) ) : <EOL> entries . append ( entry ) <EOL> if entries : <EOL> env . use_utility_code ( UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> for entry in entries : <EOL> signature = entry . type . empty_declaration_code ( ) <EOL> name = code . intern_identifier ( entry . name ) <EOL> code . putln ( '<STR_LIT>' % ( <EOL> name , entry . cname , signature , <EOL> code . error_goto ( self . pos ) ) ) <EOL> def generate_c_function_export_code ( self , env , code ) : <EOL> entries = [ ] <EOL> for entry in env . cfunc_entries : <EOL> if ( entry . api <EOL> or entry . defined_in_pxd <EOL> or ( Options . cimport_from_pyx and not entry . visibility == '<STR_LIT>' ) ) : <EOL> entries . append ( entry ) <EOL> if entries : <EOL> env . use_utility_code ( <EOL> UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> for entry in entries : <EOL> signature = entry . type . signature_string ( ) <EOL> code . putln ( '<STR_LIT>' % ( <EOL> entry . name , <EOL> entry . cname , <EOL> signature , <EOL> code . error_goto ( self . pos ) ) ) <EOL> def generate_type_import_code_for_module ( self , module , env , code ) : <EOL> for entry in module . c_class_entries : <EOL> if entry . defined_in_pxd : <EOL> self . generate_type_import_code ( env , entry . type , entry . pos , code ) <EOL> def specialize_fused_types ( self , pxd_env ) : <EOL> """<STR_LIT>""" <EOL> for entry in pxd_env . cfunc_entries [ : ] : <EOL> if entry . type . is_fused : <EOL> entry . type . get_all_specialized_function_types ( ) <EOL> def generate_c_variable_import_code_for_module ( self , module , env , code ) : <EOL> entries = [ ] <EOL> for entry in module . var_entries : <EOL> if entry . defined_in_pxd : <EOL> entries . append ( entry ) <EOL> if entries : <EOL> env . use_utility_code ( <EOL> UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> env . use_utility_code ( <EOL> UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> temp = code . funcstate . allocate_temp ( py_object_type , manage_ref = True ) <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> temp , <EOL> module . qualified_name , <EOL> temp , <EOL> code . error_goto ( self . pos ) ) ) <EOL> for entry in entries : <EOL> if env is module : <EOL> cname = entry . cname <EOL> else : <EOL> cname = module . mangle ( Naming . varptr_prefix , entry . name ) <EOL> signature = entry . type . empty_declaration_code ( ) <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> temp , entry . name , cname , signature , <EOL> code . error_goto ( self . pos ) ) ) <EOL> code . putln ( "<STR_LIT>" % ( temp , temp ) ) <EOL> def generate_c_function_import_code_for_module ( self , module , env , code ) : <EOL> entries = [ ] <EOL> for entry in module . cfunc_entries : <EOL> if entry . defined_in_pxd and entry . used : <EOL> entries . append ( entry ) <EOL> if entries : <EOL> env . use_utility_code ( <EOL> UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> env . use_utility_code ( <EOL> UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> temp = code . funcstate . allocate_temp ( py_object_type , manage_ref = True ) <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> temp , <EOL> module . qualified_name , <EOL> temp , <EOL> code . error_goto ( self . pos ) ) ) <EOL> for entry in entries : <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> temp , <EOL> entry . name , <EOL> entry . cname , <EOL> entry . type . signature_string ( ) , <EOL> code . error_goto ( self . pos ) ) ) <EOL> code . putln ( "<STR_LIT>" % ( temp , temp ) ) <EOL> def generate_type_init_code ( self , env , code ) : <EOL> for entry in env . c_class_entries : <EOL> if entry . visibility == '<STR_LIT>' and not entry . utility_code_definition : <EOL> self . generate_type_import_code ( env , entry . type , entry . pos , code ) <EOL> else : <EOL> self . generate_base_type_import_code ( env , entry , code ) <EOL> self . generate_exttype_vtable_init_code ( entry , code ) <EOL> self . generate_type_ready_code ( env , entry , code ) <EOL> self . generate_typeptr_assignment_code ( entry , code ) <EOL> def generate_base_type_import_code ( self , env , entry , code ) : <EOL> base_type = entry . type . base_type <EOL> if ( base_type and base_type . module_name != env . qualified_name and not <EOL> base_type . is_builtin_type and not entry . utility_code_definition ) : <EOL> self . generate_type_import_code ( env , base_type , self . pos , code ) <EOL> def generate_type_import_code ( self , env , type , pos , code ) : <EOL> if type in env . types_imported : <EOL> return <EOL> env . use_utility_code ( UtilityCode . load_cached ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . generate_type_import_call ( type , code , <EOL> code . error_goto_if_null ( type . typeptr_cname , pos ) ) <EOL> if type . vtabptr_cname : <EOL> code . globalstate . use_utility_code ( <EOL> UtilityCode . load_cached ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> code . putln ( "<STR_LIT>" % ( <EOL> type . vtabptr_cname , <EOL> type . vtabstruct_cname , <EOL> type . typeptr_cname , <EOL> code . error_goto_if_null ( type . vtabptr_cname , pos ) ) ) <EOL> env . types_imported . add ( type ) <EOL> py3_type_name_map = { '<STR_LIT:str>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:str>' } <EOL> def generate_type_import_call ( self , type , code , error_code ) : <EOL> if type . typedef_flag : <EOL> objstruct = type . objstruct_cname <EOL> else : <EOL> objstruct = "<STR_LIT>" % type . objstruct_cname <EOL> sizeof_objstruct = objstruct <EOL> module_name = type . module_name <EOL> condition = replacement = None <EOL> if module_name not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> module_name = '<STR_LIT>' % module_name <EOL> else : <EOL> module_name = '<STR_LIT>' <EOL> if type . name in Code . non_portable_builtins_map : <EOL> condition , replacement = Code . non_portable_builtins_map [ type . name ] <EOL> if objstruct in Code . basicsize_builtins_map : <EOL> sizeof_objstruct = Code . basicsize_builtins_map [ objstruct ] <EOL> code . put ( '<STR_LIT>' % ( <EOL> type . typeptr_cname , <EOL> module_name ) ) <EOL> if condition and replacement : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" % condition ) <EOL> code . putln ( '<STR_LIT>' % replacement ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( '<STR_LIT>' % type . name ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> else : <EOL> code . put ( '<STR_LIT>' % type . name ) <EOL> if sizeof_objstruct != objstruct : <EOL> if not condition : <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( '<STR_LIT>' % objstruct ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> code . putln ( '<STR_LIT>' % sizeof_objstruct ) <EOL> code . putln ( "<STR_LIT>" ) <EOL> else : <EOL> code . put ( '<STR_LIT>' % objstruct ) <EOL> code . putln ( '<STR_LIT>' % ( <EOL> not type . is_external or type . is_subclassed , <EOL> error_code ) ) <EOL> def generate_type_ready_code ( self , env , entry , code ) : <EOL> type = entry . type <EOL> typeobj_cname = type . typeobj_cname <EOL> scope = type . scope <EOL> if scope : <EOL> if entry . visibility != '<STR_LIT>' : <EOL> for slot in TypeSlots . slot_table : <EOL> slot . generate_dynamic_init_code ( scope , code ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> typeobj_cname , <EOL> code . error_goto ( entry . pos ) ) ) <EOL> code . putln ( "<STR_LIT>" % typeobj_cname ) <EOL> for func in entry . type . scope . pyfunc_entries : <EOL> is_buffer = func . name in ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if ( func . is_special and Options . docstrings and <EOL> func . wrapperbase_cname and not is_buffer ) : <EOL> slot = TypeSlots . method_name_to_slot [ func . name ] <EOL> preprocessor_guard = slot . preprocessor_guard_code ( ) <EOL> if preprocessor_guard : <EOL> code . putln ( preprocessor_guard ) <EOL> code . putln ( '<STR_LIT>' ) <EOL> code . putln ( "<STR_LIT:{>" ) <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> typeobj_cname , <EOL> func . name , <EOL> code . error_goto_if_null ( '<STR_LIT>' , entry . pos ) ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> func . wrapperbase_cname ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( func . wrapperbase_cname , func . doc_cname ) ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> func . wrapperbase_cname ) ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( "<STR_LIT:}>" ) <EOL> code . putln ( '<STR_LIT>' ) <EOL> if preprocessor_guard : <EOL> code . putln ( '<STR_LIT>' ) <EOL> if type . vtable_cname : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> typeobj_cname , <EOL> type . vtabptr_cname , <EOL> code . error_goto ( entry . pos ) ) ) <EOL> code . globalstate . use_utility_code ( <EOL> UtilityCode . load_cached ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if not type . scope . is_internal and not type . scope . directives [ '<STR_LIT>' ] : <EOL> code . putln ( <EOL> '<STR_LIT>' % ( <EOL> Naming . module_cname , <EOL> scope . class_name , <EOL> typeobj_cname , <EOL> code . error_goto ( entry . pos ) ) ) <EOL> weakref_entry = scope . lookup_here ( "<STR_LIT>" ) <EOL> if weakref_entry : <EOL> if weakref_entry . type is py_object_type : <EOL> tp_weaklistoffset = "<STR_LIT>" % typeobj_cname <EOL> if type . typedef_flag : <EOL> objstruct = type . objstruct_cname <EOL> else : <EOL> objstruct = "<STR_LIT>" % type . objstruct_cname <EOL> code . putln ( "<STR_LIT>" % ( <EOL> tp_weaklistoffset , <EOL> tp_weaklistoffset , <EOL> objstruct , <EOL> weakref_entry . cname ) ) <EOL> else : <EOL> error ( weakref_entry . pos , "<STR_LIT>" ) <EOL> def generate_exttype_vtable_init_code ( self , entry , code ) : <EOL> type = entry . type <EOL> if type . vtable_cname : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> type . vtabptr_cname , <EOL> type . vtable_cname ) ) <EOL> if type . base_type and type . base_type . vtabptr_cname : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> type . vtable_cname , <EOL> Naming . obj_base_cname , <EOL> type . base_type . vtabptr_cname ) ) <EOL> c_method_entries = [ <EOL> entry for entry in type . scope . cfunc_entries <EOL> if entry . func_cname ] <EOL> if c_method_entries : <EOL> for meth_entry in c_method_entries : <EOL> cast = meth_entry . type . signature_cast_string ( ) <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> type . vtable_cname , <EOL> meth_entry . cname , <EOL> cast , <EOL> meth_entry . func_cname ) ) <EOL> def generate_typeptr_assignment_code ( self , entry , code ) : <EOL> type = entry . type <EOL> if type . typeobj_cname : <EOL> code . putln ( <EOL> "<STR_LIT>" % ( <EOL> type . typeptr_cname , type . typeobj_cname ) ) <EOL> def generate_cfunction_declaration ( entry , env , code , definition ) : <EOL> from_cy_utility = entry . used and entry . utility_code_definition <EOL> if entry . used and entry . inline_func_in_pxd or ( not entry . in_cinclude and ( <EOL> definition or entry . defined_in_pxd or entry . visibility == '<STR_LIT>' or from_cy_utility ) ) : <EOL> if entry . visibility == '<STR_LIT>' : <EOL> storage_class = Naming . extern_c_macro <EOL> dll_linkage = "<STR_LIT>" <EOL> elif entry . visibility == '<STR_LIT>' : <EOL> storage_class = Naming . extern_c_macro <EOL> dll_linkage = "<STR_LIT>" <EOL> elif entry . visibility == '<STR_LIT>' : <EOL> storage_class = "<STR_LIT>" <EOL> dll_linkage = None <EOL> else : <EOL> storage_class = "<STR_LIT>" <EOL> dll_linkage = None <EOL> type = entry . type <EOL> if entry . defined_in_pxd and not definition : <EOL> storage_class = "<STR_LIT>" <EOL> dll_linkage = None <EOL> type = CPtrType ( type ) <EOL> header = type . declaration_code ( <EOL> entry . cname , dll_linkage = dll_linkage ) <EOL> modifiers = code . build_function_modifiers ( entry . func_modifiers ) <EOL> code . putln ( "<STR_LIT>" % ( <EOL> storage_class , <EOL> modifiers , <EOL> header ) ) <EOL> refnanny_utility_code = UtilityCode . load ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> packed_struct_utility_code = UtilityCode ( proto = """<STR_LIT>""" , impl = "<STR_LIT>" , proto_block = '<STR_LIT>' ) <EOL> capsule_utility_code = UtilityCode . load ( "<STR_LIT>" ) </s>
