Changeset ce68f23


Ignore:
Timestamp:
Jun 25, 2011, 3:26:16 AM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
c266281
Parents:
3cdd6d2
git-author:
David Benjamin <davidben@mit.edu> (06/11/11 20:06:46)
git-committer:
David Benjamin <davidben@mit.edu> (06/25/11 03:26:16)
Message:
Make owl_dict_get_keys return a GPtrArray

Almost all the remaining uses of owl_list are tightly coupled into this
one giant blob.
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • cmd.c

    r6829afc rce68f23  
    2828}
    2929
    30 void owl_cmddict_get_names(const owl_cmddict *d, owl_list *l) {
    31   owl_dict_get_keys(d, l);
     30GPtrArray *owl_cmddict_get_names(const owl_cmddict *d) {
     31  return owl_dict_get_keys(d);
    3232}
    3333
  • dict.c

    r6829afc rce68f23  
    5656}
    5757
    58 /* Appends dictionary keys to a list.  Duplicates the keys,
    59  * so they will need to be freed by the caller. */
    60 void owl_dict_get_keys(const owl_dict *d, owl_list *l) {
     58/* Returns a GPtrArray of dictionary keys. Duplicates the keys, so
     59 * they will need to be freed by the caller with g_free. */
     60CALLER_OWN GPtrArray *owl_dict_get_keys(const owl_dict *d) {
     61  GPtrArray *keys = g_ptr_array_sized_new(d->size);
    6162  int i;
    62   for (i=0; i<d->size; i++) {
    63     owl_list_append_element(l, g_strdup(d->els[i].k));
     63  for (i = 0; i < d->size; i++) {
     64    g_ptr_array_add(keys, g_strdup(d->els[i].k));
    6465  }
     66  return keys;
    6567}
    6668
  • fmtext.c

    r6829afc rce68f23  
    755755 * If format_fn is specified, passes it the list element value
    756756 * and it will return a string which this needs to free. */
    757 void owl_fmtext_append_list(owl_fmtext *f, const owl_list *l, const char *join_with, char *(format_fn)(const char *))
    758 {
    759   int i, size;
     757void owl_fmtext_append_list(owl_fmtext *f, const GPtrArray *l, const char *join_with, char *(format_fn)(const char *))
     758{
     759  int i;
    760760  const char *elem;
    761761  char *text;
    762762
    763   size = owl_list_get_size(l);
    764   for (i=0; i<size; i++) {
    765     elem = owl_list_get_element(l,i);
     763  for (i = 0; i < l->len; i++) {
     764    elem = l->pdata[i];
    766765    if (elem && format_fn) {
    767766      text = format_fn(elem);
     
    773772      owl_fmtext_append_normal(f, elem);
    774773    }
    775     if ((i < size-1) && join_with) {
     774    if ((i < l->len - 1) && join_with) {
    776775      owl_fmtext_append_normal(f, join_with);
    777776    }
  • functions.c

    r3cdd6d2 rce68f23  
    4747void owl_function_show_commands(void)
    4848{
    49   owl_list l;
     49  GPtrArray *l;
    5050  owl_fmtext fm;
    5151
     
    5353  owl_fmtext_append_bold(&fm, "Commands:  ");
    5454  owl_fmtext_append_normal(&fm, "(use 'show command <name>' for details)\n");
    55   owl_list_create(&l);
    56   owl_cmddict_get_names(owl_global_get_cmddict(&g), &l);
    57   owl_fmtext_append_list(&fm, &l, "\n", owl_function_cmd_describe);
     55  l = owl_cmddict_get_names(owl_global_get_cmddict(&g));
     56  owl_fmtext_append_list(&fm, l, "\n", owl_function_cmd_describe);
    5857  owl_fmtext_append_normal(&fm, "\n");
    5958  owl_function_popless_fmtext(&fm);
    60   owl_list_cleanup(&l, g_free);
     59  owl_ptr_array_free(l, g_free);
    6160  owl_fmtext_cleanup(&fm);
    6261}
     
    8180
    8281void owl_function_show_styles(void) {
    83   owl_list l;
     82  GPtrArray *l;
    8483  owl_fmtext fm;
    8584
    8685  owl_fmtext_init_null(&fm);
    8786  owl_fmtext_append_bold(&fm, "Styles:\n");
    88   owl_list_create(&l);
    89   owl_global_get_style_names(&g, &l);
    90   owl_fmtext_append_list(&fm, &l, "\n", owl_function_style_describe);
     87  l = owl_global_get_style_names(&g);
     88  owl_fmtext_append_list(&fm, l, "\n", owl_function_style_describe);
    9189  owl_fmtext_append_normal(&fm, "\n");
    9290  owl_function_popless_fmtext(&fm);
    93   owl_list_cleanup(&l, g_free);
     91  owl_ptr_array_free(l, g_free);
    9492  owl_fmtext_cleanup(&fm);
    9593}
     
    15761574  const char *name;
    15771575  char *var;
    1578   owl_list varnames;
    1579   int i, numvarnames;
     1576  GPtrArray *varnames;
     1577  int i;
    15801578  GString *str   = g_string_new("");
    15811579
    15821580  g_string_append_printf(str, "%-20s = %s\n", "VARIABLE", "VALUE");
    15831581  g_string_append_printf(str, "%-20s   %s\n",  "--------", "-----");
    1584   owl_list_create(&varnames);
    1585   owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
    1586   numvarnames = owl_list_get_size(&varnames);
    1587   for (i=0; i<numvarnames; i++) {
    1588     name = owl_list_get_element(&varnames, i);
     1582  varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g));
     1583  for (i = 0; i < varnames->len; i++) {
     1584    name = varnames->pdata[i];
    15891585    if (name && name[0]!='_') {
    15901586      g_string_append_printf(str, "\n%-20s = ", name);
     
    15971593  }
    15981594  g_string_append(str, "\n");
    1599   owl_list_cleanup(&varnames, g_free);
     1595  owl_ptr_array_free(varnames, g_free);
    16001596
    16011597  owl_function_popless_text(str->str);
     
    16051601void owl_function_show_variables(void)
    16061602{
    1607   owl_list varnames;
     1603  GPtrArray *varnames;
    16081604  owl_fmtext fm; 
    1609   int i, numvarnames;
     1605  int i;
    16101606  const char *varname;
    16111607
     
    16131609  owl_fmtext_append_bold(&fm,
    16141610      "Variables: (use 'show variable <name>' for details)\n");
    1615   owl_list_create(&varnames);
    1616   owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
    1617   numvarnames = owl_list_get_size(&varnames);
    1618   for (i=0; i<numvarnames; i++) {
    1619     varname = owl_list_get_element(&varnames, i);
     1611  varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g));
     1612  for (i = 0; i < varnames->len; i++) {
     1613    varname = varnames->pdata[i];
    16201614    if (varname && varname[0]!='_') {
    16211615      owl_variable_describe(owl_global_get_vardict(&g), varname, &fm);
    16221616    }
    16231617  }
    1624   owl_list_cleanup(&varnames, g_free);
     1618  owl_ptr_array_free(varnames, g_free);
    16251619  owl_function_popless_fmtext(&fm);
    16261620  owl_fmtext_cleanup(&fm);
     
    28262820void owl_function_show_keymaps(void)
    28272821{
    2828   owl_list l;
     2822  GPtrArray *l;
    28292823  owl_fmtext fm;
    28302824  const owl_keymap *km;
    28312825  const owl_keyhandler *kh;
    2832   int i, numkm;
     2826  int i;
    28332827  const char *kmname;
    28342828
     
    28372831  owl_fmtext_append_bold(&fm, "Keymaps:   ");
    28382832  owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n");
    2839   owl_list_create(&l);
    2840   owl_keyhandler_get_keymap_names(kh, &l);
    2841   owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary);
     2833  l = owl_keyhandler_get_keymap_names(kh);
     2834  owl_fmtext_append_list(&fm, l, "\n", owl_function_keymap_summary);
    28422835  owl_fmtext_append_normal(&fm, "\n");
    28432836
    2844   numkm = owl_list_get_size(&l);
    2845   for (i=0; i<numkm; i++) {
    2846     kmname = owl_list_get_element(&l, i);
     2837  for (i = 0; i < l->len; i++) {
     2838    kmname = l->pdata[i];
    28472839    km = owl_keyhandler_get_keymap(kh, kmname);
    28482840    owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n");
     
    28522844 
    28532845  owl_function_popless_fmtext(&fm);
    2854   owl_list_cleanup(&l, g_free);
     2846  owl_ptr_array_free(l, g_free);
    28552847  owl_fmtext_cleanup(&fm);
    28562848}
  • global.c

    re6d7e4e rce68f23  
    753753}
    754754
    755 void owl_global_get_style_names(const owl_global *g, owl_list *l) {
    756   owl_dict_get_keys(&(g->styledict), l);
     755CALLER_OWN GPtrArray *owl_global_get_style_names(const owl_global *g)
     756{
     757  return owl_dict_get_keys(&g->styledict);
    757758}
    758759
  • help.c

    rf25df21 rce68f23  
    66  owl_fmtext fm;
    77  const char *varname;
    8   owl_list varnames;
    9   int i, numvarnames;
     8  GPtrArray *varnames;
     9  int i;
    1010
    1111  owl_fmtext_init_null(&fm);
     
    129129  owl_fmtext_append_bold(&fm,
    130130                         "Variables:\n");
    131   owl_list_create(&varnames);
    132   owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
    133   numvarnames = owl_list_get_size(&varnames);
    134   for (i=0; i<numvarnames; i++) {
    135     varname = owl_list_get_element(&varnames, i);
     131  varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g));
     132  for (i = 0; i < varnames->len; i++) {
     133    varname = varnames->pdata[i];
    136134    if (varname && varname[0]!='_') {
    137135      owl_variable_describe(owl_global_get_vardict(&g), varname, &fm);
    138136    }
    139137  }
    140   owl_list_cleanup(&varnames, g_free);
     138  owl_ptr_array_free(varnames, g_free);
    141139
    142140  owl_fmtext_append_normal(&fm, "\n");
  • keymap.c

    r3cdd6d2 rce68f23  
    209209}
    210210
    211 void owl_keyhandler_get_keymap_names(const owl_keyhandler *kh, owl_list *l)
    212 {
    213   owl_dict_get_keys(&kh->keymaps, l);
     211CALLER_OWN GPtrArray *owl_keyhandler_get_keymap_names(const owl_keyhandler *kh)
     212{
     213  return owl_dict_get_keys(&kh->keymaps);
    214214}
    215215
  • perlconfig.c

    rf9df2f0 rce68f23  
    3636}
    3737
    38 CALLER_OWN AV *owl_new_av(const owl_list *l, SV *(*to_sv)(const void *))
     38CALLER_OWN AV *owl_new_av(const GPtrArray *l, SV *(*to_sv)(const void *))
    3939{
    4040  AV *ret;
     
    4444  ret = newAV();
    4545
    46   for (i = 0; i < owl_list_get_size(l); i++) {
    47     element = owl_list_get_element(l, i);
     46  for (i = 0; i < l->len; i++) {
     47    element = l->pdata[i];
    4848    av_push(ret, to_sv(element));
    4949  }
     
    5555{
    5656  HV *ret;
    57   owl_list l;
     57  GPtrArray *keys;
    5858  const char *key;
    5959  void *element;
     
    6363
    6464  /* TODO: add an iterator-like interface to owl_dict */
    65   owl_list_create(&l);
    66   owl_dict_get_keys(d, &l);
    67   for (i = 0; i < owl_list_get_size(&l); i++) {
    68     key = owl_list_get_element(&l, i);
     65  keys = owl_dict_get_keys(d);
     66  for (i = 0; i < keys->len; i++) {
     67    key = keys->pdata[i];
    6968    element = owl_dict_find_element(d, key);
    7069    (void)hv_store(ret, key, strlen(key), to_sv(element), 0);
    7170  }
    72   owl_list_cleanup(&l, g_free);
     71  owl_ptr_array_free(keys, g_free);
    7372
    7473  return ret;
  • perlglue.xs

    rbcde7926 rce68f23  
    329329all_filters()
    330330        PREINIT:
    331                 owl_list fl;
    332         CODE:
    333         {
    334                 owl_list_create(&fl);
    335                 owl_dict_get_keys(&g.filters, &fl);
    336                 RETVAL = owl_new_av(&fl, (SV*(*)(const void*))owl_new_sv);
     331                GPtrArray *fl;
     332        CODE:
     333        {
     334                fl = owl_dict_get_keys(&g.filters);
     335                RETVAL = owl_new_av(fl, (SV*(*)(const void*))owl_new_sv);
    337336                sv_2mortal((SV*)RETVAL);
    338                 owl_list_cleanup(&fl, g_free);
     337                owl_ptr_array_free(fl, g_free);
    339338        }
    340339        OUTPUT:
     
    344343all_styles()
    345344        PREINIT:
    346                 owl_list l;
    347         CODE:
    348         {
    349                 owl_list_create(&l);
    350                 owl_global_get_style_names(&g, &l);
    351                 RETVAL = owl_new_av(&l, (SV*(*)(const void*))owl_new_sv);
     345                GPtrArray *l;
     346        CODE:
     347        {
     348                l = owl_global_get_style_names(&g);
     349                RETVAL = owl_new_av(l, (SV*(*)(const void*))owl_new_sv);
    352350                sv_2mortal((SV*)RETVAL);
    353351        }
     
    355353                RETVAL
    356354        CLEANUP:
    357                 owl_list_cleanup(&l, g_free);
     355                owl_ptr_array_free(l, g_free);
    358356
    359357
     
    361359all_variables()
    362360        PREINIT:
    363                 owl_list l;
    364         CODE:
    365         {
    366                 owl_list_create(&l);
    367                 owl_dict_get_keys(owl_global_get_vardict(&g), &l);
    368                 RETVAL = owl_new_av(&l, (SV*(*)(const void*))owl_new_sv);
     361                GPtrArray *l;
     362        CODE:
     363        {
     364                l = owl_dict_get_keys(owl_global_get_vardict(&g));
     365                RETVAL = owl_new_av(l, (SV*(*)(const void*))owl_new_sv);
    369366                sv_2mortal((SV*)RETVAL);
    370367        }
     
    372369                RETVAL
    373370        CLEANUP:
    374                 owl_list_cleanup(&l, g_free);
     371                owl_ptr_array_free(l, g_free);
    375372
    376373
     
    378375all_keymaps()
    379376        PREINIT:
    380                 owl_list l;
     377                GPtrArray *l;
    381378                const owl_keyhandler *kh;
    382379        CODE:
    383380        {
    384381                kh = owl_global_get_keyhandler(&g);
    385                 owl_list_create(&l);
    386                 owl_keyhandler_get_keymap_names(kh, &l);
    387                 RETVAL = owl_new_av(&l, (SV*(*)(const void*))owl_new_sv);
     382                l = owl_keyhandler_get_keymap_names(kh);
     383                RETVAL = owl_new_av(l, (SV*(*)(const void*))owl_new_sv);
    388384                sv_2mortal((SV*)RETVAL);
    389385        }
     
    391387                RETVAL
    392388        CLEANUP:
    393                 owl_list_cleanup(&l, g_free);
     389                owl_ptr_array_free(l, g_free);
    394390
    395391void
  • tester.c

    r4e37d56 rce68f23  
    230230int owl_dict_regtest(void) {
    231231  owl_dict d;
    232   owl_list l;
     232  GPtrArray *l;
    233233  int numfailed=0;
    234234  char *av = g_strdup("aval"), *bv = g_strdup("bval"), *cv = g_strdup("cval"),
     
    251251
    252252  FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d));
    253   owl_list_create(&l);
    254   owl_dict_get_keys(&d, &l);
    255   FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l));
     253  l = owl_dict_get_keys(&d);
     254  FAIL_UNLESS("get_keys result size", 3 == l->len);
    256255 
    257256  /* these assume the returned keys are sorted */
    258   FAIL_UNLESS("get_keys result val",0==strcmp("a",owl_list_get_element(&l,0)));
    259   FAIL_UNLESS("get_keys result val",0==strcmp("b",owl_list_get_element(&l,1)));
    260   FAIL_UNLESS("get_keys result val",0==strcmp("c",owl_list_get_element(&l,2)));
    261 
    262   owl_list_cleanup(&l, g_free);
     257  FAIL_UNLESS("get_keys result val", 0 == strcmp("a", l->pdata[0]));
     258  FAIL_UNLESS("get_keys result val", 0 == strcmp("b", l->pdata[1]));
     259  FAIL_UNLESS("get_keys result val", 0 == strcmp("c", l->pdata[2]));
     260
     261  owl_ptr_array_free(l, g_free);
    263262  owl_dict_cleanup(&d, NULL);
    264263
  • variable.c

    r6829afc rce68f23  
    729729}
    730730
    731 void owl_variable_dict_get_names(const owl_vardict *d, owl_list *l) {
    732   owl_dict_get_keys(d, l);
     731CALLER_OWN GPtrArray *owl_variable_dict_get_names(const owl_vardict *d) {
     732  return owl_dict_get_keys(d);
    733733}
    734734
Note: See TracChangeset for help on using the changeset viewer.