Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
djinni
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
djinni
Commits
82f0751c
Commit
82f0751c
authored
Jul 14, 2016
by
Aleksey Konovalov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
c++ wide strings support
parent
1dc5a248
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
139 additions
and
2 deletions
+139
-2
src/source/CppMarshal.scala
src/source/CppMarshal.scala
+1
-1
src/source/JNIMarshal.scala
src/source/JNIMarshal.scala
+1
-1
src/source/Main.scala
src/source/Main.scala
+4
-0
src/source/generator.scala
src/source/generator.scala
+1
-0
support-lib/jni/Marshal.hpp
support-lib/jni/Marshal.hpp
+19
-0
support-lib/jni/djinni_support.cpp
support-lib/jni/djinni_support.cpp
+23
-0
support-lib/jni/djinni_support.hpp
support-lib/jni/djinni_support.hpp
+3
-0
test-suite/djinni/wchar_test.djinni
test-suite/djinni/wchar_test.djinni
+10
-0
test-suite/handwritten-src/cpp/wchar_test_helpers.cpp
test-suite/handwritten-src/cpp/wchar_test_helpers.cpp
+29
-0
test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java
...andwritten-src/java/com/dropbox/djinni/test/AllTests.java
+1
-0
test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java
...ndwritten-src/java/com/dropbox/djinni/test/WcharTest.java
+16
-0
test-suite/run_djinni.sh
test-suite/run_djinni.sh
+31
-0
No files found.
src/source/CppMarshal.scala
View file @
82f0751c
...
@@ -145,7 +145,7 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
...
@@ -145,7 +145,7 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
}
}
def
base
(
m
:
Meta
)
:
String
=
m
match
{
def
base
(
m
:
Meta
)
:
String
=
m
match
{
case
p
:
MPrimitive
=>
p
.
cName
case
p
:
MPrimitive
=>
p
.
cName
case
MString
=>
"std::string"
case
MString
=>
if
(
spec
.
cppUseWideStrings
)
"std::wstring"
else
"std::string"
case
MDate
=>
"std::chrono::system_clock::time_point"
case
MDate
=>
"std::chrono::system_clock::time_point"
case
MBinary
=>
"std::vector<uint8_t>"
case
MBinary
=>
"std::vector<uint8_t>"
case
MOptional
=>
spec
.
cppOptionalTemplate
case
MOptional
=>
spec
.
cppOptionalTemplate
...
...
src/source/JNIMarshal.scala
View file @
82f0751c
...
@@ -98,7 +98,7 @@ class JNIMarshal(spec: Spec) extends Marshal(spec) {
...
@@ -98,7 +98,7 @@ class JNIMarshal(spec: Spec) extends Marshal(spec) {
}
}
case
MOptional
=>
"Optional"
case
MOptional
=>
"Optional"
case
MBinary
=>
"Binary"
case
MBinary
=>
"Binary"
case
MString
=>
"String"
case
MString
=>
if
(
spec
.
cppUseWideStrings
)
"WString"
else
"String"
case
MDate
=>
"Date"
case
MDate
=>
"Date"
case
MList
=>
"List"
case
MList
=>
"List"
case
MSet
=>
"Set"
case
MSet
=>
"Set"
...
...
src/source/Main.scala
View file @
82f0751c
...
@@ -35,6 +35,7 @@ object Main {
...
@@ -35,6 +35,7 @@ object Main {
var
cppNnHeader
:
Option
[
String
]
=
None
var
cppNnHeader
:
Option
[
String
]
=
None
var
cppNnType
:
Option
[
String
]
=
None
var
cppNnType
:
Option
[
String
]
=
None
var
cppNnCheckExpression
:
Option
[
String
]
=
None
var
cppNnCheckExpression
:
Option
[
String
]
=
None
var
cppUseWideStrings
:
Boolean
=
false
var
javaOutFolder
:
Option
[
File
]
=
None
var
javaOutFolder
:
Option
[
File
]
=
None
var
javaPackage
:
Option
[
String
]
=
None
var
javaPackage
:
Option
[
String
]
=
None
var
javaCppException
:
Option
[
String
]
=
None
var
javaCppException
:
Option
[
String
]
=
None
...
@@ -133,6 +134,8 @@ object Main {
...
@@ -133,6 +134,8 @@ object Main {
.
text
(
"The type to use for non-nullable pointers (as a substitute for std::shared_ptr)"
)
.
text
(
"The type to use for non-nullable pointers (as a substitute for std::shared_ptr)"
)
opt
[
String
](
"cpp-nn-check-expression"
).
valueName
(
"<header>"
).
foreach
(
x
=>
cppNnCheckExpression
=
Some
(
x
))
opt
[
String
](
"cpp-nn-check-expression"
).
valueName
(
"<header>"
).
foreach
(
x
=>
cppNnCheckExpression
=
Some
(
x
))
.
text
(
"The expression to use for building non-nullable pointers"
)
.
text
(
"The expression to use for building non-nullable pointers"
)
opt
[
Boolean
](
"cpp-use-wide-strings"
).
valueName
(
"<true/false>"
).
foreach
(
x
=>
cppUseWideStrings
=
x
)
.
text
(
"Use wide strings in C++ code (default: false)"
)
note
(
""
)
note
(
""
)
opt
[
File
](
"jni-out"
).
valueName
(
"<out-folder>"
).
foreach
(
x
=>
jniOutFolder
=
Some
(
x
))
opt
[
File
](
"jni-out"
).
valueName
(
"<out-folder>"
).
foreach
(
x
=>
jniOutFolder
=
Some
(
x
))
.
text
(
"The folder for the JNI C++ output files (Generator disabled if unspecified)."
)
.
text
(
"The folder for the JNI C++ output files (Generator disabled if unspecified)."
)
...
@@ -293,6 +296,7 @@ object Main {
...
@@ -293,6 +296,7 @@ object Main {
cppNnHeader
,
cppNnHeader
,
cppNnType
,
cppNnType
,
cppNnCheckExpression
,
cppNnCheckExpression
,
cppUseWideStrings
,
jniOutFolder
,
jniOutFolder
,
jniHeaderOutFolder
,
jniHeaderOutFolder
,
jniIncludePrefix
,
jniIncludePrefix
,
...
...
src/source/generator.scala
View file @
82f0751c
...
@@ -49,6 +49,7 @@ package object generatorTools {
...
@@ -49,6 +49,7 @@ package object generatorTools {
cppNnHeader
:
Option
[
String
],
cppNnHeader
:
Option
[
String
],
cppNnType
:
Option
[
String
],
cppNnType
:
Option
[
String
],
cppNnCheckExpression
:
Option
[
String
],
cppNnCheckExpression
:
Option
[
String
],
cppUseWideStrings
:
Boolean
,
jniOutFolder
:
Option
[
File
],
jniOutFolder
:
Option
[
File
],
jniHeaderOutFolder
:
Option
[
File
],
jniHeaderOutFolder
:
Option
[
File
],
jniIncludePrefix
:
String
,
jniIncludePrefix
:
String
,
...
...
support-lib/jni/Marshal.hpp
View file @
82f0751c
...
@@ -178,6 +178,25 @@ namespace djinni
...
@@ -178,6 +178,25 @@ namespace djinni
}
}
};
};
struct
WString
{
using
CppType
=
std
::
wstring
;
using
JniType
=
jstring
;
using
Boxed
=
WString
;
static
CppType
toCpp
(
JNIEnv
*
jniEnv
,
JniType
j
)
{
assert
(
j
!=
nullptr
);
return
jniWStringFromString
(
jniEnv
,
j
);
}
static
LocalRef
<
JniType
>
fromCpp
(
JNIEnv
*
jniEnv
,
const
CppType
&
c
)
{
return
{
jniEnv
,
jniStringFromWString
(
jniEnv
,
c
.
c_str
())};
}
};
struct
Binary
struct
Binary
{
{
using
CppType
=
std
::
vector
<
uint8_t
>
;
using
CppType
=
std
::
vector
<
uint8_t
>
;
...
...
support-lib/jni/djinni_support.cpp
View file @
82f0751c
...
@@ -371,6 +371,15 @@ jstring jniStringFromUTF8(JNIEnv * env, const std::string & str) {
...
@@ -371,6 +371,15 @@ jstring jniStringFromUTF8(JNIEnv * env, const std::string & str) {
return
res
;
return
res
;
}
}
jstring
jniStringFromWString
(
JNIEnv
*
env
,
const
std
::
wstring
&
str
)
{
std
::
u16string
utf16
(
str
.
begin
(),
str
.
end
());;
jstring
res
=
env
->
NewString
(
reinterpret_cast
<
const
jchar
*>
(
utf16
.
data
()),
utf16
.
length
());
DJINNI_ASSERT
(
res
,
env
);
return
res
;
}
// UTF-16 decode helpers.
// UTF-16 decode helpers.
static
inline
bool
is_high_surrogate
(
char16_t
c
)
{
return
(
c
>=
0xD800
)
&&
(
c
<
0xDC00
);
}
static
inline
bool
is_high_surrogate
(
char16_t
c
)
{
return
(
c
>=
0xD800
)
&&
(
c
<
0xDC00
);
}
static
inline
bool
is_low_surrogate
(
char16_t
c
)
{
return
(
c
>=
0xDC00
)
&&
(
c
<
0xE000
);
}
static
inline
bool
is_low_surrogate
(
char16_t
c
)
{
return
(
c
>=
0xDC00
)
&&
(
c
<
0xE000
);
}
...
@@ -441,6 +450,20 @@ std::string jniUTF8FromString(JNIEnv * env, const jstring jstr) {
...
@@ -441,6 +450,20 @@ std::string jniUTF8FromString(JNIEnv * env, const jstring jstr) {
return
out
;
return
out
;
}
}
std
::
wstring
jniWStringFromString
(
JNIEnv
*
env
,
const
jstring
jstr
)
{
DJINNI_ASSERT
(
jstr
,
env
);
const
jsize
length
=
env
->
GetStringLength
(
jstr
);
jniExceptionCheck
(
env
);
const
auto
deleter
=
[
env
,
jstr
]
(
const
jchar
*
c
)
{
env
->
ReleaseStringChars
(
jstr
,
c
);
};
std
::
unique_ptr
<
const
jchar
,
decltype
(
deleter
)
>
ptr
(
env
->
GetStringChars
(
jstr
,
nullptr
),
deleter
);
const
char16_t
*
begin
=
reinterpret_cast
<
const
char16_t
*>
(
ptr
.
get
());
const
char16_t
*
end
=
begin
+
length
;
return
std
::
wstring
(
begin
,
end
);
}
DJINNI_WEAK_DEFINITION
DJINNI_WEAK_DEFINITION
void
jniSetPendingFromCurrent
(
JNIEnv
*
env
,
const
char
*
ctx
)
noexcept
{
void
jniSetPendingFromCurrent
(
JNIEnv
*
env
,
const
char
*
ctx
)
noexcept
{
jniDefaultSetPendingFromCurrent
(
env
,
ctx
);
jniDefaultSetPendingFromCurrent
(
env
,
ctx
);
...
...
support-lib/jni/djinni_support.hpp
View file @
82f0751c
...
@@ -543,6 +543,9 @@ private:
...
@@ -543,6 +543,9 @@ private:
jstring
jniStringFromUTF8
(
JNIEnv
*
env
,
const
std
::
string
&
str
);
jstring
jniStringFromUTF8
(
JNIEnv
*
env
,
const
std
::
string
&
str
);
std
::
string
jniUTF8FromString
(
JNIEnv
*
env
,
const
jstring
jstr
);
std
::
string
jniUTF8FromString
(
JNIEnv
*
env
,
const
jstring
jstr
);
jstring
jniStringFromWString
(
JNIEnv
*
env
,
const
std
::
wstring
&
str
);
std
::
wstring
jniWStringFromString
(
JNIEnv
*
env
,
const
jstring
jstr
);
class
JniEnum
{
class
JniEnum
{
public:
public:
/*
/*
...
...
test-suite/djinni/wchar_test.djinni
0 → 100644
View file @
82f0751c
wchar_test_rec = record {
s: string;
}
wchar_test_helpers = interface +c {
static get_record() : wchar_test_rec;
static get_string() : string;
static check_string(s: string) : bool;
static check_record(r: wchar_test_rec) : bool;
}
test-suite/handwritten-src/cpp/wchar_test_helpers.cpp
0 → 100644
View file @
82f0751c
#include "wchar_test_helpers.hpp"
#include "wchar_test_rec.hpp"
namespace
testsuite
{
static
const
std
::
wstring
str1
=
L"some string with unicode \u263a symbol"
;
static
const
std
::
wstring
str2
=
L"another string with unicode \u263b symbol"
;
WcharTestRec
WcharTestHelpers
::
get_record
()
{
return
WcharTestRec
(
str1
);
}
std
::
wstring
WcharTestHelpers
::
get_string
()
{
return
str2
;
}
bool
WcharTestHelpers
::
check_string
(
const
std
::
wstring
&
s
)
{
return
s
==
str2
;
}
bool
WcharTestHelpers
::
check_record
(
const
WcharTestRec
&
r
)
{
return
r
.
s
==
str1
;
}
}
// namespace testsuite
test-suite/handwritten-src/java/com/dropbox/djinni/test/AllTests.java
View file @
82f0751c
...
@@ -22,6 +22,7 @@ public class AllTests extends TestSuite {
...
@@ -22,6 +22,7 @@ public class AllTests extends TestSuite {
mySuite
.
addTestSuite
(
TokenTest
.
class
);
mySuite
.
addTestSuite
(
TokenTest
.
class
);
mySuite
.
addTestSuite
(
DurationTest
.
class
);
mySuite
.
addTestSuite
(
DurationTest
.
class
);
mySuite
.
addTestSuite
(
MockRecordTest
.
class
);
mySuite
.
addTestSuite
(
MockRecordTest
.
class
);
mySuite
.
addTestSuite
(
WcharTest
.
class
);
return
mySuite
;
return
mySuite
;
}
}
...
...
test-suite/handwritten-src/java/com/dropbox/djinni/test/WcharTest.java
0 → 100644
View file @
82f0751c
package
com.dropbox.djinni.test
;
import
junit.framework.TestCase
;
public
class
WcharTest
extends
TestCase
{
private
static
final
String
STR1
=
"some string with unicode \u263a symbol"
;
private
static
final
String
STR2
=
"another string with unicode \u263b symbol"
;
public
void
test
()
{
assertEquals
(
WcharTestHelpers
.
getRecord
().
getS
(),
STR1
);
assertEquals
(
WcharTestHelpers
.
getString
(),
STR2
);
assertEquals
(
WcharTestHelpers
.
checkString
(
STR2
),
true
);
assertEquals
(
WcharTestHelpers
.
checkRecord
(
new
WcharTestRec
(
STR1
)),
true
);
}
}
test-suite/run_djinni.sh
View file @
82f0751c
...
@@ -17,12 +17,14 @@ base_dir=$(cd "`dirname "$loc"`" && pwd)
...
@@ -17,12 +17,14 @@ base_dir=$(cd "`dirname "$loc"`" && pwd)
temp_out
=
"
$base_dir
/djinni-output-temp"
temp_out
=
"
$base_dir
/djinni-output-temp"
in
=
"
$base_dir
/djinni/all.djinni"
in
=
"
$base_dir
/djinni/all.djinni"
wchar_in
=
"
$base_dir
/djinni/wchar_test.djinni"
# Relative version of in and temp_out are used for Djinni call below so that
# Relative version of in and temp_out are used for Djinni call below so that
# generated lists of infiles/outfiles are not machine-dependent. This
# generated lists of infiles/outfiles are not machine-dependent. This
# is an artifact of the test suite, where we want the genereated files
# is an artifact of the test suite, where we want the genereated files
# to be in git for examination.
# to be in git for examination.
in_relative
=
"djinni/all.djinni"
in_relative
=
"djinni/all.djinni"
wchar_in_relative
=
"djinni/wchar_test.djinni"
temp_out_relative
=
"djinni-output-temp"
temp_out_relative
=
"djinni-output-temp"
cpp_out
=
"
$base_dir
/generated-src/cpp"
cpp_out
=
"
$base_dir
/generated-src/cpp"
...
@@ -59,6 +61,35 @@ fi
...
@@ -59,6 +61,35 @@ fi
"
$base_dir
/../src/build"
"
$base_dir
/../src/build"
[
!
-e
"
$temp_out
"
]
||
rm
-r
"
$temp_out
"
[
!
-e
"
$temp_out
"
]
||
rm
-r
"
$temp_out
"
(
cd
"
$base_dir
"
&&
\
(
cd
"
$base_dir
"
&&
\
"
$base_dir
/../src/run-assume-built"
\
--java-out
"
$temp_out_relative
/java"
\
--java-package
$java_package
\
--java-nullable-annotation
"javax.annotation.CheckForNull"
\
--java-nonnull-annotation
"javax.annotation.Nonnull"
\
--java-use-final-for-record
false
\
--ident-java-field
mFooBar
\
\
--cpp-out
"
$temp_out_relative
/cpp"
\
--cpp-namespace
testsuite
\
--ident-cpp-enum-type
foo_bar
\
--cpp-optional-template
"std::experimental::optional"
\
--cpp-optional-header
"<experimental/optional>"
\
--cpp-extended-record-include-prefix
"../../handwritten-src/cpp/"
\
--cpp-use-wide-strings
true
\
\
--jni-out
"
$temp_out_relative
/jni"
\
--ident-jni-class
NativeFooBar
\
--ident-jni-file
NativeFooBar
\
\
--objc-out
"
$temp_out_relative
/objc"
\
--objcpp-out
"
$temp_out_relative
/objc"
\
--objc-type-prefix
DB
\
\
--yaml-out
"
$temp_out_relative
/yaml"
\
--yaml-out-file
"yaml-test.yaml"
\
--yaml-prefix
"test_"
\
\
--idl
"
$wchar_in_relative
"
&&
\
"
$base_dir
/../src/run-assume-built"
\
"
$base_dir
/../src/run-assume-built"
\
--java-out
"
$temp_out_relative
/java"
\
--java-out
"
$temp_out_relative
/java"
\
--java-package
$java_package
\
--java-package
$java_package
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment