Fix reflection of setters for unsigned primitive types.
BUG=6764163
We now generate set_*() functions for unsigned types by creating a single
element FieldPacker and stuffing it with the larger Dalvik type. Reusing
FieldPacker in this way allows us to validate that the input is non-negative
and within the appropriate range (i.e. not really using more bits than the
unsigned C type should).
This change also fixes a subtle race where the Dalvik and script side can
disagree about a variable's value. All set_*() methods need to be synchronized,
and we must do the Dalvik update after validating the input data.
Change-Id: I7b2371206848ebbf0b0752779cb6c98cec1ab5f6
diff --git a/slang_rs_reflection.h b/slang_rs_reflection.h
index 424cb2f..3674e82 100644
--- a/slang_rs_reflection.h
+++ b/slang_rs_reflection.h
@@ -105,8 +105,15 @@
bool mUseStdout;
mutable std::ofstream mOF;
+ // Generated RS Elements for type-checking code.
std::set<std::string> mTypesToCheck;
+ // Generated FieldPackers for unsigned setters/validation.
+ std::set<std::string> mFieldPackerTypes;
+
+ bool addTypeNameForElement(const std::string &TypeName);
+ bool addTypeNameForFieldPacker(const std::string &TypeName);
+
static const char *AccessModifierStr(AccessModifier AM);
Context(const std::string &OutputPathBase,
@@ -265,6 +272,9 @@
static void genTypeInstance(Context &C,
const RSExportType *ET);
+ static void genFieldPackerInstance(Context &C,
+ const RSExportType *ET);
+
bool genTypeClass(Context &C,
const RSExportRecordType *ERT,
std::string &ErrorMsg);