Ticket #286: split-encoding-charset-labeling-from-init.patch

File split-encoding-charset-labeling-from-init.patch, 7.6 KB (added by Infinoid, 13 years ago)

split-encoding-charset-labeling-from-init.patch v2

  • include/parrot/encoding.h

    commit 8afa6355db522255e2d9a8e9471e6d874e84a1f0
    Author: Mark Glines <mark@glines.org>
    Date:   Sun Feb 8 09:23:09 2009 -0800
    
        Split the labeling of charsets and encodings until after the init functions have been called.
    
    diff --git a/include/parrot/encoding.h b/include/parrot/encoding.h
    index 55118db..3c70ae0 100644
    a b  
    152152        __attribute__nonnull__(3); 
    153153 
    154154void parrot_deinit_encodings(void); 
    155 void parrot_init_encodings_2(void); 
     155void Parrot_str_internal_register_encoding_names(PARROT_INTERP) 
     156        __attribute__nonnull__(1); 
     157 
    156158#define ASSERT_ARGS_Parrot_default_encoding __attribute__unused__ int _ASSERT_ARGS_CHECK = 0 
    157159#define ASSERT_ARGS_Parrot_encoding_c_name __attribute__unused__ int _ASSERT_ARGS_CHECK = 0 
    158160#define ASSERT_ARGS_Parrot_encoding_name __attribute__unused__ int _ASSERT_ARGS_CHECK = 0 
     
    180182    || PARROT_ASSERT_ARG(encodingname) \ 
    181183    || PARROT_ASSERT_ARG(encoding) 
    182184#define ASSERT_ARGS_parrot_deinit_encodings __attribute__unused__ int _ASSERT_ARGS_CHECK = 0 
    183 #define ASSERT_ARGS_parrot_init_encodings_2 __attribute__unused__ int _ASSERT_ARGS_CHECK = 0 
     185#define ASSERT_ARGS_Parrot_str_internal_register_encoding_names \ 
     186     __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
     187       PARROT_ASSERT_ARG(interp) 
    184188/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */ 
    185189/* HEADERIZER END: src/string/encoding.c */ 
    186190 
  • include/parrot/string_funcs.h

    diff --git a/include/parrot/string_funcs.h b/include/parrot/string_funcs.h
    index 8dccd81..96dbe1c 100644
    a b  
    298298    ARGIN_NULLOK(const char *buffer), 
    299299    UINTVAL len, 
    300300    ARGIN(const ENCODING *encoding), 
    301     ARGIN_NULLOK(const CHARSET *charset), 
     301    ARGIN(const CHARSET *charset), 
    302302    UINTVAL flags) 
    303303        __attribute__nonnull__(1) 
    304         __attribute__nonnull__(4); 
     304        __attribute__nonnull__(4) 
     305        __attribute__nonnull__(5); 
    305306 
    306307PARROT_EXPORT 
    307308PARROT_CANNOT_RETURN_NULL 
     
    638639    || PARROT_ASSERT_ARG(s) 
    639640#define ASSERT_ARGS_Parrot_str_new_init __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
    640641       PARROT_ASSERT_ARG(interp) \ 
    641     || PARROT_ASSERT_ARG(encoding) 
     642    || PARROT_ASSERT_ARG(encoding) \ 
     643    || PARROT_ASSERT_ARG(charset) 
    642644#define ASSERT_ARGS_Parrot_str_new_noinit __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
    643645       PARROT_ASSERT_ARG(interp) 
    644646#define ASSERT_ARGS_Parrot_str_not_equal __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
  • src/string/api.c

    diff --git a/src/string/api.c b/src/string/api.c
    index e87b87a..57a6397 100644
    a b  
    762762PARROT_CANNOT_RETURN_NULL 
    763763STRING * 
    764764Parrot_str_new_init(PARROT_INTERP, ARGIN_NULLOK(const char *buffer), UINTVAL len, 
    765         ARGIN(const ENCODING *encoding), ARGIN_NULLOK(const CHARSET *charset), UINTVAL flags) 
     765        ARGIN(const ENCODING *encoding), ARGIN(const CHARSET *charset), UINTVAL flags) 
    766766{ 
    767767    ASSERT_ARGS(Parrot_str_new_init) 
    768768    DECL_CONST_CAST; 
  • src/string/charset.c

    diff --git a/src/string/charset.c b/src/string/charset.c
    index 4a25e6d..c9ad004 100644
    a b  
    6363/* HEADERIZER BEGIN: static */ 
    6464/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */ 
    6565 
     66static void Parrot_str_internal_register_charset_names(PARROT_INTERP) 
     67        __attribute__nonnull__(1); 
     68 
    6669static INTVAL register_charset(PARROT_INTERP, 
    6770    ARGIN(const char *charsetname), 
    6871    ARGIN(CHARSET *charset)) 
     
    7376static void register_static_converters(PARROT_INTERP) 
    7477        __attribute__nonnull__(1); 
    7578 
     79#define ASSERT_ARGS_Parrot_str_internal_register_charset_names \ 
     80     __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
     81       PARROT_ASSERT_ARG(interp) 
    7682#define ASSERT_ARGS_register_charset __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 
    7783       PARROT_ASSERT_ARG(interp) \ 
    7884    || PARROT_ASSERT_ARG(charsetname) \ 
     
    340346                (n + 1) * sizeof (One_charset)); 
    341347    all_charsets->n_charsets++; 
    342348    all_charsets->set[n].charset = charset; 
    343     all_charsets->set[n].name = Parrot_str_new_constant(interp, charsetname); 
    344349    all_charsets->set[n].n_converters = 0; 
    345350 
    346351    return 1; 
     
    348353 
    349354/* 
    350355 
     356=item C<static void Parrot_str_internal_register_charset_names> 
     357 
     358Helper function for initializing characterset names. We can't create the 
     359STRING names until the default encodings and charsets are already initted, 
     360so the name generation is split into a second init stage. 
     361 
     362=cut 
     363 
     364*/ 
     365 
     366static void 
     367Parrot_str_internal_register_charset_names(PARROT_INTERP) 
     368{ 
     369    ASSERT_ARGS(Parrot_str_internal_register_charset_names) 
     370    int n; 
     371    for (n = 0; n < all_charsets->n_charsets; n++) 
     372        all_charsets->set[n].name = 
     373            Parrot_str_new_constant(interp, all_charsets->set[n].charset->name); 
     374} 
     375 
     376/* 
     377 
    351378=item C<static void register_static_converters> 
    352379 
    353380Registers several standard converters between common charsets, including: 
     
    462489    Parrot_charset_binary_init(interp); 
    463490    Parrot_charset_unicode_init(interp); 
    464491 
    465     /* 
    466      * now encoding strings don't have a charset yet - set default 
     492    /* Now that the plugins are registered, we can create STRING 
     493     * names for them. 
    467494     */ 
    468     parrot_init_encodings_2(); 
     495    Parrot_str_internal_register_encoding_names(interp); 
     496    Parrot_str_internal_register_charset_names(interp); 
     497 
    469498    /* 
    470499     * now install charset converters 
    471500     */ 
  • src/string/encoding.c

    diff --git a/src/string/encoding.c b/src/string/encoding.c
    index 425d687..b2f95ff 100644
    a b  
    5858 
    5959/* 
    6060 
    61 =item C<void parrot_init_encodings_2> 
    62  
    63 Helper function for initializing characterset encodings. Initializes the 
    64 C<all_encodings> array. 
    65  
    66 =cut 
    67  
    68 */ 
    69  
    70 void 
    71 parrot_init_encodings_2(void) 
    72 { 
    73     ASSERT_ARGS(parrot_init_encodings_2) 
    74     const int n = all_encodings->n_encodings; 
    75     int i; 
    76  
    77     for (i = 0; i < n; ++i) { 
    78         all_encodings->enc[i].name->charset = Parrot_default_charset_ptr; 
    79     } 
    80 } 
    81  
    82 /* 
    83  
    8461=item C<void parrot_deinit_encodings> 
    8562 
    8663Deinitialize encodings and free all memory used by them. 
     
    338315                (n + 1) * sizeof (One_encoding)); 
    339316    all_encodings->n_encodings++; 
    340317    all_encodings->enc[n].encoding = encoding; 
    341     all_encodings->enc[n].name = Parrot_str_new_constant(interp, encodingname); 
    342318 
    343319    return 1; 
    344320} 
    345321 
    346322/* 
    347323 
     324=item C<void Parrot_str_internal_register_encoding_names> 
     325 
     326Helper function for initializing characterset encoding names. We can't create 
     327the STRING names until the default encodings and charsets are already initted, 
     328so the name generation is split into a second init stage. 
     329 
     330=cut 
     331 
     332*/ 
     333 
     334 
     335void 
     336Parrot_str_internal_register_encoding_names(PARROT_INTERP) 
     337{ 
     338    ASSERT_ARGS(Parrot_str_internal_register_encoding_names) 
     339    int n; 
     340    for (n = 0; n < all_encodings->n_encodings; n++) 
     341        all_encodings->enc[n].name = 
     342            Parrot_str_new_constant(interp, all_encodings->enc[n].encoding->name); 
     343} 
     344 
     345/* 
     346 
    348347=item C<INTVAL Parrot_register_encoding> 
    349348 
    350349Registers a character encoding C<encoding> with name C<encodingname>.