diff options
| author | Mike Pall <mike> | 2011-06-07 20:57:32 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2011-06-07 20:57:32 +0200 |
| commit | a7ca722dca4b96367dff34402b21901f3e44a3cf (patch) | |
| tree | 381ebda81d9f519257e603d7a9e85091197ffeb1 | |
| parent | 51ee3d951e6cb5cbcd7d97ba8e82d019df8a2056 (diff) | |
| download | luajit-a7ca722dca4b96367dff34402b21901f3e44a3cf.tar.gz luajit-a7ca722dca4b96367dff34402b21901f3e44a3cf.tar.bz2 luajit-a7ca722dca4b96367dff34402b21901f3e44a3cf.zip | |
FFI: Show address pointed to for tostring(pointer).
| -rw-r--r-- | src/lib_ffi.c | 9 | ||||
| -rw-r--r-- | src/lj_str.c | 4 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 0f8d5013..99f04aab 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
| @@ -268,9 +268,10 @@ LJLIB_CF(ffi_meta___tostring) | |||
| 268 | GCcdata *cd = ffi_checkcdata(L, 1); | 268 | GCcdata *cd = ffi_checkcdata(L, 1); |
| 269 | const char *msg = "cdata<%s>: %p"; | 269 | const char *msg = "cdata<%s>: %p"; |
| 270 | CTypeID id = cd->typeid; | 270 | CTypeID id = cd->typeid; |
| 271 | void *p = cdataptr(cd); | ||
| 271 | if (id == CTID_CTYPEID) { | 272 | if (id == CTID_CTYPEID) { |
| 272 | msg = "ctype<%s>"; | 273 | msg = "ctype<%s>"; |
| 273 | id = *(CTypeID *)cdataptr(cd); | 274 | id = *(CTypeID *)p; |
| 274 | } else { | 275 | } else { |
| 275 | CType *ct = ctype_raw(ctype_cts(L), id); | 276 | CType *ct = ctype_raw(ctype_cts(L), id); |
| 276 | if (ctype_iscomplex(ct->info)) { | 277 | if (ctype_iscomplex(ct->info)) { |
| @@ -286,9 +287,13 @@ LJLIB_CF(ffi_meta___tostring) | |||
| 286 | cTValue *tv = lj_ctype_meta(cts, id, MM_tostring); | 287 | cTValue *tv = lj_ctype_meta(cts, id, MM_tostring); |
| 287 | if (tv) | 288 | if (tv) |
| 288 | return lj_meta_tailcall(L, tv); | 289 | return lj_meta_tailcall(L, tv); |
| 290 | } else if (ctype_isptr(ct->info)) { | ||
| 291 | p = cdata_getptr(p, ct->size); | ||
| 292 | } else if (ctype_isfunc(ct->info)) { | ||
| 293 | p = *(void **)p; | ||
| 289 | } | 294 | } |
| 290 | } | 295 | } |
| 291 | lj_str_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), cdataptr(cd)); | 296 | lj_str_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p); |
| 292 | checkgc: | 297 | checkgc: |
| 293 | lj_gc_check(L); | 298 | lj_gc_check(L); |
| 294 | return 1; | 299 | return 1; |
diff --git a/src/lj_str.c b/src/lj_str.c index 516acefe..a5d894e0 100644 --- a/src/lj_str.c +++ b/src/lj_str.c | |||
| @@ -361,8 +361,8 @@ const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp) | |||
| 361 | ptrdiff_t p = (ptrdiff_t)(va_arg(argp, void *)); | 361 | ptrdiff_t p = (ptrdiff_t)(va_arg(argp, void *)); |
| 362 | ptrdiff_t i, lasti = 2+FMTP_CHARS; | 362 | ptrdiff_t i, lasti = 2+FMTP_CHARS; |
| 363 | #if LJ_64 | 363 | #if LJ_64 |
| 364 | if ((p >> 32) == 0) /* Shorten output for true 32 bit pointers. */ | 364 | /* Shorten output for 64 bit pointers. */ |
| 365 | lasti = 2+2*4; | 365 | lasti = 2+2*4+((p >> 32) ? 2+2*(lj_fls((uint32_t)(p >> 32))>>3) : 0); |
| 366 | #endif | 366 | #endif |
| 367 | buf[0] = '0'; | 367 | buf[0] = '0'; |
| 368 | buf[1] = 'x'; | 368 | buf[1] = 'x'; |
