[fpc-pascal] Custom NewInstance allocator
Tony Whyman
tony.whyman at mccallumwhyman.com
Wed Jun 5 10:26:01 CEST 2024
You may find that compiling with "{$OBJECTCHECKS OFF}" allows your
program to run and as long as your object has no virtual methods nor
does it require its fields to be initialised to zero, then it might even
give a useful result - otherwise, you also need to call InitInstance.
On 04/06/2024 09:54, Hairy Pixels via fpc-pascal wrote:
> In the manual it at https://www.freepascal.org/docs-html/ref/refse38.html it says "Calling the constructor will provoke a call to the virtual class method NewInstance, which, in its default implementation, calls GetMem, to allocate enough space to hold the class instance data, and then zeroes out the memory."
>
> I'm trying this like below but it crashes. Is this correct? The fact NewInstance returns TObject instead of Pointer doesn't make sense to me and suggests this isn't correct.
>
> class function TDataObject.NewInstance: TObject;
> begin
> result := TObject(GetMem(InstanceSize));
> end;
>
> Regards,
> Ryan Joseph
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
> Return-Path: <tony at mccallumwhyman.com>
> Received: from mail3.mwassocs.co.uk (mail3.mwassocs.co.uk [IPv6:2a00:da00:1800:8207:0:0:0:1])
> by olympus.mwassocs.co.uk (8.17.1.9/8.17.1.9/Debian-2) with ESMTP id 454925ln001681
> for <tony at olympus.mwassocs.co.uk>; Tue, 4 Jun 2024 10:02:13 +0100
> Authentication-Results: mail3.mwassocs.co.uk;
> dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=QYUmS2JD;
> dkim-atps=neutral
> Received: from mwa2023.mwassocs.co.uk (localhost [127.0.0.1])
> by mail3.mwassocs.co.uk (8.17.1.9/8.17.1.9/Debian-2) with ESMTPS id 4547BXql783561
> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO)
> for <tony at olympus.mwassocs.co.uk>; Tue, 4 Jun 2024 07:11:33 GMT
> Received: (from tony at localhost)
> by mwa2023.mwassocs.co.uk (8.17.1.9/8.17.1.9/Submit) id 4547BXAJ783560
> for tony at olympus.mwassocs.co.uk; Tue, 4 Jun 2024 07:11:33 GMT
> Received: from mail-wr1-x438.google.com (mail-wr1-x438.google.com [IPv6:2a00:1450:4864:20:0:0:0:438])
> by mail3.mwassocs.co.uk (8.17.1.9/8.17.1.9/Debian-2) with ESMTPS id 4547BUZr783552
> (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=FAIL)
> for <tony.whyman at mccallumwhyman.com>; Tue, 4 Jun 2024 07:11:31 GMT
> Received: by mail-wr1-x438.google.com with SMTP id ffacd0b85a97d-35e7d4f4243sf466477f8f.1
> for <tony.whyman at mccallumwhyman.com>; Tue, 04 Jun 2024 00:11:31 -0700 (PDT)
> ARC-Seal: i=2; a=rsa-sha256; t=1717485084; cv=pass;
> d=google.com; s=arc-20160816;
> b=z3rh7siQ5LSx2gqOn6Mj2et1j7nRVra3IEAIQP3K+wiLPpUXI7Tr01d/nylJ1HaFGg
> TKMLH/7nimkBSESeSME1HlbXG/UZ3e0eDyQJiX/+9xPvWikDEfUquqMOn/mNiqw7e0Xd
> +pZECf4Ja5GvrNIdwhvWwE19XAy47TOFoHfh8g+88q2NBW4fHsKwqVJKpqfi9Ph4V+hq
> u28lFheObpB69LUI3OFdETpRigKxoVZmMBYY1yGyfHTzR2shJuyPqpj/rx6Ltbp2QHKu
> YPBSqS9MC+jWyvogY3jalcSBCQOmlTMB2lS5dkJCSFv/U9c+waOqTUnyq9NKuUe13Nqz
> IrTA==
> ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
> h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
> :list-id:mailing-list:precedence:reply-to:content-transfer-encoding
> :in-reply-to:organization:from:content-language:references:to
> :subject:user-agent:mime-version:date:dkim-filter:message-id
> :dkim-signature;
> bh=VKy8eSS7uMgsfe7Vrkk4zMlxj8C0nXu9E/pOm4K0rMk=;
> fh=GfuQ6oQp7YQ6NU+kiZIdgjvraiHPaEC7d1yzxmt/vc4=;
> b=0lhn/6GQITvaXqpbaKK84AIaB2cjpSaDetDLj6vUj73e+DeHzE4+kqx30HeD4RUwhZ
> J8nfrgcc/XKIDNflRql2my0pBwCNIatSqJOWvZNkvdt1UM62LwnaAb4o0nG8e7zb7E6r
> VGEPv5RotVFDMnrtRhED3pKlLKQkyqBGG6yb0IqUtkyCB/BcBAjhO6sYbO3QGcRs2wPW
> ZAEb/oSv5DTEO3TYDSHjAwyQ4E/q9WjDtd954my1tHUvaXPbzDnR8YvaTXQ6a1wktIDI
> ZqGD68N9Fmcf7KsICOqThJrRERmgdzP6247CcqS0PN5CUDoaGMo604eJbDbSpIU6Rymo
> 0Nrg==;
> darn=mccallumwhyman.com
> ARC-Authentication-Results: i=2; gmr-mx.google.com;
> dkim=pass header.i=@lawinegevaar.nl header.s=protagio header.b=xOXklYHI;
> spf=pass (google.com: domain of mark at lawinegevaar.nl designates 2a00:51c0::5fd7:bd14 as permitted sender) smtp.mailfrom=mark at lawinegevaar.nl;
> dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=lawinegevaar.nl
> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
> d=googlegroups.com; s=20230601; t=1717485084; x=1718089884; darn=mccallumwhyman.com;
> h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
> :list-id:mailing-list:precedence:reply-to
> :x-original-authentication-results:x-original-sender
> :content-transfer-encoding:in-reply-to:organization:from
> :content-language:references:to:subject:user-agent:mime-version:date
> :dkim-filter:message-id:from:to:cc:subject:date:message-id:reply-to;
> bh=VKy8eSS7uMgsfe7Vrkk4zMlxj8C0nXu9E/pOm4K0rMk=;
> b=QYUmS2JD9igEh2GCuLqex1YPMWgL7uB576WNGf6qDn+fZKlOid4d7qs1PgHY+W68Vk
> +AF5wYCuH+KjgYsy8e8K2DBOkBbL7QMUmUq2iXO4uTsSTbN2qmebjobxzZUB/awbrNkc
> DpSv4Z24x493UjN5hhGLCyrM+pRxniveBouMNV3Qc7+QoGD49+CndPN57Plx4u1nTLuJ
> UAXkXR++eZpsJHpogQmUJk5WLG8KMyaWQUZnkFNEu+Jxyh+C01AtJDmRV0NmLfv0YS2L
> achfM5H9S9269rggngPHnt/8+r+oS83GsUlsaKNw5pUqEPW2zT0YEC56r84HP3++p1jU
> +OQA==
> X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
> d=1e100.net; s=20230601; t=1717485084; x=1718089884;
> h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
> :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to
> :x-original-authentication-results:x-original-sender
> :content-transfer-encoding:in-reply-to:organization:from
> :content-language:references:to:subject:user-agent:mime-version:date
> :dkim-filter:message-id:x-beenthere:x-gm-message-state:from:to:cc
> :subject:date:message-id:reply-to;
> bh=VKy8eSS7uMgsfe7Vrkk4zMlxj8C0nXu9E/pOm4K0rMk=;
> b=s+pDimf/3IV8IsmC5TsqIeLKlKJwS5TFxhui3FTG63TZ+tDydvw4bnNjhH0iT1WTwn
> d71Oh9cANHXmnyIJqzSMo1nO/rj0vWq6uIWLa1ZMjBQEkWWp58AhFnekjeAA+dL+uIan
> zwxCpqeiVQxSLJvuk4MiTbvHuu9IsOgTLjE/j6m+RZ6CltGh6M/gJq0QTHhIhOoMPScQ
> LwruJb8SIuiwqie5Z4VHRiqzGGl9ZiJgbs/6Gdyf/qmCgn3tqvFVA10HzADsN1QJgBTS
> 8WS8DLepmSf5KPE/WxzfxfjQ6bEGYw7tm5hEpcW6ESMo+c5ZSwfj9J17z/zqrKvKeIAw
> O54Q==
> X-Forwarded-Encrypted: i=2; AJvYcCUbJ7zImHgTvOY/CvPkA3YTLROjZMH9+/fOSNvvgakuyDOpooN3WhxGjzd6s3IafyrHw7YYfQMfJVk19f8Kj3+2/HLHuQuIodxV4ITWyBY=
> X-Gm-Message-State: AOJu0YwR3LgUc3P7D0D1NwX+r7T6tG+KXRvnq9PQcf3vhL3kvXP6YxHo
> Mvmc5l/C+UxBEXF/ZBYquuqq3jsGWukqPWcE0wgenpqOmFVZLvB0
> X-Google-Smtp-Source: AGHT+IGO+TgM+9nhzRypTegXKfboZ2tjhVfRxSoBnMbPXIY4R22AxERsWxoRp0gAWBBNpvVsMHN0Ow==
> X-Received: by 2002:a5d:6e5e:0:b0:354:faf4:fa87 with SMTP id ffacd0b85a97d-35e0f2590e5mr6110059f8f.3.1717485084015;
> Tue, 04 Jun 2024 00:11:24 -0700 (PDT)
> X-BeenThere: firebird-devel at googlegroups.com
> Received: by 2002:a5d:670d:0:b0:359:7b15:59e6 with SMTP id ffacd0b85a97d-35dbf8e1891ls1138330f8f.2.-pod-prod-06-eu;
> Tue, 04 Jun 2024 00:11:22 -0700 (PDT)
> X-Received: by 2002:adf:f212:0:b0:354:fb2a:7da8 with SMTP id ffacd0b85a97d-35e0f26e7femr8277131f8f.20.1717485081908;
> Tue, 04 Jun 2024 00:11:21 -0700 (PDT)
> ARC-Seal: i=1; a=rsa-sha256; t=1717485081; cv=none;
> d=google.com; s=arc-20160816;
> b=0jYbhWGukb2FBWfp871tAg7gsm05GLIe4kPRaEkGvBluE6sSrAV2Ek6R1EkCaMBtEH
> nskx99rb50CGmWj+YVGK7+NggqspltZ+F3ltDf7LzVXH2znr90sDVMkzAtb2Wc8TNqlf
> Q9WkYFP0EdWw1hhIbSKHmYuRBlJALGIEr9iTCshP/YZLGwh226mTGEQX371KPsJmKidW
> TIhbKpA+I1Gd0et+7HllUdy9cltEo3x+Y6Em/fv3bRVE8dXn0t0nK5dD/ASlZWcOSIFs
> BUz59zWOflfM5yRzX8WzTpm66a6AErTZHM93+wy3iBnlRLVmyaYYtrxwJtRJllZp2OCd
> QDAA==
> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
> h=content-transfer-encoding:in-reply-to:organization:from
> :content-language:references:to:subject:user-agent:mime-version:date
> :dkim-signature:dkim-filter:message-id;
> bh=xsj+P5Hbtlxg9a+C5ARS1vHMPhhnGqY7nUQqi4OzgX0=;
> fh=KEmKjYo6I4tnlNlyyVLpK9R/qyiCMzQnYmv7XX42lns=;
> b=tgshVQqqXSaArO2pcE+WDCMQXCd+x5eFYijoiVZPveikv6LUhMf4TgNlGFsEzlkutj
> xgWVS9/N0luJPU3+WGK2yOuEJDlhm31BFYthFXU/Ww+/2euWRq73HG3R3FhZfTk7KBjV
> 6FZeg4bnKvTOJnAMfdbM/K7Si7iF3hr+AeT+lEDz4luZIv6uvab/xBv+Ttt14VLN6Y20
> XSE73/xLdPEjHPkIZ7+8a7ZFgl9CC5vVC+dyDV3hXrK8eQpvm5kr4Z79svhF78M9t1/u
> xbidWpj6ecYmDc0pUyuf67jdGrq2E2SM+z3UpT/Hgz/lCzwa/I8Ad/Vawf5aSROmx2rQ
> NtRQ==;
> dara=google.com
> ARC-Authentication-Results: i=1; gmr-mx.google.com;
> dkim=pass header.i=@lawinegevaar.nl header.s=protagio header.b=xOXklYHI;
> spf=pass (google.com: domain of mark at lawinegevaar.nl designates 2a00:51c0::5fd7:bd14 as permitted sender) smtp.mailfrom=mark at lawinegevaar.nl;
> dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=lawinegevaar.nl
> Received: from smtp2.protagio.nl (smtp2.protagio.nl. [2a00:51c0::5fd7:bd14])
> by gmr-mx.google.com with ESMTPS id ffacd0b85a97d-35dd0646e78si215661f8f.7.2024.06.04.00.11.21
> for <firebird-devel at googlegroups.com>
> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
> Tue, 04 Jun 2024 00:11:21 -0700 (PDT)
> Received-SPF: pass (google.com: domain of mark at lawinegevaar.nl designates 2a00:51c0::5fd7:bd14 as permitted sender) client-ip=2a00:51c0::5fd7:bd14;
> Message-ID: <fb3b3487-0883-422e-9d7d-f2460ae6a445 at lawinegevaar.nl>
> DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.protagio.nl 8D10127A
> Date: Tue, 4 Jun 2024 09:11:20 +0200
> MIME-Version: 1.0
> User-Agent: Mozilla Thunderbird
> Subject: Re: [firebird-devel] Schemas in Firebird - SYSTEM schema, migration
> from old versions and plugin objects
> To: firebird-devel at googlegroups.com
> References: <2fe615f0-2afc-44f1-a7d0-941cf6c79cb5 at gmail.com>
> <674f20a3-e2fe-4309-9017-000369bf3637 at lawinegevaar.nl>
> <b95e737f-92fa-41a2-bb63-8f6a775fccfc at gmail.com>
> <9e23853f-5afc-4c52-997d-2f452221996a at lawinegevaar.nl>
> <5cef6a31-e1ff-4a15-8380-6b7d26c202d7n at googlegroups.com>
> Content-Language: en-US
> From: "'Mark Rotteveel' via firebird-devel" <firebird-devel at googlegroups.com>
> Organization: Me, myself and I
> In-Reply-To: <5cef6a31-e1ff-4a15-8380-6b7d26c202d7n at googlegroups.com>
> Content-Type: text/plain; charset="UTF-8"; format=flowed
> X-Original-Sender: mark at lawinegevaar.nl
> X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass
> header.i=@lawinegevaar.nl header.s=protagio header.b=xOXklYHI; spf=pass
> (google.com: domain of mark at lawinegevaar.nl designates 2a00:51c0::5fd7:bd14
> as permitted sender) smtp.mailfrom=mark at lawinegevaar.nl; dmarc=pass
> (p=REJECT sp=REJECT dis=NONE) header.from=lawinegevaar.nl
> X-Original-From: Mark Rotteveel <mark at lawinegevaar.nl>
> Reply-To: firebird-devel at googlegroups.com
> Precedence: list
> Mailing-list: list firebird-devel at googlegroups.com; contact firebird-devel+owners at googlegroups.com
> List-ID: <firebird-devel.googlegroups.com>
> X-Spam-Checked-In-Group: firebird-devel at googlegroups.com
> X-Google-Group-Id: 664696289522
> List-Post: <https://groups.google.com/group/firebird-devel/post>, <mailto:firebird-devel at googlegroups.com>
> List-Help: <https://groups.google.com/support/>, <mailto:firebird-devel+help at googlegroups.com>
> List-Archive: <https://groups.google.com/group/firebird-devel
> List-Subscribe: <https://groups.google.com/group/firebird-devel/subscribe>, <mailto:firebird-devel+subscribe at googlegroups.com>
> List-Unsubscribe: <mailto:googlegroups-manage+664696289522+unsubscribe at googlegroups.com>,
> <https://groups.google.com/group/firebird-devel/subscribe>
> X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,
> DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,
> DMARC_PASS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,
> SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.0
> X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on
> mwa2023.mwassocs.co.uk
> Content-Transfer-Encoding: 8bit
> X-MIME-Autoconverted: from quoted-printable to 8bit by mail3.mwassocs.co.uk id 4547BUZr783552
>
> On 03/06/2024 16:11, Ð”ÐµÐ½Ð¸Ñ Ð¡Ð¸Ð¼Ð¾Ð½Ð¾Ð² wrote:
>> Why not make the default schema PUBLIC, like Postgresql does?
>>
>> Let all system tables be located in the SYSTEM schema. There are many
>> ways to solve backward compatibility problems, for example making all
>> current RDB$ tables views on the SYSTEM table, or aliases of objects
>> from the SYSTEM schema.
> In PostgreSQL, the system tables do not reside in public, but in pg_catalog.
>
> Mark
More information about the fpc-pascal
mailing list