鸡蛋炒什么菜好吃| 水果的英文是什么| 女人喝什么茶叶最好| 女人为什么喜欢坏男人| 六月初九是什么日子| 吃什么能补蛋白| 克罗恩病吃什么药| 发际线是什么| 心脏做造影是什么意思| 检查耳朵挂什么科| 6月8日是什么星座| 痔疮疼痛用什么药| 下巴长痘痘是什么原因| 循环利息是什么意思| 耳朵大代表什么| 万象更新是什么生肖| 阴唇痒用什么药| 后脑勺发热是什么原因| 蘑菇炒什么好吃| 拔凉拔凉是什么意思| 鸡汤放什么调料| 总恶心是什么病的前兆| 优甲乐过量有什么症状| 喝茶叶有什么好处| 空虚什么意思| 宝宝尿少是什么原因| 吃什么补阳气最快| 谷丙转氨酶是检查什么的| 何方珠宝是什么档次| 烁字五行属什么| 人巨细胞病毒是什么病| dl是什么意思| 是什么单位| 西洋参什么季节吃最好| 小孩吐奶是什么原因| 蝙蝠是什么变的| 忠厚是什么意思| lcc是什么意思| 嘴唇一圈发黑是什么原因造成的| 梦见别人杀人是什么预兆| 黄精有什么作用| 什么药止痒效果最好| 痛风什么东西不可以吃| 扁平足是什么意思| 什么是音节什么是音序| 4月14日是什么星座| prince是什么牌子| 血府逐瘀片主治什么病| 悬壶济世是什么意思| 孕妇梦见狗是什么意思| hpv低危型是什么意思| wing什么意思| 儿童办护照需要什么证件| 纵横四海是什么意思| 彩色多普勒超声检查是什么| 梦见自己生男孩是什么意思| 腹肌不对称是什么原因| 什么虎不吃人| 脓包疮用什么药| 酒糟鼻子是什么原因引起的| 左肺上叶钙化灶什么意思| 血糖高是什么原因造成的| 祛火喝什么茶| skll什么牌子| 三个土叫什么| 生化妊娠是什么意思| 什么是抗生素类药物| 9点半是什么时辰| 升米恩斗米仇是什么意思| 云吞面是什么面| 女人肝胆湿热吃什么药| crp高是什么感染| 日照香炉生紫烟的香炉是什么意思| 感冒打喷嚏吃什么药| 香油是什么| 持续高烧不退是什么原因| 什么叫早教| 梦见两条蛇是什么预兆| 益生菌对人体有什么好处| 社论是什么| 勾芡用什么淀粉| 不动明王是什么属相的本命佛| 托孤是什么意思| 肠道消炎用什么药最好| 清末民初是什么时候| 学生是什么阶级| 慈母手中线的下一句是什么| 小分子肽能治什么病| 买车置换是什么意思| 鲭鱼是什么鱼| 荒淫无度是什么意思| 农田种什么最赚钱| 喜结连理是什么意思| 眼睛干涩吃什么食物好| 3月16是什么星座| 吃什么补记忆力最快| 苏铁属于什么植物| 木薯粉是什么做的| 金丝玉是什么玉| 锋芒的意思是什么| 酵母菌属于什么菌| 11月5号什么星座| 子宫肥大有什么危害| 牙疼吃什么水果| 舌头有裂纹是什么原因| 双肾小结石是什么意思| 促甲状腺激素低是什么原因| 龙和什么生肖最配| 什么是化学性肝损伤| 香蕉皮擦脸有什么作用与功效| 对峙是什么意思| 看淋巴挂什么科室| 铁皮石斛花有什么作用| 二次元是什么| 彩铃是什么意思| 苹果绿是什么颜色| 排卵期有什么症状| 乳头状瘤是什么病| 溃疡性结肠炎有什么症状| 梅雨是什么| 什么茶降血脂最好| 测尿酸挂什么科| 鼻屎有臭味是什么原因| 五十岁是什么之年| 阴虱卵长什么样图片| bug是什么意思中文翻译| 大蒜吃多了有什么坏处| 什么鸟叫声最好听| 皮下水肿是什么原因| doki是什么意思| 2017年五行属什么| 头晕眼花是什么原因| 在干什么| 山竹和什么不能一起吃| 肾结水有什么危害| 肉刺长什么样子图片| 什么肉是碱性的| 拔牙后吃什么食物| 指甲挂什么科| 孔雀为什么会开屏| 宝宝吃什么辅食最好| 法令纹上的痣代表什么| 金国是什么民族| 南辕北辙什么意思| 宫颈囊肿是什么原因| 基友什么意思| 八字刘海适合什么脸型| 梦见孩子结婚什么预兆| 西瓜不能和什么一起吃| 讣告什么意思| human什么意思| 赤什么意思| 肺结核挂什么科| 667什么意思| 运动员心率为什么慢| 乙型肝炎表面抗原阳性是什么意思| 先兆流产是什么原因| 猫传腹是什么| 白带发黄吃什么药| 孩子恶心想吐是什么原因| 静脉血栓有什么症状| 一什么秋千| 岳字五行属什么| 一热就咳嗽是什么原因| 安陵容为什么叫安小鸟| 做梦梦见死去的亲人是什么意思| 暗物质和暗能量是什么| 蜂蜜为什么会结晶| 偶数和奇数是什么意思| 高血糖吃什么药| 水是由什么构成的| 轴位什么意思| 脚气用什么药膏效果好| 什么蘑菇| 泡饭为什么对胃不好| 高血压的人不能吃什么| 妊娠线什么时候长| 夫妻肺片里面都有什么| 开市是什么意思| 肉馅可以做什么美食| 释迦摩尼是什么意思| 4月28日是什么日子| 铁扇公主是什么妖精| 长期拉肚子是什么原因| 鱼腥草治什么病| 什么是禽流感| 右下腹是什么器官| 多吃丝瓜有什么好处和坏处| 慢性咽炎用什么药| 尿液有泡沫什么原因| 高血糖能吃什么| 养性是什么意思| 阳萎吃什么药| 六味地黄丸有什么功效| 女人吃牛油果有什么好处| 心衰的症状是什么| dmc是什么意思| 加仓什么意思| 天子是什么生肖| 跳槽是什么意思| 胎儿生物物理评分8分什么意思| 血管炎症状表现是什么| 吃太烫的东西有什么坏处| 狗头军师什么意思| 狗肉炖什么好吃| 口臭是什么原因引起| joy什么意思| 抖腿是什么原因| 县里的局长是什么级别| 女生爱出汗是什么原因| 欧芹在中国叫什么| 拧巴什么意思| 很黄很暴力是什么意思| 宫颈糜烂有什么症状和现象| 灵芝主要治什么病| 谷草谷丙是什么| 比音勒芬是什么档次| 宿醉是什么意思| 黑枸杞和什么一起泡水喝比较好| 耳朵里长痘是什么原因| 98年属什么| 信徒是什么意思| napoleon是什么酒| 梦见很多人是什么意思| 天地不仁以万物为刍狗什么意思| ph值高是什么原因| 煤气是什么味道| 木鱼花是什么做的| 白血球低吃什么补得快| 后脖子出汗多是什么原因| 大便不成型吃什么药| 心肌供血不足吃什么| 猫的胡子有什么作用| 十月初八是什么星座| 曲克芦丁片治什么病| 周围神经病是什么病| ra是什么| 容易出汗是什么问题| 98年一月属什么生肖| 想吃辣是身体缺乏什么| 类风湿关节炎不能吃什么食物| 怀孕了挂什么科| 玛咖是什么| 八十岁是什么之年| 贵人是什么意思| 一如既往的意思是什么| 白癜风不能吃什么| 发飙是什么意思| 被银环蛇咬了有什么症状| 市宣传部长是什么级别| 阑尾炎是什么症状| 脸部过敏红痒抹什么药| 检查怀没怀孕挂什么科| 花裤子配什么上衣| 疝是什么意思| 买什么化妆品好| 以什么当什么| 彪是什么动物| 为什么会脑梗| 爸爸的姐姐应该叫什么| 眼疲劳用什么眼药水| 什么的鼓励| 小厨宝是什么东西| 白带异常吃什么药| 百度 develooper Front page | perl.perl5.porters | Postings from August 2025

