Changeset d1b1cf6 for perlconfig.c


Ignore:
Timestamp:
Aug 28, 2009, 12:09:07 AM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
ec21c62
Parents:
0571c30
git-author:
Nelson Elhage <nelhage@mit.edu> (08/26/09 23:49:26)
git-committer:
Nelson Elhage <nelhage@mit.edu> (08/28/09 00:09:07)
Message:
Set the UTF-8 flag on on strings we pass to Perl.

Add an owl_new_sv helper function that validates a string as UTF-8 and
turns it into an SV with the UTF-8 flag set, and use it everywhere in
preference to newSVpv.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perlconfig.c

    rdbe8729 rd1b1cf6  
    2222}
    2323
     24
     25SV *owl_new_sv(const char * str)
     26{
     27  SV *ret = newSVpv(str, 0);
     28  if(is_utf8_string(str, strlen(str))) {
     29    SvUTF8_on(ret);
     30  } else {
     31    owl_function_error("Internal error! Non-UTF-8 string encountered:\n%s", str);
     32  }
     33  return ret;
     34}
     35
    2436SV *owl_perlconfig_message2hashref(const owl_message *m)
    2537{
     
    4254
    4355#define MSG2H(h,field) (void)hv_store(h, #field, strlen(#field),        \
    44                                       newSVpv(owl_message_get_##field(m),0), 0)
     56                                      owl_new_sv(owl_message_get_##field(m)), 0)
    4557
    4658  if (owl_message_is_type_zephyr(m)
     
    5365    for (i=0; i<j; i++) {
    5466      ptr=owl_zephyr_get_field_as_utf8(owl_message_get_notice(m), i+1);
    55       av_push(av_zfields, newSVpvn(ptr, strlen(ptr)));
     67      av_push(av_zfields, owl_new_sv(ptr));
    5668      owl_free(ptr);
    5769    }
     
    5971
    6072    (void)hv_store(h, "auth", strlen("auth"),
    61                    newSVpv(owl_zephyr_get_authstr(owl_message_get_notice(m)),0),0);
     73                   owl_new_sv(owl_zephyr_get_authstr(owl_message_get_notice(m))),0);
    6274  }
    6375
     
    6678    pair=owl_list_get_element(&(m->attributes), i);
    6779    (void)hv_store(h, owl_pair_get_key(pair), strlen(owl_pair_get_key(pair)),
    68                    newSVpv(owl_pair_get_value(pair),0),0);
     80                   owl_new_sv(owl_pair_get_value(pair)),0);
    6981  }
    7082 
     
    8597    MSG2H(h, header);
    8698  }
    87   (void)hv_store(h, "time", strlen("time"), newSVpv(owl_message_get_timestr(m),0),0);
     99  (void)hv_store(h, "time", strlen("time"), owl_new_sv(owl_message_get_timestr(m)),0);
    88100  (void)hv_store(h, "unix_time", strlen("unix_time"), newSViv(m->time), 0);
    89101  (void)hv_store(h, "id", strlen("id"), newSViv(owl_message_get_id(m)),0);
     
    261273  XPUSHs(sv_2mortal(msgref));
    262274  for(i=0;i<argc;i++) {
    263     XPUSHs(sv_2mortal(newSVpv(argv[i], 0)));
     275    XPUSHs(sv_2mortal(owl_new_sv(argv[i])));
    264276  }
    265277  PUTBACK;
     
    352364  path = owl_sprintf("%s/lib", owl_get_datadir());
    353365  av_unshift(inc, 1);
    354   av_store(inc, 0, newSVpv(path, 0));
     366  av_store(inc, 0, owl_new_sv(path));
    355367  owl_free(path);
    356368
     
    437449
    438450  PUSHMARK(SP);
    439   XPUSHs(sv_2mortal(newSVpv(name, 0)));
     451  XPUSHs(sv_2mortal(owl_new_sv(name)));
    440452  PUTBACK;
    441453
     
    464476  PUSHMARK(SP);
    465477  for(i=0;i<argc;i++) {
    466     SV *tmp = newSVpv(argv[i], 0);
    467     SvUTF8_on(tmp);
    468     XPUSHs(sv_2mortal(tmp));
     478    XPUSHs(sv_2mortal(owl_new_sv(argv[i])));
    469479  }
    470480  PUTBACK;
     
    512522    owl_function_error("Perl callback is NULL!");
    513523  }
    514   text = newSVpv(owl_editwin_get_text(e), 0);
    515   SvUTF8_on(text);
     524  text = owl_new_sv(owl_editwin_get_text(e));
    516525
    517526  ENTER;
Note: See TracChangeset for help on using the changeset viewer.