Closed harisont closed 1 year ago
Looks good! There are three things that I noticed:
To release the memory correctly, implement the finalize for the PGF class. From the method call pgf_free_revision
If you get err.type == PGF_EXN_OTHER_ERROR then just clean up any allocated resources and return NULL. This error is used when the runtime of the host language, e.g. Java or Python, has detected an error and then we must abort the whole operation. If that happens the host runtime has already generated the exception and we don't want to generate a new one. This is probably wrong in Python as well. I will take a look.
You can't use (*env)->NewStringUTF(env,txt->text). There are two reasons. First using txt->text ignores the size field which means that the call will fail if the string contains the zero character. Second, Java is using a modified version of UTF-8 while we use the standard one. You should implement your own conversions to and from UTF-8. gu2j_string and j2gu_string should be good starting points. Java is using UTF-16 for storing text and NewStringUTF is converting to a modified UTF-8. Since we want the conversion to work in a different way, we should not use NewStringUTF to avoid double conversion. Instead use NewString, GetStringLength and GetStringChars.
On Fri, 24 Sept 2021 at 17:02, Arianna Masciolini @.***> wrote:
Hi, I'm getting started with the Java bindings for the new runtime and so far it seems I got readPGF(path) and getAbstractName working.
Even though this is still very little, I'm opening this pull request so that maybe @krangelov https://github.com/krangelov can tell me how I should go about in terms of memory management in what I already implemented, so that I can continue along those lines (I have not noticed any strange behavior so far, but I'd be surprised if there were no memory issues, I don't really have a clue about that, and especially not in the context of the JNI).
You can view, comment on, or merge this pull request online at:
https://github.com/GrammaticalFramework/gf-core/pull/133 Commit Summary
- create readme for java bindings https://github.com/GrammaticalFramework/gf-core/pull/133/commits/a54d6d408e5ebf63573421336c2cc1909ca95c78
- minor changes https://github.com/GrammaticalFramework/gf-core/pull/133/commits/5d6191cd9263f5fbfdb8aef1878fe5b00154d046
- setup for junit tests and a first test https://github.com/GrammaticalFramework/gf-core/pull/133/commits/70c2c0bf39fb0c92d54c66909d0212b1ca1652db
- valid test case for readPGF https://github.com/GrammaticalFramework/gf-core/pull/133/commits/5d38bdb01bf0ec12e941060d0c737bcc2518b522
- setup for junit tests and a first test https://github.com/GrammaticalFramework/gf-core/pull/133/commits/51e127f7ca586e742508c2fe0bd94d50e01dfa3b
- Merge branch 'GrammaticalFramework:majestic' into majestic https://github.com/GrammaticalFramework/gf-core/pull/133/commits/a42a40c28b9cbd81dc7dfb3f896bf76b0100c8ab
- WIP readPGF from file https://github.com/GrammaticalFramework/gf-core/pull/133/commits/690b3ad879d0232b931571e20a114b73e990c9ce
- Merge branch 'majestic' of https://github.com/harisont/gf-core into majestic https://github.com/GrammaticalFramework/gf-core/pull/133/commits/6165dfc6fdbb040ed1991ef0f5c898234b0d6cb2
- improved error handling https://github.com/GrammaticalFramework/gf-core/pull/133/commits/b976896c85750ca21b2df9abe45bf18f94ba6d84
- rm gu library from makefile https://github.com/GrammaticalFramework/gf-core/pull/133/commits/b2b87aa15449407e6b5a0523d93d2b9bc837d7b4
- update running java tests instructions https://github.com/GrammaticalFramework/gf-core/pull/133/commits/3b7b740b5a3759410976c5c63133e3c86f47d835
- updated system error test https://github.com/GrammaticalFramework/gf-core/pull/133/commits/52a2b21b09e2f55dc8d79fcca8bf70128f5582a3
- commented out gu2j_string_capit but we can probably get rid of it entirely https://github.com/GrammaticalFramework/gf-core/pull/133/commits/d4a5dfd167136a602b31de338e293c8f648bac60
- first compiling version of jpgf.c; it passed the tests but may be wrong in other ways https://github.com/GrammaticalFramework/gf-core/pull/133/commits/81876bdd8d8d8e0b3d34b79469c9e45262e8ca3b
- updated PGF class https://github.com/GrammaticalFramework/gf-core/pull/133/commits/3f6085c3a4fdac1351a2e79009f1dc9895b5642c
- all tests for readPGF (from file) https://github.com/GrammaticalFramework/gf-core/pull/133/commits/70e3b31924eec7b089c3afd9e79f7754025dd2d2
- change test naming conventions https://github.com/GrammaticalFramework/gf-core/pull/133/commits/d0233a4d7a72c199405494d27100474ef75a6ada
- add test for getAbstractName https://github.com/GrammaticalFramework/gf-core/pull/133/commits/61239318141146e960f0cb77aa09eff3b5422676
- fix the dumbest error in tests https://github.com/GrammaticalFramework/gf-core/pull/133/commits/ef124d2b4c30d6719aaca84a596cf7226330d554
- working readPGF (from file) and getAbstractName https://github.com/GrammaticalFramework/gf-core/pull/133/commits/997d5f4f809624691b1e03149ad8db56e0aa6de3
- cleanup https://github.com/GrammaticalFramework/gf-core/pull/133/commits/2e145dd45f31253d853e7dc231c93c882555a540
File Changes
- M src/runtime/java/Makefile https://github.com/GrammaticalFramework/gf-core/pull/133/files#diff-992ade8165ffdc4d4bc7471e9ee20b8163ca36cbfd7163a79bcbe4511338116c (2)
- A src/runtime/java/README.md https://github.com/GrammaticalFramework/gf-core/pull/133/files#diff-6134d467ebe9949ffb3b42585fe49394bcc487796679bd98d7e832f377775f83 (43)
- D src/runtime/java/Test.java https://github.com/GrammaticalFramework/gf-core/pull/133/files#diff-7546dc211b307d5892ae2834f94e2bbb7b95405cc21e7d09ecfa237fca7ef9f1 (34)
- A src/runtime/java/TestBasic.java https://github.com/GrammaticalFramework/gf-core/pull/133/files#diff-7b2671c4dc55c2c462cf8b9de942aed2664045fb2a008cd888d64985697019b7 (65)
- M src/runtime/java/jni_utils.c https://github.com/GrammaticalFramework/gf-core/pull/133/files#diff-8ff4685f9049266be4ce7c5b59abdd3d20025b858c47c25776bf46ae11f19a4b (16)
- M src/runtime/java/jni_utils.h https://github.com/GrammaticalFramework/gf-core/pull/133/files#diff-56e863c2da7e997ac6062463cb3d4db2ad1bfa23556d4c4761bdc8223adaa1e4 (29)
- M src/runtime/java/jpgf.c https://github.com/GrammaticalFramework/gf-core/pull/133/files#diff-dd8b035202aa8782d84f2c014af8b9cf9ba926d3d62d20409a7a7997270db3dd (75)
- M src/runtime/java/org/grammaticalframework/pgf/PGF.java https://github.com/GrammaticalFramework/gf-core/pull/133/files#diff-ca1eb15441008e8371909f2f5d49c21c6abaf9d5340356a03339b477e1dbc560 (10)
Patch Links:
- https://github.com/GrammaticalFramework/gf-core/pull/133.patch
- https://github.com/GrammaticalFramework/gf-core/pull/133.diff
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GrammaticalFramework/gf-core/pull/133, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYFSZG7LP2VFYPUI7NPEGDUDSHIJANCNFSM5EWEY4BQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Thank you! I might come back with further question as I make these changes but everything seems clear for now.
I'm not sure how to do the last thing.
I understand why I should use NewString
instead of NewStringUTF
, but I do not know how to get from let's say txt->text
to the corresponding string in the correct encoding.
If I am not mistaken, txt->text
is standard UTF-8 to be converted to UTF-16, and I assume conversion is similar to that in gu2j_string
. The thing is, I don't really understand how GuString
s and GuUCS
s work, which makes me unsure about how a hypothetical utf82j_string
should differ from gu2j_string
itself.
Push the code as it is and I can update it.
On Mon, 27 Sept 2021 at 15:48, Arianna Masciolini @.***> wrote:
I'm not sure how to do the last thing.
I understand why I should use NewString instead of NewStringUTF, but I do not know how to get from let's say txt->text to the corresponding string in the correct encoding.
If I am not mistaken, txt->text is standard UTF-8 to be converted to UTF-16, and I assume conversion is similar to that in gu2j_string. The thing is, I don't really understand how GuStrings and GuUCSs work, which makes me unsure about how a hypothetical utf82j_string should differ from gu2j_string itself.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GrammaticalFramework/gf-core/pull/133#issuecomment-927892871, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYFSZGHJVOPIHHAEJHUPBLUEBY3PANCNFSM5EWEY4BQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Question for @krangelov:
I'm working on some abstract syntax methods of the PGF
class, specifically getStartCat
and getCategories
, and looking at the old bindings I noticed that they return respectively a String
and a list of List<String>
.
Given that there is already a class Type
as part of the Java bindings, shouldn't these method return instead a Type
and a list of Type
s (like in Haskell and Python)?
To me, that seems only logical, but at the same time I imagine that there is a reason for having done otherwise and wanted to know what your thoughts are before breaking backwards compatibility.
Similarly, shouldn0t the input of getFunctionsByCat
be a Type
?
Probably when I added getStartCat, there wasn't a type for classes. Features in the Java binding were developed on demand. I think getStartCat should return Type.
getCategories should return strings just like getFunctions which also returns only function names.
On Thu, 30 Sept 2021 at 15:43, Arianna Masciolini @.***> wrote:
Question for @krangelov https://github.com/krangelov:
I'm working on some abstract syntax methods of the PGF class, specifically getStartCat and getCategories, and looking at the old bindings I noticed that they return respectively a String and a list of List
. Given that there is already a class Type as part of the Java bindings, shouldn't these method return instead a Type and a list of Types (like in Haskell and Python)? To me, that seems only logical, but at the same time I imagine that there is a reason for having done otherwise and wanted to know what your thoughts are before breaking backwards compatibility.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GrammaticalFramework/gf-core/pull/133#issuecomment-931335174, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYFSZEBAAWARKFRM3VXEELUERSOLANCNFSM5EWEY4BQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
On Thu, 30 Sept 2021 at 16:09, Arianna Masciolini @.***> wrote:
Similarly, shouldn0t the input of getFunctionsByCat be a Type?
No. getFunctionsByCat should take a string as input. If we filter by type then we must do type checking as well.
What do you mean? I see this in the master repository:
/** Returns the type of the function with the given name.
On Wed, 20 Oct 2021 at 12:37, Arianna Masciolini @.***> wrote:
Probably when I added getStartCat, there wasn't a type for classes. Features in the Java binding were developed on demand. I think getStartCat should return Type. getCategories should return strings just like getFunctions which also returns only function names.
Maybe getStartCat should also return a string after all. getFunctionType also returns a string instead of a Type, now that I look at it...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GrammaticalFramework/gf-core/pull/133#issuecomment-947541503, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYFSZCCPW3FTLB7NYPKKCDUH2LXBANCNFSM5EWEY4BQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Yes, sorry. I had mixed up two things, in fact I deleted the comment immediately, but you still got the email. On Oct 20 2021, at 2:14 pm, Krasimir Angelov @.***> wrote:
What do you mean? I see this in the master repository: /** Returns the type of the function with the given name.
- @param fun The name of the function. */ public native Type getFunctionType(String fun);
On Wed, 20 Oct 2021 at 12:37, Arianna Masciolini @.***> wrote:
Probably when I added getStartCat, there wasn't a type for classes. Features in the Java binding were developed on demand. I think getStartCat should return Type. getCategories should return strings just like getFunctions which also returns only function names.
Maybe getStartCat should also return a string after all. getFunctionType also returns a string instead of a Type, now that I look at it...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GrammaticalFramework/gf-core/pull/133#issuecomment-947541503, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYFSZCCPW3FTLB7NYPKKCDUH2LXBANCNFSM5EWEY4BQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub (https://github.com/GrammaticalFramework/gf-core/pull/133#issuecomment-947606169), or unsubscribe (https://github.com/notifications/unsubscribe-auth/AEJI3XYLCBJU7442H5MEPM3UH2XDZANCNFSM5EWEY4BQ).
I'm having issues implementing the marshaller. In particular, I'm working on match_type
.
I know that this makes the program crash, and initially I thought that the issue was related to casting the result of getObjectField
to jobjectArray
(or, in general, that it was an array problem), but that doesn't seem to be the case. In fact, I think the reason for the failure is that the fieldID
I pass to getObjectField
is NULL
, even though I don't understand why, and even though I thought that, with a null field id, GetObjectField
itself would fail in the first place.
I then also noticed that, similarly, trying to use the cat
field also causes the program to crash.
Therefore I think that the problem is not specific to any field of Type
objects, and I suspect it is somehow connected to the env
pointer, which I don't know if I'm using correctly.
To be honest, even if so far everything seems to work in the unmarshaller I'm in general unsure about what I should do with it in both marshalling and unmarshalling.
Can anyone help me with that?
In both cases, I see that there is a missing semicolon. It should be:
"[Lorg/grammaticalframework/pgf/Hypo;" "Ljava/lang/String;"
I think that is the reason.
In general if you get 0 from GetFieldID then you should return back to Java. Java will then show an exception which will hopefully clarify the issue.
On Tue, 26 Oct 2021 at 15:06, Arianna Masciolini @.***> wrote:
I'm having issues implementing the marshaller. In particular, I'm working on match_type.
I know that this https://github.com/harisont/gf-core/blob/0fdcce39fcc91ed9968e22d5c8a8873f7f9c8837/src/runtime/java/jpgf.c#L161 makes the program crash, and initially I thought that the issue was related to casting the result of getObjectField to jobjectArray https://github.com/harisont/gf-core/blob/0fdcce39fcc91ed9968e22d5c8a8873f7f9c8837/src/runtime/java/jpgf.c#L160 (or, in general, that it was an array problem), but that doesn't seem to be the case. In fact, I think the reason for the failure is that the fieldID I pass to getObjectField https://github.com/harisont/gf-core/blob/0fdcce39fcc91ed9968e22d5c8a8873f7f9c8837/src/runtime/java/jpgf.c#L159 is NULL, even though I don't understand why, and even though I thought that, with a null field id, GetObjectField itself would fail in the first place.
I then also noticed that, similarly, trying to use the cat field also causes the program to crash https://github.com/harisont/gf-core/blob/0fdcce39fcc91ed9968e22d5c8a8873f7f9c8837/src/runtime/java/jpgf.c#L168-L170 .
Therefore I think that the problem is not specific to any field of Type objects, and I suspect it is somehow connected to the env pointer, which I don't know if I'm using correctly. To be honest, even if so far everything seems to work in the unmarshaller I'm in general unsure about what I should do with it in both marshalling and unmarshalling.
Can anyone help me with that?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GrammaticalFramework/gf-core/pull/133#issuecomment-951919490, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYFSZADDUKPQ55V3TI4NE3UI2YU5ANCNFSM5EWEY4BQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Oh but of course! :facepalm: The example(s) in the JNI documentation had made me misunderstand what the semicolons'role in signatures is
I also missed the semicolon the first time when I used the JNI. Something in their documentation should be improved.
On Wed, 27 Oct 2021 at 10:07, Arianna Masciolini @.***> wrote:
Oh but of course! 🤦 The example(s) in the JNI documentation had made me misunderstand what the semicolons'role in signatures is
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GrammaticalFramework/gf-core/pull/133#issuecomment-952645851, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEYFSZBTZV5E4Z6PDADEXETUI66MJANCNFSM5EWEY4BQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Hi, I'm getting started with the Java bindings for the new runtime and so far it seems I got
readPGF(path)
andgetAbstractName
working.Even though this is still very little, I'm opening this pull request so that maybe @krangelov can tell me how I should go about in terms of memory management in what I already implemented, so that I can continue along those lines (I have not noticed any strange behavior so far, but I'd be surprised if there were no memory issues, I don't really have a clue about that, and especially not in the context of the JNI).