-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update GMT_IS_REFERENCE and GMT_IS_DUPLICATE to allow duplicating strings #3718
Conversation
Hm. Let's see. So in effect, the default is GMT_IS_REFERENCE. If we wanted to have a different behavior (GMT_IS_DUPLICATE) then we would need a way to say so. If we know that the pointer passed in is an array of char* pointers then we can do the duplication inside since we know the number of rows = number of strings. So the options are:
So it is a bit problematic. If this was just a C API that other people used then I could just change the values assigned to GMT_IS_REFERENCE and GMT_IS_DUPLICATE. I need @joa-quim to comment on that. I don't like the idea that Julia would dictate what we can do in the C API. The whole point of using named constants is to avoid having to change a hardwired 4 to 40 down the road since the code only uses the named constant. If I understand how @joa-quim builds Julia he started with a version of gmt_resources.h some time ago and it is not recreated from a changing gmt source. For PyGMT, @leouieda made me add the GMT_Get_Enum function so you could pass the name and get the value; ideally Julia could do the same. So let's wait until tomorrow to see what we can do here. |
I can use |
Just so we understand: Your Julia code is using the constants like GMT_IS_DUPLICATE, GMT_IS DATASET, etc and their values are fixed values. if so, presumably adding GMT_DUP_STRINGS wont hurt anything. |
Adding a new enum won't hurt anything. Only if it changes old functionality. But you can change the GMT_IS_REFERENCE value. |
How about the GMT_IS_DUPLICATE value? That would be ideal since having to add another enum with the same meaning is not good style. But in general, I think you need to consider a strategy where you do not impose conditions on such changes in the GMT API. At the very least, there should be some versioning since changing the number assigned to an enum or constant is not considered breaking backwards compatibility. I understand it does in fact affect the Julia implementation but that is an issue with that implementation and not the C API, no? You could, for example, import all those enums via GMT_Get_Enum in your startup. |
I don't use GMT_IS_DUPLICATE. I try to use the minimum enums as possible. I told you, it's not easy to import the enums. I can only use |
I mean, GMT.jl version X requires GMT version Y. It should not aim to work with all possible GMT versions.
OK I see, so you really need a process that runs script makeJL and it builds the porting of gmt_resources.h etc from the C. I think you said you did something like that but not final so took lots of manual edits after that, which is why you don't like to do this again. But perhaps we can help with coming up with such a solution? |
I intend to drop GMT5 support soon, but I think not supporting 6.X is a killing feature. Recreating the the wrapper functions is a complex operation. It involves installing a package that depends on LLVM that scans lots of headers and creates wrappers to lots of functions. Than those must be cleaned. No way I want to repeat this process without absolute need. |
And can't currently trust in
|
These values also can't be accessed in PyGMT, but others like |
It's because these enums are not included in |
yes looks like it. Weill have a look after last morning swim before impending hurricane... Note that it is likely there will be power-outages in Hawaii and the GMT server will go down at some point. |
GMT_Put_Strings only worked by reference. Now, we can accept a family argument such as GMT_IS_VECTOR|GMT_IS_DUPLICATE (or GMT_IS_REFERENCE which is the default) and it will duplicate the array string if requested.
Hi @seisman, I think this ought to work but I am unable to run tests with the gmtserver down (they are looking into it as no power outage yet). Since I changed the values of GMT_IS_DUPLICATE and GMT_IS_REFERENCE we need to run the tests to see if I forgot some case. It seems the only issues was the use of these are array indices into GMT_method for debug print statements so I changed that. The rest of the use of GMT_IS_DUPLICATE should be fine. There are more use of GMT_IS_REFERENCE in modules so need to run all tests to know. Oh, and I did not actually run your C code... |
I manually ran the |
You mean in the test C program? I think the argument should be GMT_IS_VECTOR|GMT_IS_DUPLICATE, no? E.g.,
|
You're right. The PR looks good, but I didn't run the full test, due to the server down. Just two more questions:
|
Good questions, so:
Given all that, it may possibly be cleaner to add three more functions:
unless we are to add |GMT_IS_DUPLICATE to the type argument in GMT_Put_Vector |
I could define DUP and REF as 16 and 32 and then you could pass GMT_DOUBLE|GMT_IS_DUPLICATE to Put_Vector and we could do the duplication. Perhaps that is an OK solution as well? |
Forgot to answer the failiure re GMT_IS_REFERENCE. If by failure you mean the same as the first plots then yes, if you pass by reference and then remote the information it will fail by design. So I am thinking it may make more sense to pass by REF and not free what you created temporarily anyways since you are just forcing the duplication to happen again anyway. |
I add
I'm not sure if it's necessary. At least it works well from the PyGMT side, most likely because the Python numeric arrays are not freed, but string arrays are.
It's up to you. I can test it from the PyGMT side, but as mentioned above, |
Sorry, did not think of the text call. Good one, I can see why now. I will fix this separately outside this branch. |
I will adjust the values of DUP and REF so that there is room to enhance GMT_Put_* if we feel like it. |
yes, taht is a good idea. Please give it a spin, @joa-quim so we dont break anything. This PR changed the values of GMT_IS_REFERENCE|DUPLICATE and fixed some issues that surfaced because if it. |
Also backport this PR to 6.1? Some PyGMT features needs this PR, and we don't want to wait for the 6.2.0 release. |
I am sorry I click that button too fast - one more time, please!
On July 28, 2020 at 7:25:02 PM, Dongdong Tian ([email protected]) wrote:
Also backport this PR to 6.1? Some PyGMT features needs this PR, and we
don't want to wait for the 6.2.0 release.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3718 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGJ7IX472KSSPP524VW7T6DR56XC3ANCNFSM4PGLMGIQ>
.
|
Do you mean backporting PR #3735? I'm talking about this branch. |
I meant this branch put-strings. |
"backport 6.1" label added. FYI, we can even add the label after a PR is merged. |
Tested GMT.jl and no problems. |
but the MEX
From the mastar branch the above crashes Matlab as it also crashes Julia. The problem seem to be that the returned grids is junk. |
Just to be clear, you tested GMT.jl and no problems, but then you discovered the above example which crashes on both MEX and Julia, yes? |
Right. |
Thanks, will have a look. Also time for me to remind @joa-quim and @seisman about Debugging. It would be nice to have information there for how to debug GMT when called from Julia, MEX, and PyGMT, for 3 platforms. IF we want people to help find bugs then we need more people to actually step into the code. The biggest problem is setting up a working GUI debugging system. I can add stuff for debugging MEX on macos, for instance, but I do not know how for Julia and PyGMT. Since one uses Xcode on macOS I think it is possibly to do the same for Julia and Python but have not tried. |
Good but hard on the brain to debug this. We end up in grdblend of course, writing a grid back to grdcut who writes the grid back to gmtmex. So the actual grid is passed up via two modules. Unfortunately, looks like the original object does not release ownership so at the last minute we wipe that grid which is the same pointer taht we pass back to mex, so it is NULL there... |
So I have the solution to this, @seisman and @seisman . When we call the gmt_assemble_grid function inside GMT_Read_Data, we already have an object container (API->object[ID]) to hold the grid to be read. But then gmt_assemble_grid also creates its own container via GMT_Open_VirtualFile. Once we get the grid we actually need to delete that VirtualFile (and its container) since we are done. Otherwise it lives on in the API object list and causes trouble like above. I can do this in a few different ways:
We would have to backport to 6.1 for the above command to work in 6.1.1. Maybe option 2 is good enough for now? No point making a full API function that other developers will never use, no? |
Option 2 sounds good to me. |
Yes, 2 seems the best for now. |
OK separate PR coming up, with backport, that is independent of the put-strings branch. |
Yes, looks good to me. Since I opened this PR, I can't approve myself. |
…ings (#3718) * Debug GMT_Put_Strings * SHift GMT_IS_DUPLICATE,REFERENCE and allow for string duplication GMT_Put_Strings only worked by reference. Now, we can accept a family argument such as GMT_IS_VECTOR|GMT_IS_DUPLICATE (or GMT_IS_REFERENCE which is the default) and it will duplicate the array string if requested. * Adjust these enums to allow future use in GMT_Put_Vector|Matrix * Update gmt_enum_dict.h * Possible clash with GMT_VIA_MODULE_INPUT * Update gmt_enum_dict.h * Update gmt_enum_dict.h and testapi_vector_strings2.c * Update api.rst * Update gmt_api.c * Update gmt_api.c * Add debug messages * check for directory * Update gmt_io.c Co-authored-by: Paul Wessel <[email protected]>
…ings (#3718) (#3777) * Debug GMT_Put_Strings * SHift GMT_IS_DUPLICATE,REFERENCE and allow for string duplication GMT_Put_Strings only worked by reference. Now, we can accept a family argument such as GMT_IS_VECTOR|GMT_IS_DUPLICATE (or GMT_IS_REFERENCE which is the default) and it will duplicate the array string if requested. * Adjust these enums to allow future use in GMT_Put_Vector|Matrix * Update gmt_enum_dict.h * Possible clash with GMT_VIA_MODULE_INPUT * Update gmt_enum_dict.h * Update gmt_enum_dict.h and testapi_vector_strings2.c * Update api.rst * Update gmt_api.c * Update gmt_api.c * Add debug messages * check for directory * Update gmt_io.c Co-authored-by: Paul Wessel <[email protected]> Co-authored-by: Dongdong Tian <[email protected]> Co-authored-by: Paul Wessel <[email protected]>
Description of proposed changes
The C code
src/testapi_vector_strings2.c
is modified from the testsrc/testapi_vector_strings.c
.The two C codes are very similar, except that in
src/testapi_vector_strings2.c
:strings
are dynamically allocated usingmalloc
(line 28)GMT_Put_Strings
(line 45).Running the C code gives me:
If the string array are not freed (i.e., comment out lines 44-46), I can get the correct result:
@PaulWessel Is it the expected behaviour or a GMT bug?