indenting, + don't use men streams in Android
This commit is contained in:
parent
636992781c
commit
396bd2f8c3
75
C/blobs.c
75
C/blobs.c
@ -21,21 +21,22 @@
|
||||
#include "fmemopen.h"
|
||||
#endif
|
||||
|
||||
#if __ANDROID__
|
||||
#undef HAVE_FMEMOPEN
|
||||
#undef HAVE_OPEN_MEMSTREAM
|
||||
#endif
|
||||
|
||||
#include "blobs.h"
|
||||
|
||||
static blob_type_t unregistered_blob_atom =
|
||||
{ YAP_BLOB_MAGIC_B,
|
||||
PL_BLOB_NOCOPY|PL_BLOB_TEXT,
|
||||
"unregistered"
|
||||
};
|
||||
static blob_type_t unregistered_blob_atom = {
|
||||
YAP_BLOB_MAGIC_B, PL_BLOB_NOCOPY | PL_BLOB_TEXT, "unregistered"};
|
||||
|
||||
char * Yap_blob_to_string(AtomEntry *ref, const char *s0, size_t sz)
|
||||
{
|
||||
char *Yap_blob_to_string(AtomEntry *ref, const char *s0, size_t sz) {
|
||||
// int rc;
|
||||
char *s = (char *)s0;
|
||||
|
||||
// blob_type_t *type = RepBlobProp(ref->PropsOfAE)->blob_type;
|
||||
#if HAVE_FMEMOPEN
|
||||
#if HAVE_FMEMOPEN && !__ANDROID__
|
||||
if (type->write) {
|
||||
FILE *f = fmemopen(s, sz, "w");
|
||||
if (f == NULL) {
|
||||
@ -45,7 +46,8 @@ char * Yap_blob_to_string(AtomEntry *ref, const char *s0, size_t sz)
|
||||
Atom at = AbsAtom(ref);
|
||||
rc = type->write(f, at, 0);
|
||||
if (rc < 0) {
|
||||
Yap_Error( EVALUATION_ERROR_UNDEFINED, MkAtomTerm(at), "failure in user-defined blob to string code" );
|
||||
Yap_Error(EVALUATION_ERROR_UNDEFINED, MkAtomTerm(at),
|
||||
"failure in user-defined blob to string code");
|
||||
}
|
||||
fclose(f); // return the final result.
|
||||
return s;
|
||||
@ -73,8 +75,7 @@ char * Yap_blob_to_string(AtomEntry *ref, const char *s0, size_t sz)
|
||||
#endif
|
||||
}
|
||||
|
||||
int Yap_write_blob(AtomEntry *ref, FILE *stream)
|
||||
{
|
||||
int Yap_write_blob(AtomEntry *ref, FILE *stream) {
|
||||
blob_type_t *type = RepBlobProp(ref->PropsOfAE)->blob_type;
|
||||
|
||||
if (type->write) {
|
||||
@ -85,17 +86,14 @@ int Yap_write_blob(AtomEntry *ref, FILE *stream)
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
return fprintf(stream, "\'%s\'(%p)", RepAtom(AtomSWIStream)->StrOfAE, ref);
|
||||
#else
|
||||
return fprintf(stream, "\'%s\'(0x%p)", RepAtom(AtomSWIStream)->StrOfAE, ref);
|
||||
return fprintf(stream, "\'%s\'(0x%p)", RepAtom(AtomSWIStream)->StrOfAE,
|
||||
ref);
|
||||
#endif
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
YAP_is_blob(Term t, blob_type_t **type)
|
||||
{
|
||||
bool YAP_is_blob(Term t, blob_type_t **type) {
|
||||
CACHE_REGS
|
||||
Term yt = Yap_GetFromSlot(t);
|
||||
Atom a;
|
||||
@ -113,7 +111,6 @@ YAP_is_blob(Term t, blob_type_t **type)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* void check_chain(void); */
|
||||
|
||||
/* void check_chain(void) { */
|
||||
@ -126,9 +123,7 @@ YAP_is_blob(Term t, blob_type_t **type)
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
AtomEntry *
|
||||
Yap_lookupBlob(void *blob, size_t len, void *type0, int *new)
|
||||
{
|
||||
AtomEntry *Yap_lookupBlob(void *blob, size_t len, void *type0, int *new) {
|
||||
YAP_BlobPropEntry *b;
|
||||
AtomEntry *ae;
|
||||
blob_type_t *type = type0;
|
||||
@ -140,8 +135,7 @@ Yap_lookupBlob(void *blob, size_t len, void *type0, int *new)
|
||||
/* just keep a linked chain for now */
|
||||
ae = Blobs;
|
||||
while (ae) {
|
||||
if (ae->PropsOfAE &&
|
||||
RepBlobProp(ae->PropsOfAE)->blob_type == type &&
|
||||
if (ae->PropsOfAE && RepBlobProp(ae->PropsOfAE)->blob_type == type &&
|
||||
ae->rep.blob->length == len &&
|
||||
!memcmp(ae->rep.blob->data, blob, len)) {
|
||||
UNLOCK(Blobs_Lock);
|
||||
@ -160,7 +154,8 @@ Yap_lookupBlob(void *blob, size_t len, void *type0, int *new)
|
||||
b->NextOfPE = NIL;
|
||||
b->KindOfPE = BlobProperty;
|
||||
b->blob_type = type;
|
||||
ae = (AtomEntry *)Yap_AllocCodeSpace(sizeof(AtomEntry)+len+sizeof(size_t));
|
||||
ae =
|
||||
(AtomEntry *)Yap_AllocCodeSpace(sizeof(AtomEntry) + len + sizeof(size_t));
|
||||
if (!ae) {
|
||||
UNLOCK(Blobs_Lock);
|
||||
return NULL;
|
||||
@ -179,9 +174,7 @@ Yap_lookupBlob(void *blob, size_t len, void *type0, int *new)
|
||||
return ae;
|
||||
}
|
||||
|
||||
bool
|
||||
YAP_unify_blob(Term *t, void *blob, size_t len, blob_type_t *type)
|
||||
{
|
||||
bool YAP_unify_blob(Term *t, void *blob, size_t len, blob_type_t *type) {
|
||||
AtomEntry *ae;
|
||||
|
||||
if (!blob)
|
||||
@ -197,9 +190,7 @@ YAP_unify_blob(Term *t, void *blob, size_t len, blob_type_t *type)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
YAP_get_blob(Term t, void **blob, size_t *len, blob_type_t **type)
|
||||
{
|
||||
bool YAP_get_blob(Term t, void **blob, size_t *len, blob_type_t **type) {
|
||||
CACHE_REGS
|
||||
Atom a;
|
||||
Term tt;
|
||||
@ -223,9 +214,7 @@ YAP_get_blob(Term t, void **blob, size_t *len, blob_type_t **type)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void *
|
||||
YAP_blob_data(Atom x, size_t *len, blob_type_t **type)
|
||||
{
|
||||
void *YAP_blob_data(Atom x, size_t *len, blob_type_t **type) {
|
||||
|
||||
if (!IsBlob(x)) {
|
||||
if (IsWideAtom(x)) {
|
||||
@ -233,8 +222,6 @@ YAP_blob_data(Atom x, size_t *len, blob_type_t **type)
|
||||
*len = wcslen(x->WStrOfAE);
|
||||
if (type)
|
||||
|
||||
|
||||
|
||||
*type = &unregistered_blob_atom;
|
||||
return x->WStrOfAE;
|
||||
}
|
||||
@ -251,16 +238,12 @@ YAP_blob_data(Atom x, size_t *len, blob_type_t **type)
|
||||
return x->rep.blob[0].data;
|
||||
}
|
||||
|
||||
void
|
||||
YAP_register_blob_type(blob_type_t *type)
|
||||
{
|
||||
void YAP_register_blob_type(blob_type_t *type) {
|
||||
type->next = (void *)BlobTypes;
|
||||
BlobTypes = (void *)type;
|
||||
}
|
||||
|
||||
blob_type_t*
|
||||
YAP_find_blob_type(const char* name)
|
||||
{
|
||||
blob_type_t *YAP_find_blob_type(const char *name) {
|
||||
AtomEntry *a = RepAtom(Yap_LookupAtom(name));
|
||||
if (!IsBlob(a)) {
|
||||
return &unregistered_blob_atom;
|
||||
@ -268,18 +251,12 @@ YAP_find_blob_type(const char* name)
|
||||
return RepBlobProp(a->PropsOfAE)->blob_type;
|
||||
}
|
||||
|
||||
bool
|
||||
YAP_unregister_blob_type(blob_type_t *type)
|
||||
{
|
||||
bool YAP_unregister_blob_type(blob_type_t *type) {
|
||||
fprintf(stderr, "YAP_unregister_blob_type not implemented yet\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
Yap_install_blobs(void)
|
||||
{
|
||||
|
||||
}
|
||||
void Yap_install_blobs(void) {}
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
@ -112,7 +112,7 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
||||
private final OperationLog mRecentOperations = new OperationLog();
|
||||
|
||||
// The native SQLiteConnection pointer. (FOR INTERNAL USE ONLY)
|
||||
private int mConnectionPtr;
|
||||
private long mConnectionPtr;
|
||||
|
||||
private boolean mOnlyAllowReadOnlyOperations;
|
||||
|
||||
@ -122,45 +122,45 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
||||
// we can ensure that we detach the signal at the right time.
|
||||
private int mCancellationSignalAttachCount;
|
||||
|
||||
private static native int nativeOpen(String path, int openFlags, String label,
|
||||
private static native long nativeOpen(String path, int openFlags, String label,
|
||||
boolean enableTrace, boolean enableProfile);
|
||||
private static native void nativeClose(int connectionPtr);
|
||||
private static native void nativeRegisterCustomFunction(int connectionPtr,
|
||||
private static native void nativeClose(long connectionPtr);
|
||||
private static native void nativeRegisterCustomFunction(long connectionPtr,
|
||||
SQLiteCustomFunction function);
|
||||
private static native void nativeRegisterLocalizedCollators(int connectionPtr, String locale);
|
||||
private static native int nativePrepareStatement(int connectionPtr, String sql);
|
||||
private static native void nativeFinalizeStatement(int connectionPtr, int statementPtr);
|
||||
private static native int nativeGetParameterCount(int connectionPtr, int statementPtr);
|
||||
private static native boolean nativeIsReadOnly(int connectionPtr, int statementPtr);
|
||||
private static native int nativeGetColumnCount(int connectionPtr, int statementPtr);
|
||||
private static native String nativeGetColumnName(int connectionPtr, int statementPtr,
|
||||
private static native void nativeRegisterLocalizedCollators(long connectionPtr, String locale);
|
||||
private static native long nativePrepareStatement(long connectionPtr, String sql);
|
||||
private static native void nativeFinalizeStatement(long connectionPtr, long statementPtr);
|
||||
private static native int nativeGetParameterCount(long connectionPtr, long statementPtr);
|
||||
private static native boolean nativeIsReadOnly(long connectionPtr, long statementPtr);
|
||||
private static native int nativeGetColumnCount(long connectionPtr, long statementPtr);
|
||||
private static native String nativeGetColumnName(long connectionPtr, long statementPtr,
|
||||
int index);
|
||||
private static native void nativeBindNull(int connectionPtr, int statementPtr,
|
||||
private static native void nativeBindNull(long connectionPtr, long statementPtr,
|
||||
int index);
|
||||
private static native void nativeBindLong(int connectionPtr, int statementPtr,
|
||||
private static native void nativeBindLong(long connectionPtr, long statementPtr,
|
||||
int index, long value);
|
||||
private static native void nativeBindDouble(int connectionPtr, int statementPtr,
|
||||
private static native void nativeBindDouble(long connectionPtr, long statementPtr,
|
||||
int index, double value);
|
||||
private static native void nativeBindString(int connectionPtr, int statementPtr,
|
||||
private static native void nativeBindString(long connectionPtr, long statementPtr,
|
||||
int index, String value);
|
||||
private static native void nativeBindBlob(int connectionPtr, int statementPtr,
|
||||
private static native void nativeBindBlob(long connectionPtr, long statementPtr,
|
||||
int index, byte[] value);
|
||||
private static native void nativeResetStatementAndClearBindings(
|
||||
int connectionPtr, int statementPtr);
|
||||
private static native void nativeExecute(int connectionPtr, int statementPtr);
|
||||
private static native long nativeExecuteForLong(int connectionPtr, int statementPtr);
|
||||
private static native String nativeExecuteForString(int connectionPtr, int statementPtr);
|
||||
long connectionPtr, long statementPtr);
|
||||
private static native void nativeExecute(long connectionPtr, long statementPtr);
|
||||
private static native long nativeExecuteForLong(long connectionPtr, long statementPtr);
|
||||
private static native String nativeExecuteForString(long connectionPtr, long statementPtr);
|
||||
private static native int nativeExecuteForBlobFileDescriptor(
|
||||
int connectionPtr, int statementPtr);
|
||||
private static native int nativeExecuteForChangedRowCount(int connectionPtr, int statementPtr);
|
||||
long connectionPtr, long statementPtr);
|
||||
private static native int nativeExecuteForChangedRowCount(long connectionPtr, long statementPtr);
|
||||
private static native long nativeExecuteForLastInsertedRowId(
|
||||
int connectionPtr, int statementPtr);
|
||||
long connectionPtr, long statementPtr);
|
||||
private static native long nativeExecuteForCursorWindow(
|
||||
int connectionPtr, int statementPtr, CursorWindow win,
|
||||
long connectionPtr, long statementPtr, CursorWindow win,
|
||||
int startPos, int requiredPos, boolean countAllRows);
|
||||
private static native int nativeGetDbLookaside(int connectionPtr);
|
||||
private static native void nativeCancel(int connectionPtr);
|
||||
private static native void nativeResetCancel(int connectionPtr, boolean cancelable);
|
||||
private static native int nativeGetDbLookaside(long connectionPtr);
|
||||
private static native void nativeCancel(long connectionPtr);
|
||||
private static native void nativeResetCancel(long connectionPtr, boolean cancelable);
|
||||
|
||||
private static native boolean nativeHasCodec();
|
||||
public static boolean hasCodec(){ return nativeHasCodec(); }
|
||||
@ -902,7 +902,7 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
||||
skipCache = true;
|
||||
}
|
||||
|
||||
final int statementPtr = nativePrepareStatement(mConnectionPtr, sql);
|
||||
final long statementPtr = nativePrepareStatement(mConnectionPtr, sql);
|
||||
try {
|
||||
final int numParameters = nativeGetParameterCount(mConnectionPtr, statementPtr);
|
||||
final int type = DatabaseUtils.getSqlStatementType(sql);
|
||||
@ -1003,7 +1003,7 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
||||
return;
|
||||
}
|
||||
|
||||
final int statementPtr = statement.mStatementPtr;
|
||||
final long statementPtr = statement.mStatementPtr;
|
||||
for (int i = 0; i < count; i++) {
|
||||
final Object arg = bindArgs[i];
|
||||
switch (ExtraUtils.getTypeOfObject(arg)) {
|
||||
@ -1088,7 +1088,7 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
||||
void dumpUnsafe(Printer printer, boolean verbose) {
|
||||
printer.println("Connection #" + mConnectionId + ":");
|
||||
if (verbose) {
|
||||
printer.println(" connectionPtr: 0x" + Integer.toHexString(mConnectionPtr));
|
||||
printer.println(" connectionPtr: 0x" + Long.toHexString(mConnectionPtr));
|
||||
}
|
||||
printer.println(" isPrimaryConnection: " + mIsPrimaryConnection);
|
||||
printer.println(" onlyAllowReadOnlyOperations: " + mOnlyAllowReadOnlyOperations);
|
||||
@ -1194,7 +1194,7 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
||||
return "SQLiteConnection: " + mConfiguration.path + " (" + mConnectionId + ")";
|
||||
}
|
||||
|
||||
private PreparedStatement obtainPreparedStatement(String sql, int statementPtr,
|
||||
private PreparedStatement obtainPreparedStatement(String sql, long statementPtr,
|
||||
int numParameters, int type, boolean readOnly) {
|
||||
PreparedStatement statement = mPreparedStatementPool;
|
||||
if (statement != null) {
|
||||
@ -1241,7 +1241,7 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
||||
|
||||
// The native sqlite3_stmt object pointer.
|
||||
// Lifetime is managed explicitly by the connection.
|
||||
public int mStatementPtr;
|
||||
public long mStatementPtr;
|
||||
|
||||
// The number of parameters that the prepared statement has.
|
||||
public int mNumParameters;
|
||||
@ -1287,7 +1287,7 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen
|
||||
if (statement.mInCache) { // might be false due to a race with entryRemoved
|
||||
String sql = entry.getKey();
|
||||
printer.println(" " + i + ": statementPtr=0x"
|
||||
+ Integer.toHexString(statement.mStatementPtr)
|
||||
+ Long.toHexString(statement.mStatementPtr)
|
||||
+ ", numParameters=" + statement.mNumParameters
|
||||
+ ", type=" + statement.mType
|
||||
+ ", readOnly=" + statement.mReadOnly
|
@ -111,7 +111,19 @@ public class SQLiteCursor extends AbstractWindowedCursor {
|
||||
mQuery = query;
|
||||
|
||||
mColumns = query.getColumnNames();
|
||||
mRowIdColumnIndex = ExtraUtils.findRowIdColumnIndex(mColumns);
|
||||
//mRowIdColumnIndex = ExtraUtils.findRowIdColumnIndex(mColumns);
|
||||
|
||||
// try {
|
||||
// Field field = AbstractCursor.class.getDeclaredField("mRowIdColumnIndex");
|
||||
// field.setInt(this, ExtraUtils.findRowIdColumnIndex(mColumns));
|
||||
// } catch (NoSuchFieldException nfe) {
|
||||
// ;//loaded in system with api level 23 or later
|
||||
// } catch (IllegalAccessException e) {
|
||||
// ;//iae
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// ;//iae
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/**
|
Reference in New Issue
Block a user