Re: New XS features?

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
August 2, 2025 13:47
Subject:
Re: New XS features?
Message ID:
aI4W6E1hnz_vZy0j@iabyn.com
On Sun, Jul 27, 2025 at 03:28:43AM +0200, Leon Timmermans wrote:
> Currently I'm experiencing two problems around strings that could use
> better solutions than what is currently available.
> 
> 1. The char pointer typemaps currently do not do SV_CHECK_THINK_FIRST,
> and hence can very easily mess up COW strings. But obviously should
> only do so selectively. Fortunately this scenario is probably uncommon
> (given one often has to resize or some such, one usually needs the
> full SV anyway).

So IIUC, the three use-cases seem to be:

1) get a char* pointer to a string buffer holding a string-representation
of the SV. This is for for read-only purposes. This is what XS is
currently geared up for, and works with any SV, including ints, COW,
overloaded refs etc etc.

2) get a char* pointer, and modify the bytes within it in-place, e.g. for
an uc()-like function. It wouldn't expand the size of the buffer. This
would superficially appear to work, but would corrupt COW strings, and
become a NOOP on the temporary buffers allocated for stringified refs etc.

3) A general string modification; e.g. append to the string.

I think (2) is a rare enough use that we don't need to support it, but we
should warn against it in the docs. And as you say, for (3) they
should be directly working with the SV anyway.

I'm not sure how well any of this works with OUT parameters:

    void uc(OUT char *s)
        CODE:
            /* modify s then update the passed arg with this value ?? */

This looks to be both modifying the passed arg's string buffer directly,
then assigning it back to the arg. So (2) but even wronger?

So my initial gut reaction is that XS doesn't need any new support for this,
but the docs should warn about what to do and not to do when updating
strings.

> 2. The char pointer typemaps predate unicode support, and therefore
> code using them has the unicode bug. One really needs to handle these
> separately (SvPVbyte versus SvPVutf8). Using two macro-redefines one
> can sort-of fix this for the whole module, but that becomes a problem
> when you need both kinds in the same module.
> 
> One approach out of this predicament would be to use separate typemaps
> for all these permutations. A major problem with that is that the
> length() feature is hardcoded to only work with the `T_PV` typemap.
> Making that work would probably require adding a new type of map
> handling input with length.
> 
> Another approach might be modifiers on the types (much like IN/OUT/…
> already exist nowadays). This feels more flexible (given that the
> above approach gives increasingly more permutations) but puts more
> weight on ParseXS.

So what sort of use cases would we want to support? For example, when
wrapping a library function which takes char* and STRLEN args, the
three options for the char* seem to be:

* SvPV(): chars with ord 0x80-0xff may be in either form: this is what XS
  currently uses.
* SvPVbyte(): croak on ord() > 0xff; downgrade 0x80-0xff to single byte.
* SvPVutf8(): upgrade 0x80-0xff to two bytes

and the two options for the STELEN arg seem to be number of bytes or
number of characters; this is potentially orthogonal to what the char* is;
fr example the function might expect a utf8-encoded buffer by still expect
the size of the buffer.

I could envision having optional BYTE and UTF8 parameter declaration
modifiers for both strings and length parameters, e.g.

    void
    foo(UTF8 char* s, BYTE int length(s))

Then, in the presence of a  modifier, append _BTYE or _UTF8 to
the typemap name. So for example with 

    void foo(UTF8 char *s)

the first stage of the typemap lookup will map 'char *' to T_PV. The XS
parser amends that to T_PV_UTF8, which is then looked up in the INPUT
section of the typemap, and croaks if not found. So the INPUT section
might have entries like:

    T_PV
        $var = ($type)SvPV_nolen($arg)
    T_PV_BYTE
        $var = ($type)SvPVbyte_nolen($arg)
    T_PV_UTF8
        $var = ($type)SvPVutf8_nolen($arg)

