bool RowIndexesValid(JNIEnv* env, T* pTable, jlong startIndex, jlong endIndex, jlong range) { size_t maxIndex = pTable->size(); if (endIndex == -1) endIndex = maxIndex; if (startIndex < 0) { TR_ERR("startIndex %" PRId64 " < 0 - invalid!", S64(startIndex)) ThrowException(env, IndexOutOfBounds, "startIndex < 0."); return false; } if (realm::util::int_greater_than(startIndex, maxIndex)) { TR_ERR("startIndex %" PRId64 " > %" PRId64 " - invalid!", S64(startIndex), S64(maxIndex)) ThrowException(env, IndexOutOfBounds, "startIndex > available rows."); return false; } if (realm::util::int_greater_than(endIndex, maxIndex)) { TR_ERR("endIndex %" PRId64 " > %" PRId64 " - invalid!", S64(endIndex), S64(maxIndex)) ThrowException(env, IndexOutOfBounds, "endIndex > available rows."); return false; } if (startIndex > endIndex) { TR_ERR("startIndex %" PRId64 " > endIndex %" PRId64 " - invalid!", S64(startIndex), S64(endIndex)) ThrowException(env, IndexOutOfBounds, "startIndex > endIndex."); return false; } if (range != -1 && range < 0) { TR_ERR("range %" PRId64 " < 0 - invalid!", S64(range)) ThrowException(env, IndexOutOfBounds, "range < 0."); return false; } return true; }
bool RowIndexesValid(JNIEnv* env, T* pTable, jlong startIndex, jlong endIndex, jlong range) { size_t maxIndex = pTable->size(); if (endIndex == -1) endIndex = maxIndex; if (startIndex < 0) { TR_ERR((env, "startIndex %lld < 0 - invalid!", S(startIndex), 0)); ThrowException(env, IndexOutOfBounds, "startIndex < 0."); return false; } if (tightdb::util::int_greater_than(startIndex, maxIndex)) { TR_ERR((env, "startIndex %lld > %lld - invalid!", S(startIndex), maxIndex)); ThrowException(env, IndexOutOfBounds, "startIndex > available rows."); return false; } if (tightdb::util::int_greater_than(endIndex, maxIndex)) { TR_ERR((env, "endIndex %lld > %lld - invalid!", S(endIndex), maxIndex)); ThrowException(env, IndexOutOfBounds, "endIndex > available rows."); return false; } if (startIndex > endIndex) { TR_ERR((env, "startIndex %lld > endIndex %lld- invalid!", S(startIndex), S(endIndex))); ThrowException(env, IndexOutOfBounds, "startIndex > endIndex."); return false; } if (range != -1 && range < 0) { TR_ERR((env, "range %lld < 0 - invalid!", range)); ThrowException(env, IndexOutOfBounds, "range < 0."); return false; } return true; }
int yyerror(const char* msg) { m_errormsg = msg; TR_ERR("Parsing error - line %d, text `%s`, msg `%s`", yylineno, yytext, msg); return 0; }
/** * osInitializeVMM * * Do operating system dependent on time initializations here. * * @return OK if successful else error number. */ IEC_UINT osInitializeVMM(STaskInfoVMM *pVMM) { IEC_UINT uRes = OK; the_pVMM = pVMM; #if defined(_SOF_4CFC_SRC_) pthread_t thr; fcSetLed(FC_LED_RUN, FC_LED_ON_TOGGLE); fcSetLed(FC_LED_ERROR, FC_LED_ON_TOGGLE); int iRes = osPthreadCreate(&thr, NULL, LED_Thread, pVMM, "LED", 0); if (iRes != 0) { TR_ERR("pthread_create() failed", iRes); RETURN(ERR_CREATE_TASK); } osSleep(50); #endif dataEngineStart(); #if defined(IP_CFG_NCC) typedef void (*LibFct)(void); extern LibFct libFcts[]; pVMM->Shared.pLibFcts = libFcts; #endif RETURN(uRes); }
inline bool RowIsValid(JNIEnv* env, Row* rowPtr) { bool valid = (rowPtr != NULL && rowPtr->is_attached()); if (!valid) { TR_ERR("Row %p is no longer attached!", VOID_PTR(rowPtr)) ThrowException(env, RowInvalid, "Object is no longer valid to operate on. Was it deleted by another thread?"); } return valid; }
inline bool TypeIsLinkLike(JNIEnv* env, T* pTable, jlong columnIndex) { size_t col = static_cast<size_t>(columnIndex); int colType = pTable->get_column_type(col); if (colType == type_Link || colType == type_LinkList) { return true; } TR_ERR("Expected columnType %d or %d, but got %d", type_Link, type_LinkList, colType) ThrowException(env, IllegalArgument, "ColumnType invalid: expected type_Link or type_LinkList"); return false; }
inline bool TblIndexInsertValid(JNIEnv* env, T* pTable, jlong columnIndex, jlong rowIndex) { if (!TblColIndexValid(env, pTable, columnIndex)) return false; bool rowErr = realm::util::int_greater_than(rowIndex, pTable->size()+1); if (rowErr) { TR_ERR("rowIndex %" PRId64 " > %" PRId64 " - invalid!", S64(rowIndex), S64(pTable->size())) ThrowException(env, IndexOutOfBounds, "rowIndex " + num_to_string(rowIndex) + " > available rows " + num_to_string(pTable->size()) + "."); } return !rowErr; }
inline bool ColIndexValid(JNIEnv* env, T* pTable, jlong columnIndex) { if (columnIndex < 0) { ThrowException(env, IndexOutOfBounds, "columnIndex is less than 0."); return false; } bool colErr = realm::util::int_greater_than_or_equal(columnIndex, pTable->get_column_count()); if (colErr) { TR_ERR("columnIndex %" PRId64 " > %" PRId64 " - invalid!", S64(columnIndex), S64(pTable->get_column_count())) ThrowException(env, IndexOutOfBounds, "columnIndex > available columns."); } return !colErr; }
inline bool RowIndexValid(JNIEnv* env, T* pTable, jlong rowIndex, bool offset=false) { if(rowIndex < 0) { ThrowException(env, IndexOutOfBounds, "rowIndex is less than 0."); return false; } size_t size = pTable->size(); if (size > 0 && offset) size -= 1; bool rowErr = tightdb::util::int_greater_than_or_equal(rowIndex, size); if (rowErr) { TR_ERR((env, "rowIndex %lld > %lld - invalid!", S(rowIndex), size)); ThrowException(env, IndexOutOfBounds, "rowIndex > available rows."); } return !rowErr; }
inline bool TypeValid(JNIEnv* env, T* pTable, jlong columnIndex, jlong rowIndex, int expectColType, bool allowMixed) { size_t col = static_cast<size_t>(columnIndex); int colType = pTable->get_column_type(col); if (allowMixed) { if (colType == realm::type_Mixed) { size_t row = static_cast<size_t>(rowIndex); colType = pTable->get_mixed_type(col, row); } } if (colType != expectColType) { TR_ERR("Expected columnType %d, but got %d.", expectColType, pTable->get_column_type(col)) ThrowException(env, IllegalArgument, "ColumnType invalid."); return false; } return true; }
inline bool TableIsValid(JNIEnv* env, T* objPtr) { bool valid = (objPtr != NULL); if (valid) { // Check if Table is valid if (realm::util::SameType<realm::Table, T>::value) { valid = TBL(objPtr)->is_attached(); } // TODO: Add check for TableView } if (!valid) { TR_ERR("Table %p is no longer attached!", VOID_PTR(objPtr)) ThrowException(env, TableInvalid, "Table is no longer valid to operate on."); } return valid; }
inline bool TableIsValid(JNIEnv* env, T* objPtr) { bool valid = (objPtr != NULL); if (valid) { // Check if Table is valid if (tightdb::util::SameType<tightdb::Table, T>::value) { valid = TBL(objPtr)->is_attached(); } // TODO: Add check for TableView } if (!valid) { TR_ERR((env, "Table %x is no longer attached!", objPtr)); ThrowException(env, TableInvalid, "Table is closed, and no longer valid to operate on."); } return valid; }
inline bool RowIndexValid(JNIEnv* env, T* pTable, jlong rowIndex, bool offset=false) { if (rowIndex < 0) { ThrowException(env, IndexOutOfBounds, "rowIndex is less than 0."); return false; } size_t size = pTable->size(); if (size > 0 && offset) size -= 1; bool rowErr = realm::util::int_greater_than_or_equal(rowIndex, size); if (rowErr) { TR_ERR("rowIndex %" PRId64 " > %" PRId64 " - invalid!", S64(rowIndex), S64(size)) ThrowException(env, IndexOutOfBounds, "rowIndex > available rows: " + num_to_string(rowIndex) + " > " + num_to_string(size)); } return !rowErr; }
void tbl_nativeDoMixed(M doMixed, T* pTable, JNIEnv* env, jlong columnIndex, jlong rowIndex, jobject jMixedValue) { DataType valueType = GetMixedObjectType(env, jMixedValue); switch(valueType) { case type_Int: { jlong longValue = GetMixedIntValue(env, jMixedValue); (pTable->*doMixed)( S(columnIndex), S(rowIndex), Mixed(static_cast<int64_t>(longValue))); return; } case type_Float: { jfloat floatValue = GetMixedFloatValue(env, jMixedValue); (pTable->*doMixed)( S(columnIndex), S(rowIndex), Mixed(floatValue)); return; } case type_Double: { jdouble doubleValue = GetMixedDoubleValue(env, jMixedValue); (pTable->*doMixed)( S(columnIndex), S(rowIndex), Mixed(doubleValue)); return; } case type_Bool: { jboolean boolValue = GetMixedBooleanValue(env, jMixedValue); (pTable->*doMixed)( S(columnIndex), S(rowIndex), Mixed(boolValue != 0 ? true : false)); return; } case type_String: { jstring stringValue = GetMixedStringValue(env, jMixedValue); JStringAccessor string(env, stringValue); // throws (pTable->*doMixed)( S(columnIndex), S(rowIndex), StringData(string)); return; } case type_DateTime: { jlong dateTimeValue = GetMixedDateTimeValue(env, jMixedValue); DateTime date(dateTimeValue); (pTable->*doMixed)( S(columnIndex), S(rowIndex), Mixed(date)); return; } case type_Binary: { jint mixedBinaryType = GetMixedBinaryType(env, jMixedValue); if (mixedBinaryType == 0) { jbyteArray dataArray = GetMixedByteArrayValue(env, jMixedValue); if (!dataArray) break; char* data = reinterpret_cast<char*>(env->GetByteArrayElements(dataArray, NULL)); if (!data) break; size_t size = S(env->GetArrayLength(dataArray)); (pTable->*doMixed)( S(columnIndex), S(rowIndex), BinaryData(data, size)); env->ReleaseByteArrayElements(dataArray, reinterpret_cast<jbyte*>(data), 0); return; } else if (mixedBinaryType == 1) { jobject jByteBuffer = GetMixedByteBufferValue(env, jMixedValue); if (!jByteBuffer) break; BinaryData binaryData; if (GetBinaryData(env, jByteBuffer, binaryData)) (pTable->*doMixed)( S(columnIndex), S(rowIndex), binaryData); return; } break; // failed } case type_Table: { (pTable->*doMixed)( S(columnIndex), S(rowIndex), Mixed::subtable_tag()); return; } case type_Mixed: break; case type_Link: break; case type_LinkList: break; } TR_ERR("ERROR: nativeSetMixed() failed.") ThrowException(env, IllegalArgument, "nativeSetMixed()"); }