mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
FFI: Show address pointed to for tostring(pointer).
This commit is contained in:
parent
51ee3d951e
commit
a7ca722dca
@ -268,9 +268,10 @@ LJLIB_CF(ffi_meta___tostring)
|
|||||||
GCcdata *cd = ffi_checkcdata(L, 1);
|
GCcdata *cd = ffi_checkcdata(L, 1);
|
||||||
const char *msg = "cdata<%s>: %p";
|
const char *msg = "cdata<%s>: %p";
|
||||||
CTypeID id = cd->typeid;
|
CTypeID id = cd->typeid;
|
||||||
|
void *p = cdataptr(cd);
|
||||||
if (id == CTID_CTYPEID) {
|
if (id == CTID_CTYPEID) {
|
||||||
msg = "ctype<%s>";
|
msg = "ctype<%s>";
|
||||||
id = *(CTypeID *)cdataptr(cd);
|
id = *(CTypeID *)p;
|
||||||
} else {
|
} else {
|
||||||
CType *ct = ctype_raw(ctype_cts(L), id);
|
CType *ct = ctype_raw(ctype_cts(L), id);
|
||||||
if (ctype_iscomplex(ct->info)) {
|
if (ctype_iscomplex(ct->info)) {
|
||||||
@ -286,9 +287,13 @@ LJLIB_CF(ffi_meta___tostring)
|
|||||||
cTValue *tv = lj_ctype_meta(cts, id, MM_tostring);
|
cTValue *tv = lj_ctype_meta(cts, id, MM_tostring);
|
||||||
if (tv)
|
if (tv)
|
||||||
return lj_meta_tailcall(L, tv);
|
return lj_meta_tailcall(L, tv);
|
||||||
|
} else if (ctype_isptr(ct->info)) {
|
||||||
|
p = cdata_getptr(p, ct->size);
|
||||||
|
} else if (ctype_isfunc(ct->info)) {
|
||||||
|
p = *(void **)p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lj_str_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), cdataptr(cd));
|
lj_str_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p);
|
||||||
checkgc:
|
checkgc:
|
||||||
lj_gc_check(L);
|
lj_gc_check(L);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -361,8 +361,8 @@ const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp)
|
|||||||
ptrdiff_t p = (ptrdiff_t)(va_arg(argp, void *));
|
ptrdiff_t p = (ptrdiff_t)(va_arg(argp, void *));
|
||||||
ptrdiff_t i, lasti = 2+FMTP_CHARS;
|
ptrdiff_t i, lasti = 2+FMTP_CHARS;
|
||||||
#if LJ_64
|
#if LJ_64
|
||||||
if ((p >> 32) == 0) /* Shorten output for true 32 bit pointers. */
|
/* Shorten output for 64 bit pointers. */
|
||||||
lasti = 2+2*4;
|
lasti = 2+2*4+((p >> 32) ? 2+2*(lj_fls((uint32_t)(p >> 32))>>3) : 0);
|
||||||
#endif
|
#endif
|
||||||
buf[0] = '0';
|
buf[0] = '0';
|
||||||
buf[1] = 'x';
|
buf[1] = 'x';
|
||||||
|
Loading…
Reference in New Issue
Block a user