From a3ee259f9f93e5f8b3b684bb12d68feaaa98bf92 Mon Sep 17 00:00:00 2001 From: Chapman Flack Date: Wed, 6 Sep 2023 22:40:24 -0400 Subject: [PATCH] Quiet warnings about casts of function types It is easy enough to stop casting _PgObject_pureVirtualCalled to incompatible function types, as it makes modern compilers suspicious, and was only done in three places anyway. --- pljava-so/src/main/c/PgObject.c | 7 +--- pljava-so/src/main/c/type/Type.c | 33 ++++++++++++++++--- .../src/main/include/pljava/PgObject_priv.h | 20 +++++------ 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/pljava-so/src/main/c/PgObject.c b/pljava-so/src/main/c/PgObject.c index c34159323..fbf311fc7 100644 --- a/pljava-so/src/main/c/PgObject.c +++ b/pljava-so/src/main/c/PgObject.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2020 Tada AB and other contributors, as listed below. + * Copyright (c) 2004-2023 Tada AB and other contributors, as listed below. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the The BSD 3-Clause License @@ -66,11 +66,6 @@ const char* PgObjectClass_getName(PgObjectClass self) return self->name; } -void _PgObject_pureVirtualCalled(PgObject object) -{ - ereport(ERROR, (errmsg("Pure virtual method called"))); -} - char* PgObject_getClassName(jclass cls) { jstring jstr; diff --git a/pljava-so/src/main/c/type/Type.c b/pljava-so/src/main/c/type/Type.c index 188e86e78..d3dcc50a5 100644 --- a/pljava-so/src/main/c/type/Type.c +++ b/pljava-so/src/main/c/type/Type.c @@ -1029,6 +1029,31 @@ void Type_initialize(void) initializeTypeBridges(); } +static Type unimplementedTypeObtainer(Oid typeId); +static jvalue unimplementedDatumCoercer(Type, Datum); +static Datum unimplementedObjectCoercer(Type, jobject); + +static Type unimplementedTypeObtainer(Oid typeId) +{ + ereport(ERROR, + (errmsg("no type obtainer registered for type oid %ud", typeId))); + pg_unreachable(); +} + +static jvalue unimplementedDatumCoercer(Type t, Datum d) +{ + ereport(ERROR, + (errmsg("no datum coercer registered for type oid %ud", t->typeId))); + pg_unreachable(); +} + +static Datum unimplementedObjectCoercer(Type t, jobject o) +{ + ereport(ERROR, + (errmsg("no object coercer registered for type oid %ud", t->typeId))); + pg_unreachable(); +} + /* * Abstract Type constructor */ @@ -1047,8 +1072,8 @@ TypeClass TypeClass_alloc2( self->javaTypeName = ""; self->javaClass = 0; self->canReplaceType = _Type_canReplaceType; - self->coerceDatum = (DatumCoercer)_PgObject_pureVirtualCalled; - self->coerceObject = (ObjectCoercer)_PgObject_pureVirtualCalled; + self->coerceDatum = unimplementedDatumCoercer; + self->coerceObject = unimplementedObjectCoercer; self->createArrayType = _Type_createArrayType; self->invoke = _Type_invoke; self->getSRFCollector = _Type_getSRFCollector; @@ -1137,9 +1162,7 @@ static void _registerType( void Type_registerType(const char* javaTypeName, Type type) { - _registerType( - type->typeId, javaTypeName, type, - (TypeObtainer)_PgObject_pureVirtualCalled); + _registerType(type->typeId, javaTypeName, type, unimplementedTypeObtainer); } void Type_registerType2( diff --git a/pljava-so/src/main/include/pljava/PgObject_priv.h b/pljava-so/src/main/include/pljava/PgObject_priv.h index b179a3b84..4c116b202 100644 --- a/pljava-so/src/main/include/pljava/PgObject_priv.h +++ b/pljava-so/src/main/include/pljava/PgObject_priv.h @@ -1,10 +1,14 @@ /* - * Copyright (c) 2004, 2005, 2006 TADA AB - Taby Sweden - * Distributed under the terms shown in the file COPYRIGHT - * found in the root folder of this project or at - * http://eng.tada.se/osprojects/COPYRIGHT.html + * Copyright (c) 2004-2023 Tada AB and other contributors, as listed below. * - * @author Thomas Hallgren + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the The BSD 3-Clause License + * which accompanies this distribution, and is available at + * http://opensource.org/licenses/BSD-3-Clause + * + * Contributors: + * Tada AB + * Chapman Flack */ #ifndef __pljava_PgObject_priv_h #define __pljava_PgObject_priv_h @@ -54,12 +58,6 @@ struct PgObject_ PgObjectClass m_class; }; -/* - * Internal bogus. Someone forgot to replace a function - * pointer somewhere. - */ -extern void _PgObject_pureVirtualCalled(PgObject self); - /* * Throw an exception indicating that wanted member could not be * found.