| 316 | |
| 317 | |
| 318 | TString *luaS_newextlstr (lua_State *L, |
| 319 | const char *s, size_t len, lua_Alloc falloc, void *ud) { |
| 320 | struct NewExt ne; |
| 321 | if (!falloc) { |
| 322 | ne.kind = LSTRFIX; |
| 323 | f_newext(L, &ne); /* just create header */ |
| 324 | } |
| 325 | else { |
| 326 | ne.kind = LSTRMEM; |
| 327 | if (luaD_rawrunprotected(L, f_newext, &ne) != LUA_OK) { /* mem. error? */ |
| 328 | (*falloc)(ud, cast_voidp(s), len + 1, 0); /* free external string */ |
| 329 | luaM_error(L); /* re-raise memory error */ |
| 330 | } |
| 331 | ne.ts->falloc = falloc; |
| 332 | ne.ts->ud = ud; |
| 333 | } |
| 334 | ne.ts->shrlen = ne.kind; |
| 335 | ne.ts->u.lnglen = len; |
| 336 | ne.ts->contents = cast_charp(s); |
| 337 | return ne.ts; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | /* |
no test coverage detected