For something non-string like 

    void foo(BYTE int i)

it would try to lookup T_IV_BYTE and croak, as expected.

For length(s), we could expand the list of acceptable XS types for s from
just T_PV to add T_PV_BYTE, T_PV_UTF8 too.

length(s) could also have an optional BYTE/UTF8 modifier. The XS parser
would then decide whether length() refers to number of bytes or chars
based on both the s and length(s) modifiers. If the length has no
modifier, it's based on the modifier of the string; if length has a
modifier, then that's used. So for example

    void foo(UTF8 char *s, int length(s)) 

would cause the passed argument to be upgraded to utf8, and
XSauto_length_of_s would contain the number of chars in the buffer; while

    void foo(UTF8 char *s, BYTE int length(s)) 

would cause the passed argument to be upgraded to utf8, but XSauto_length_of_s
would contain the number of physical bytes in the buffer.

Would XS code or wrapped libraries ever need easy access to the SvUTf8()
flag, in a similar fashion to length()? E.g.

    void(char *s, int length(s), bool utf8(s))

I would expect that most of the time, the coder would be using an explicit
BYTE or UTF8 anyway, so the value of the utf8 flag would already be known.
So I suspect this wouldn't be useful?

I would expect these modifiers to come after the IN/OUT modifiers (as
they're kind of part of the type): e.g.

    void foo(OUT UTF8 char *s)

For a return value, e.g.

    UTF8 char*
    foo(...)

I guess it would look up a T_PV_UTF8 entry in the output section of
of the typemap, which might have entries like

T_PV
        sv_setpv((SV*)$arg, $var);
T_PV_UTF8
        sv_setpv((SV*)$arg, $var);
        SvUTF8_on((SV*)$arg);
T_PV_BYTE
        sv_setpv((SV*)$arg, $var);
        SvUTF8_off((SV*)$arg);


-- 
In England there is a special word which means the last sunshine
of the summer. That word is "spring".

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About
因果报应是什么意思 右眼睛跳是什么原因 什么是感情 任然什么意思 冰箱为什么不制冷了
腿老是抽筋是什么原因 多囊为什么要跳绳而不是跑步 莴笋炒什么好吃 麻风病是什么病 射手座是什么象星座
青蛙怕什么 金兰之交是什么意思 本命佛是什么意思 小孩肚子疼是什么原因引起的 透析是什么
什么呢 身体游走性疼痛什么病 左心室高电压是什么意思 枸杞不能和什么一起吃 眼睛发炎用什么眼药水
甲醛闻多了有什么症状hebeidezhi.com 山药跟淮山有什么区别hkuteam.com 江诗丹顿属于什么档次hcv8jop2ns2r.cn 吃什么补充蛋白wuhaiwuya.com 什么是股癣hcv9jop7ns4r.cn
乙肝五项145阳性是什么意思hcv8jop3ns5r.cn 乳腺癌有什么症状hcv9jop5ns4r.cn 爱被蚊子咬是什么原因hcv8jop5ns8r.cn 珍惜眼前人是什么意思hcv9jop1ns3r.cn 肺结节挂什么科室hcv8jop3ns1r.cn
肚子疼一般是什么原因hcv9jop2ns0r.cn 质问是什么意思啊hcv8jop2ns1r.cn 萎缩性胃炎吃什么药效果好hcv8jop4ns4r.cn 意外流产有什么症状hcv9jop8ns3r.cn 喉咙发炎吃什么食物hcv9jop2ns1r.cn
prp治疗是什么意思hcv9jop2ns1r.cn 口吐白沫是什么原因hcv8jop9ns5r.cn 螳螂捕蝉黄雀在后是什么生肖hcv7jop5ns6r.cn 小孩改姓需要什么手续hcv9jop3ns5r.cn 经常拉稀是什么原因hcv8jop0ns5r.cn
百度