Ignore:
Timestamp:
Dec 7, 2010, 7:57:56 PM (15 years ago)
Author:
dmik
Message:

jdk: Added jsafe_cast<> template intended to safely cast between jchar* and wchar_t* on GCC and provide a straight (compiler-defined) conversion on Windows (where jchar and wchar_t are fully replaceable).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/openjdk/jdk/src/windows/javavm/export/jni_md.h

    r66 r195  
    3939typedef signed char jbyte;
    4040
     41#ifdef __cplusplus
     42
     43/* template for safe type casting: the generic version lets the compiler
     44 * decide (as if no template was used); specific instantiations deal with
     45 * special cases which are guaranteed to be safe */
     46template<typename TR, typename TS>
     47inline TR jsafe_cast(TS ts) { return ts; }
     48
     49#ifdef __EMX__
     50/* sizeof(jchar) = sizeof(wchar_t) in GCC but the types are not relative
     51 * (as opposed to MSVC) so an explicit cast is required */
     52typedef unsigned short jchar;
     53template<>
     54inline jchar *jsafe_cast<jchar *, wchar_t *>(wchar_t *ts) { return reinterpret_cast<jchar*>(ts); }
     55template<>
     56inline const jchar *jsafe_cast<const jchar *, wchar_t *>(wchar_t *ts) { return reinterpret_cast<const jchar*>(ts); }
     57template<>
     58inline const jchar *jsafe_cast<const jchar *, const wchar_t *>(const wchar_t *ts) { return reinterpret_cast<const jchar*>(ts); }
     59template<>
     60inline wchar_t *jsafe_cast<wchar_t *, jchar *>(jchar *ts) { return reinterpret_cast<wchar_t*>(ts); }
     61template<>
     62inline const wchar_t *jsafe_cast<const wchar_t *, jchar *>(jchar *ts) { return reinterpret_cast<const wchar_t*>(ts); }
     63template<>
     64inline const wchar_t *jsafe_cast<const wchar_t *, const jchar *>(const jchar *ts) { return reinterpret_cast<const wchar_t*>(ts); }
     65#endif
     66
     67#endif /* __cplusplus */
     68
    4169#endif /* !_JAVASOFT_JNI_MD_H_ */
Note: See TracChangeset for help on using the changeset viewer.