Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jtcqB-0006Ed-DH for pljava-dev@arkaria.postgresql.org; Thu, 09 Jul 2020 20:08:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jtcq9-0000k6-A6 for pljava-dev@arkaria.postgresql.org; Thu, 09 Jul 2020 20:08:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jtcq8-0000jI-JN for pljava-dev@lists.postgresql.org; Thu, 09 Jul 2020 20:08:17 +0000 Received: from anastigmatix.net ([68.171.219.55]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jtcq1-0006xU-Js for pljava-dev@lists.postgresql.org; Thu, 09 Jul 2020 20:08:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=anastigmatix.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:Cc:References:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=WjPP11eayKl8xiRCj8Vr+tEcwBHTxEC0Vjk4XiUIt90=; b=QUR1foYlb2qT3TR6TUVlkJLJE2 EcSTGGWjl5E5iz2VVtktwpz3QPDVZ4eXcN+SbUvVZ1nHX7quB6hjCtAbW1jMOjurH6eonSsAs0Zi1 JP0j2jOrdcNGLdoLIlc9/HkzBSApArA9zsy9/rtVmRqwqnbiBusdeaX7m9v1hwbYgi5Mo8bNudt0I rJ6HbnT/NpuUHr29eDi1vtvIX06/qgGQBQTIOdWPZsV/czv8jAWW2GB4Bw579ueDI01mBOFWaRPoT V2T/EP8X5rGgERrw1mP/brzq23SJdIsvaKA+0XNSpnvQGkcu+LD0Q/q1te4kY6SlZyf4AuzJ0Uria 2MFKtZTg==; Received: from [184.19.31.139] (port=53844) by bay.acenet.us with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1jtcpz-0079TO-5l; Thu, 09 Jul 2020 16:08:07 -0400 Subject: Re: PL/Java new build plugin To: Kartik Ohri References: <5F021785.905@anastigmatix.net> <5F021A20.1050903@anastigmatix.net> <5F02340C.7030002@anastigmatix.net> <5F04FA65.5000600@anastigmatix.net> <5F071CFC.9090306@anastigmatix.net> <5F072647.50301@anastigmatix.net> <5F0734AD.7060001@anastigmatix.net> Cc: pljava-dev@lists.postgresql.org From: Chapman Flack X-Enigmail-Draft-Status: N1110 Message-ID: <5F077926.2050806@anastigmatix.net> Date: Thu, 9 Jul 2020 16:08:06 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-OutGoing-Spam-Status: No, score=-95.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bay.acenet.us X-AntiAbuse: Original Domain - lists.postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - anastigmatix.net X-Get-Message-Sender-Via: bay.acenet.us: authenticated_id: chap@anastigmatix.net X-Authenticated-Sender: bay.acenet.us: chap@anastigmatix.net X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 07/09/20 14:45, Kartik Ohri wrote: > Meanwhile, I tried to eliminate the properties file and encountered the > include path not found issue in nar-maven plugin. It took some time to find > the issue but I was able to find the issue. It was that the pg_config > appended a newline character to its output which was being added to the Ah! Good catch. Yes, in your earlier approach with readLine(), that terminator would have been eaten already. It turns out [1] pg_config always ends the line with a single \n (no matter the platform) so that's always what to remove. (Java's readLine could have caused a related sort of problem too; it would be unlikely for the values we care about in this case to end with \r, but if one did, readLine would see the \r followed by the line-ending \n and eat both.) > Moving on, I tried to eliminate the CDATA regex in the pom.xml. I have come > up with a Java version. There are a few caveats like hex escaping is not > supported in Java so these need to be converted to Unicode escaping and so > on. But I do not know how to test the regex and what the purpose of > libjvmdefault is here. Can you explain it and tell how to test this regex > escaping code ? I assume what you mean by a Java version is a Java version of the JavaScript quoteStringForC() function, as the regex it's using is already built on java.util.regex, so should not need much/any revision. (Strictly, the string literals being passed to compile() might have to be checked for any differences between JS and Java string-literal syntax, but nothing is jumping out at me.) There are some regrettable subtleties in the pattern because of differences between what escapes a string-literal understands and what escapes a java,util.regex.Pattern understands: you can see in capture group 2 that \a\f\n\r\t\x0B are all spelled with double-backslashes, which means they survive the string literal (the double backslashes becoming single ones) and the regex compiler literally sees \a\f\n\r\t\x0B and it understands all those forms so that's fine, but the \b does not have its backslash doubled. So the string literal turns it immediately into a real backspace character, which is what the regex compiler sees. \b in the regex language does have a meaning but it's different: it means a word boundary, not a backspace. Of course the purpose of quoteStringForC is "you give me an arbitrary string, I'll give you the exact C language string literal that you need for building that string into a C program." So the output it produces has to be correct according to the rules of C. I wanted to make it as clear as I could by breaking the regex into three lines (capture group 1, group 2, and groups 3,4 which go together) and organizing the function logic the same way. Group 1 takes care of the things that only need a \ in front to be escaped for C: \ itself, ", and a ? if it could look like part of a C trigraph [2]. Really, C will turn \? to ? anywhere, but to avoid cluttering the string with backslashes, it is only necessary to find sequences like ??[=(/)'-] and \ just one of the ? characters, to prevent the sequence being seen as a trigraph. Group 2 is for characters known by special escape sequences; most of those are the same in C and Java, but C has \a and \v and Java doesn't (though java.util.regex does know \a), so those have to be spelled differently for Java (Unicode or octal would work). Group 3 just catches any other control character and turns it into a C \xnn escape. Group 4 is only to detect if the control character is followed by a hexdigit. That's necessary because C's \x escape will keep eating as many hexdigits as it sees, so you can't just turn a character into a \xnn if what follows it is also a hexdigit. You can turn it into \xnn"" which essentially ends one string literal and starts another one. C always joins together adjacent string literals, so that solves the problem. While general-purpose, the first reason to have a quoteStringForC function was so a person building PL/Java could add -Dpljava.libjvmdefault=some_path on the Maven command line, and have "some_path" properly escaped be built into the C code so it becomes the default for pljava.libjvm_location and there's no need to fuss with that GUC in PostgreSQL to make PL/Java work, ... which ends up, on Windows, being a challenging test of how reliably Java passes complicated argument values to the C compiler process ... a test the existing ProcessBuilder implementation does not pass. Regards, -Chap [1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/bin/pg_config/pg_config.c;h=5279e7f#l124 [2] https://en.wikibooks.org/wiki/C_Programming/C_trigraph