From: books at ejurka.com (Kris Jurka) Date: Thu, 24 May 2007 13:10:07 -0400 (EDT) Subject: [Pljava-dev] Build against 8.3 Message-ID: Here's a patch to make pljava build against 8.3 cvs. It was broken by these two patches: Change array coercion: https://projects.commandprompt.com/public/pgsql/changeset/27905 This may or may not be an issue for pljava. From a brief glance at the pljava source code it appears that pljava was already doing element at a time coercion for array elements, rather than doing it all in one go, so I've changed this to bail out if a whole array coercion is required. If pljava really is expecting whole array coercion to work, some more infrastructure in Coerce is needed. Use smaller varlena headers: https://projects.commandprompt.com/public/pgsql/changeset/27979 This just requires using slightly different macros to access things. Kris Jurka -------------- next part -------------- ? 83.patch Index: src/C/pljava/type/Array.c =================================================================== RCS file: /usr/local/cvsroot/pljava/org.postgresql.pljava/src/C/pljava/type/Array.c,v retrieving revision 1.3 diff -c -r1.3 Array.c *** src/C/pljava/type/Array.c 12 May 2006 06:53:23 -0000 1.3 --- src/C/pljava/type/Array.c 24 May 2007 17:01:16 -0000 *************** *** 60,66 **** --- 60,70 ---- #endif MemoryContextSwitchTo(currCtx); + #if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 3) ARR_SIZE(v) = nBytes; + #else + SET_VARSIZE(v, nBytes); + #endif ARR_NDIM(v) = 1; ARR_ELEMTYPE(v) = elemType; *((int*)ARR_DIMS(v)) = nElems; *************** *** 102,109 **** --- 106,120 ---- jvalue obj = Type_coerceDatum(elemType, value); JNI_setObjectArrayElement(objArray, idx, obj.l); JNI_deleteLocalRef(obj.l); + + #if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 3) values = att_addlength(values, elemLength, PointerGetDatum(values)); values = (char*)att_align(values, elemAlign); + #else + values = att_addlength_datum(values, elemLength, PointerGetDatum(values)); + values = (char*)att_align_nominal(values, elemAlign); + #endif + } #endif } Index: src/C/pljava/type/String.c =================================================================== RCS file: /usr/local/cvsroot/pljava/org.postgresql.pljava/src/C/pljava/type/String.c,v retrieving revision 1.17 diff -c -r1.17 String.c *** src/C/pljava/type/String.c 12 May 2006 21:59:54 -0000 1.17 --- src/C/pljava/type/String.c 24 May 2007 17:01:16 -0000 *************** *** 145,151 **** --- 145,155 ---- /* Allocate and initialize the text structure. */ result = (text*)palloc(varSize); + #if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 2) VARATT_SIZEP(result) = varSize; /* Total size of structure, not just data */ + #else + SET_VARSIZE(result, varSize); /* Total size of structure, not just data */ + #endif memcpy(VARDATA(result), denc, dencLen); /* pg_do_encoding_conversion will return the source argument Index: src/C/pljava/type/Type.c =================================================================== RCS file: /usr/local/cvsroot/pljava/org.postgresql.pljava/src/C/pljava/type/Type.c,v retrieving revision 1.35 diff -c -r1.35 Type.c *** src/C/pljava/type/Type.c 15 May 2006 21:52:26 -0000 1.35 --- src/C/pljava/type/Type.c 24 May 2007 17:01:16 -0000 *************** *** 101,106 **** --- 101,107 ---- Type coerce; Oid fromOid = other->typeId; Oid toOid = self->typeId; + bool arrayCoerce = false; if(self->inCoercions != 0) { *************** *** 109,121 **** --- 110,131 ---- return coerce; } + #if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 3) if (!find_coercion_pathway(toOid, fromOid, COERCION_EXPLICIT, &funcId)) + #else + if (!find_coercion_pathway(toOid, fromOid, COERCION_EXPLICIT, &funcId, &arrayCoerce)) + #endif { elog(ERROR, "no conversion function from %s to %s", format_type_be(fromOid), format_type_be(toOid)); } + if (arrayCoerce) + { + elog(ERROR, "can't coerce array types"); + } + if(funcId == InvalidOid) /* * Binary compatible type. No need for a special coercer *************** *** 136,141 **** --- 146,152 ---- Type coercer; Oid fromOid = self->typeId; Oid toOid = other->typeId; + bool arrayCoerce; if(self->outCoercions != 0) { *************** *** 150,162 **** --- 161,182 ---- */ return self; + #if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 3) if (!find_coercion_pathway(toOid, fromOid, COERCION_EXPLICIT, &funcId)) + #else + if (!find_coercion_pathway(toOid, fromOid, COERCION_EXPLICIT, &funcId, &arrayCoerce)) + #endif { elog(ERROR, "no conversion function from %s to %s", format_type_be(fromOid), format_type_be(toOid)); } + if (arrayCoerce) + { + elog(ERROR, "can't coerce array types"); + } + if(self->outCoercions == 0) self->outCoercions = HashMap_create(7, GetMemoryChunkContext(self)); Index: src/C/pljava/type/byte_array.c =================================================================== RCS file: /usr/local/cvsroot/pljava/org.postgresql.pljava/src/C/pljava/type/byte_array.c,v retrieving revision 1.17 diff -c -r1.17 byte_array.c *** src/C/pljava/type/byte_array.c 11 May 2006 21:59:19 -0000 1.17 --- src/C/pljava/type/byte_array.c 24 May 2007 17:01:16 -0000 *************** *** 40,46 **** --- 40,50 ---- int32 byteaSize = length + VARHDRSZ; bytes = (bytea*)palloc(byteaSize); + #if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 3) VARATT_SIZEP(bytes) = byteaSize; + #else + SET_VARSIZE(bytes, byteaSize); + #endif JNI_getByteArrayRegion((jbyteArray)byteArray, 0, length, (jbyte*)VARDATA(bytes)); } else if(JNI_isInstanceOf(byteArray, s_BlobValue_class)) *************** *** 51,57 **** --- 55,65 ---- byteaSize = (int32)(length + VARHDRSZ); bytes = (bytea*)palloc(byteaSize); + #if (PGSQL_MAJOR_VER == 8 && PGSQL_MINOR_VER < 3) VARATT_SIZEP(bytes) = byteaSize; + #else + SET_VARSIZE(bytes, byteaSize); + #endif byteBuffer = JNI_newDirectByteBuffer((void*)VARDATA(bytes), length); if(byteBuffer != 0)