in reply to Re^3: Memory Leak with XS but not pure C
in thread Memory Leak with XS but not pure C

yeah your are right

. This will be part of a bigger XS thing. Is there a macro I can use for uppercasing?
  • Comment on Re^4: Memory Leak with XS but not pure C

Replies are listed 'Best First'.
Re^5: Memory Leak with XS but not pure C
by NERDVANA (Priest) on Mar 31, 2025 at 16:49 UTC

    Actually I ran into this problem with my Tree::RB::XS module when I wanted to case-fold the keys. The 'uc' operator doesn't have a clean alternative C API available. There are API calls for single characters like 'toUPPER_utf8' but I didn't dig enough to find out if there's a robust way to call this in a loop for all the different versions of perl. The implementation of the uc operator (grep for "pp_uc" in pp.c) has a bunch of ifdef conditionals which have probably changed a lot over the years.

    Since I want to support back to 5.8, I decided to just call out to the perl function with call_pv("CORE::fc", G_SCALAR);. But, as the nearby comments mention, before perl 5.16 that wasn't a function so I needed to wrap the op with a function as sub _fc_impl { lc shift } and then call that.

    Since calling perl functions is a decent bit of overhead, if you need this to run in a hot code path you might still be better off with your external unicode library. Or, if you want to avoid that dependency and stick to recent versions of perl you could just copy/paste most of the pp_uc implementation into your own function and call that (but careful with copyrights there).

    And... um... if you get a reasonably robust version made with the perl API, I'd love to improve the performance of Tree::RB::XS :-)

      OK seems there is no simple way

      cheers!