Skip to content

Commit

Permalink
Avoid use of experimental bytes_to_utf8
Browse files Browse the repository at this point in the history
Not too sure about this one ... while bytes_to_utf8 is "experimental" according to perlapi, it isn't labelled as such in perlguts, which actually recommends using it for our exact scenario. bytes_to_utf8 was introduced in Perl 5.7.0, so it's been around like forever and it seems unlikely that it would suddenly vanish. And avoiding bytes_to_utf8 in the way this change does uses up more (temp) memory.

In spite of all that, using "experimental" functions seems like a bad idea to me.

newSVpvn_flags is available from Perl 5.10.1.
  • Loading branch information
johannessen committed Feb 22, 2021
1 parent 122a31b commit 8b706f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if ($neo_info) {
WriteMakefile(
NAME => 'Neo4j::Bolt',
VERSION_FROM => 'lib/Neo4j/Bolt.pm',
MIN_PERL_VERSION => '5.010',
MIN_PERL_VERSION => '5.010001',
CONFIGURE_REQUIRES => {
'Alien::OpenSSL' => 0,
'ExtUtils::MakeMaker' => '7.12',
Expand All @@ -67,7 +67,6 @@ WriteMakefile(
'Alien::OpenSSL' => 0,
'Neo4j::Client' => '0.46',
'Neo4j::Types' => '1.00',
'parent' => 0, # parent was first released with perl v5.10.1
'JSON::PP' => 0,
'URI' => 0,
'XSLoader' => '0.14', # XSLoader::load()
Expand Down
8 changes: 4 additions & 4 deletions lib/Neo4j/Bolt/CTypeHandlers.xs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ neo4j_value_t SVnv_to_neo4j_float (SV *sv) {
neo4j_value_t SVpv_to_neo4j_string (SV *sv) {
STRLEN len;
char *k0,*k;
SV *sv2;
k = SvPV(sv,len);
if (! SvUTF8(sv)) {
k0 = (char *) bytes_to_utf8((U8 *)k, &len);
return neo4j_ustring(k0, len);
}
// create duplicate to keep SvPVutf8 from changing the original SV
sv2 = newSVpvn_flags(k, len, SvFLAGS(sv) & SVf_UTF8 | SVs_TEMP);
k = SvPVutf8(sv2, len);
Newx(k0,len+1,char);
memcpy(k0,k,(size_t) len);
*(k0+len) = 0;
Expand Down

1 comment on commit 8b706f9

@johannessen
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn’t seem to have any measurable performance impact.

Please sign in to comment.