comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: A simple DLM question

Re: A simple DLM question
type: item
description: On Monday, August 27, 2012 11:13:57 AM UTC-6, Xin Tao wrote: > Hi, > > > > I'm having trouble figuring out the problem of the following DLM code: > > > > /* The c routine */ > > > > void simple(int argc, IDL_VPTR argv[]) > > { > > IDL_VPTR v; > > > > v = IDL_BasicTypeConversion(1, &argv[0], IDL_TYP_DOUBLE); > > > > IDL_DELTMP(v); > > } > > > > This routine just takes its input and convert it to double. After converting it to a DLM, however, I seem to see strange results. > > > > IDL> simple, 1.0d > > % Loaded DLM: TESTMODULE. > > IDL> simple, -1.0d > > Bus error > > > > That is: if I give it 1.0d as input, then the code is fine. However, if I use -1.0d, then there is a BUS error, presumably from IDL_DELTMP(v). I really don't understand why this is the case. Isn't IDL_DELTMP supposed to decide first whether v is a temporary variable or not? If I remove IDL_DELTMP, of course, I'll frequently get the annoying warning message "% Temporary variables are still checked out - cleaning up...". > > > > Please give me some help. Thanks. Try this: if (v != argv[0]) IDL_DELTMP(v); That is, no conversion was necessary. The macro (in idl_export.h, if you're interested) doesn't do extensive checking, and you should only free variables that are temps, not expressions or constants.
creator: Jim Pendleton
date: 2012-08-27T20:48:26-00:00

Re: A simple DLM question
type: item
description: On Monday, August 27, 2012 1:13:57 PM UTC-4, Xin Tao wrote: ... > Please give me some help. Thanks. Your first problem is putting "Simple" and "DLM question" in the same sentence. :-)
creator: Craig Markwardt
date: 2012-08-27T20:51:10-00:00

Re: A simple DLM question
type: item
description: Thanks Jimmy. That indeed solved my problem. It was so confusing to me, because I found from the External Development Guide that IDL_DELTMP should check it first. :) On Monday, August 27, 2012 3:48:27 PM UTC-5, jimmylee...@gmail.com wrote: > On Monday, August 27, 2012 11:13:57 AM UTC-6, Xin Tao wrote: > >> Hi, > >> > >> > >> > >> I'm having trouble figuring out the problem of the following DLM code: > >> > >> > >> > >> /* The c routine */ > >> > >> > >> > >> void simple(int argc, IDL_VPTR argv[]) > >> > >> { > >> > >> IDL_VPTR v; > >> > >> > >> > >> v = IDL_BasicTypeConversion(1, &argv[0], IDL_TYP_DOUBLE); > >> > >> > >> > >> IDL_DELTMP(v); > >> > >> } > >> > >> > >> > >> This routine just takes its input and convert it to double. After converting it to a DLM, however, I seem to see strange results. > >> > >> > >> > >> IDL> simple, 1.0d > >> > >> % Loaded DLM: TESTMODULE. > >> > >> IDL> simple, -1.0d > >> > >> Bus error > >> > >> > >> > >> That is: if I give it 1.0d as input, then the code is fine. However, if I use -1.0d, then there is a BUS error, presumably from IDL_DELTMP(v). I really don't understand why this is the case. Isn't IDL_DELTMP supposed to decide first whether v is a temporary variable or not? If I remove IDL_DELTMP, of course, I'll frequently get the annoying warning message "% Temporary variables are still checked out - cleaning up...". > >> > >> > >> > >> Please give me some help. Thanks. > > > > Try this: > > > > if (v != argv[0]) IDL_DELTMP(v); > > > > That is, no conversion was necessary. > > > > The macro (in idl_export.h, if you're interested) doesn't do extensive checking, and you should only free variables that are temps, not expressions or constants.
creator: Xin Tao
date: 2012-08-27T22:04:43-00:00

Re: A simple DLM question
type: item
description: On Monday, August 27, 2012 3:51:10 PM UTC-5, Craig Markwardt wrote: > On Monday, August 27, 2012 1:13:57 PM UTC-4, Xin Tao wrote: > > ... > >> Please give me some help. Thanks. > > > > Your first problem is putting "Simple" and "DLM question" in the same sentence. :-) I've been learning DLM for a whole day, and I thought that would be a *simple* question for some experts. :)
creator: Xin Tao
date: 2012-08-27T22:08:27-00:00

Re: A simple DLM question
type: item
description: On Monday, August 27, 2012 4:04:43 PM UTC-6, Xin Tao wrote: > Thanks Jimmy. That indeed solved my problem. It was so confusing to me, because I found from the External Development Guide that IDL_DELTMP should check it first. :) > > > > On Monday, August 27, 2012 3:48:27 PM UTC-5, jimmylee...@gmail.com wrote: > >> On Monday, August 27, 2012 11:13:57 AM UTC-6, Xin Tao wrote: > >> > >>> Hi, > >> > >>> > >> > >>> > >> > >>> > >> > >>> I'm having trouble figuring out the problem of the following DLM code: > >> > >>> > >> > >>> > >> > >>> > >> > >>> /* The c routine */ > >> > >>> > >> > >>> > >> > >>> > >> > >>> void simple(int argc, IDL_VPTR argv[]) > >> > >>> > >> > >>> { > >> > >>> > >> > >>> IDL_VPTR v; > >> > >>> > >> > >>> > >> > >>> > >> > >>> v = IDL_BasicTypeConversion(1, &argv[0], IDL_TYP_DOUBLE); > >> > >>> > >> > >>> > >> > >>> > >> > >>> IDL_DELTMP(v); > >> > >>> > >> > >>> } > >> > >>> > >> > >>> > >> > >>> > >> > >>> This routine just takes its input and convert it to double. After converting it to a DLM, however, I seem to see strange results. > >> > >>> > >> > >>> > >> > >>> > >> > >>> IDL> simple, 1.0d > >> > >>> > >> > >>> % Loaded DLM: TESTMODULE. > >> > >>> > >> > >>> IDL> simple, -1.0d > >> > >>> > >> > >>> Bus error > >> > >>> > >> > >>> > >> > >>> > >> > >>> That is: if I give it 1.0d as input, then the code is fine. However, if I use -1.0d, then there is a BUS error, presumably from IDL_DELTMP(v). I really don't understand why this is the case. Isn't IDL_DELTMP supposed to decide first whether v is a temporary variable or not? If I remove IDL_DELTMP, of course, I'll frequently get the annoying warning message "% Temporary variables are still checked out - cleaning up...". > >> > >>> > >> > >>> > >> > >>> > >> > >>> Please give me some help. Thanks. > >> > >> > >> > >> Try this: > >> > >> > >> > >> if (v != argv[0]) IDL_DELTMP(v); > >> > >> > >> > >> That is, no conversion was necessary. > >> > >> > >> > >> The macro (in idl_export.h, if you're int…
creator: Jim Pendleton
date: 2012-08-28T16:06:44-00:00

Re: A simple DLM question
type: item
description: I did check the flags of IDL_V_CONST and IDL_V_TEMP. Both failed, and then I posted the question. For example, I'm not sure how to explain this results. // Code here. void simple(int argc, IDL_VPTR argv[]) { IDL_VPTR v; v = IDL_BasicTypeConversion(1, &argv[0], IDL_TYP_DOUBLE); printf("const = %d\n", v->flags & IDL_V_CONST); printf("temp = %d\n", v->flags & IDL_V_TEMP); if (v != argv[0]) IDL_DELTMP(v); } Now results: IDL> simple, 3.0d const = 1 temp = 0 IDL> simple, -3.0d const = 0 temp = 2 This sounds really strange to me. But if there is a good explanation of this, please let me know. Thanks. Xin Tao On Tuesday, August 28, 2012 11:06:44 AM UTC-5, jimmylee...@gmail.com wrote: > On Monday, August 27, 2012 4:04:43 PM UTC-6, Xin Tao wrote: > >> Thanks Jimmy. That indeed solved my problem. It was so confusing to me, because I found from the External Development Guide that IDL_DELTMP should check it first. :) > >> > >> > >> > >> On Monday, August 27, 2012 3:48:27 PM UTC-5, jimmylee...@gmail.com wrote: > >> > >>> On Monday, August 27, 2012 11:13:57 AM UTC-6, Xin Tao wrote: > >> > >>> > >> > >>>> Hi, > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> I'm having trouble figuring out the problem of the following DLM code: > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> /* The c routine */ > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> void simple(int argc, IDL_VPTR argv[]) > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> { > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> IDL_VPTR v; > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> v = IDL_BasicTypeConversion(1, &argv[0], IDL_TYP_DOUBLE); > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> IDL_DELTMP(v); > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> } > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >> > >>> > >> > >>>> > >…
creator: Xin Tao
date: 2012-08-28T21:16:53-00:00

Re: A simple DLM question
type: item
description: On Tuesday, August 28, 2012 5:16:53 PM UTC-4, Xin Tao wrote: > I did check the flags of IDL_V_CONST and IDL_V_TEMP. Both failed, and then I posted the question. For example, I'm not sure how to explain this results. > > > > // Code here. > > > > void simple(int argc, IDL_VPTR argv[]) > > { > > IDL_VPTR v; > > > > v = IDL_BasicTypeConversion(1, &argv[0], IDL_TYP_DOUBLE); > > > > printf("const = %d\n", v->flags & IDL_V_CONST); > > printf("temp = %d\n", v->flags & IDL_V_TEMP); > > > > if (v != argv[0]) IDL_DELTMP(v); > > } > > > > > > Now results: > > > > IDL> simple, 3.0d > > const = 1 > > temp = 0 > > IDL> simple, -3.0d > > const = 0 > > temp = 2 It is a little odd, but it may be the difference between 3.0d, a constant, and -(3.0d), which is an expression. But I'd think that IDL should be smart enough to parse -3.0d as a constant. Craig
creator: Craig Markwardt
date: 2012-08-29T01:10:17-00:00

Re: A simple DLM question
type: item
description: Maybe it's a bug! Anyway, Jimmy's trick did it, but I'm still confused by IDL's EDG. On Tuesday, August 28, 2012 8:10:17 PM UTC-5, Craig Markwardt wrote: > On Tuesday, August 28, 2012 5:16:53 PM UTC-4, Xin Tao wrote: > >> I did check the flags of IDL_V_CONST and IDL_V_TEMP. Both failed, and then I posted the question. For example, I'm not sure how to explain this results. > >> > >> > >> > >> // Code here. > >> > >> > >> > >> void simple(int argc, IDL_VPTR argv[]) > >> > >> { > >> > >> IDL_VPTR v; > >> > >> > >> > >> v = IDL_BasicTypeConversion(1, &argv[0], IDL_TYP_DOUBLE); > >> > >> > >> > >> printf("const = %d\n", v->flags & IDL_V_CONST); > >> > >> printf("temp = %d\n", v->flags & IDL_V_TEMP); > >> > >> > >> > >> if (v != argv[0]) IDL_DELTMP(v); > >> > >> } > >> > >> > >> > >> > >> > >> Now results: > >> > >> > >> > >> IDL> simple, 3.0d > >> > >> const = 1 > >> > >> temp = 0 > >> > >> IDL> simple, -3.0d > >> > >> const = 0 > >> > >> temp = 2 > > > > It is a little odd, but it may be the difference between 3.0d, a constant, and -(3.0d), which is an expression. But I'd think that IDL should be smart enough to parse -3.0d as a constant. > > > > Craig
creator: Xin Tao
date: 2012-08-29T05:03:27-00:00

Re: A simple DLM question
type: item
description: Hi all, Just to clarify, this isn't a bug. It just happens that since the minus sign is an operator, then a number such as -1 gets turned into an expression, which is stored in a temporary variable. It is treated the same way as say "-a" where "a" is a variable. Jimmy said "The macro (in idl_export.h, if you're interested) doesn't do extensive checking, and you should only free variables that are temps, not expressions or constants." That isn't quite correct. In this particular case, you *must* check (v != argv[0]), regardless of whether it is a constant or temp variable. That is because if the type conversion was not needed, then "v" will be equal to argv[0]. In this case, your code does not "own" argv[0] since it didn't allocate it. Freeing "v" is bad in that case, because IDL will attempt to free it later, and a double free will occur. Probably the best way to write the line of code is: if (v != argv[0]) IDL_Deltmp(v); Here, you don't need to use the macro, because you *know* that if "v" is not equal, then it must be a temporary that is owned by you, and you can free it without doing any further checks. Hope this helps. -Chris ExelisVIS
creator: chris_torrence@NOSPAM
date: 2012-08-29T15:55:28-00:00

Re: A simple DLM question
type: item
description: That's very clear explanation, thanks. But I would still say that it's not very intuitive to me that 3 is a constant but -3 is not. On Wednesday, August 29, 2012 10:55:28 AM UTC-5, Chris Torrence wrote: > Hi all, > > > > Just to clarify, this isn't a bug. It just happens that since the minus sign is an operator, then a number such as -1 gets turned into an expression, which is stored in a temporary variable. It is treated the same way as say "-a" where "a" is a variable. > > > > Jimmy said "The macro (in idl_export.h, if you're interested) doesn't do extensive checking, and you should only free variables that are temps, not expressions or constants." > > > > That isn't quite correct. In this particular case, you *must* check (v != argv[0]), regardless of whether it is a constant or temp variable. That is because if the type conversion was not needed, then "v" will be equal to argv[0]. In this case, your code does not "own" argv[0] since it didn't allocate it. Freeing "v" is bad in that case, because IDL will attempt to free it later, and a double free will occur. > > > > Probably the best way to write the line of code is: > > > > if (v != argv[0]) IDL_Deltmp(v); > > > > Here, you don't need to use the macro, because you *know* that if "v" is not equal, then it must be a temporary that is owned by you, and you can free it without doing any further checks. > > > > Hope this helps. > > > > -Chris > > ExelisVIS
creator: Xin Tao
date: 2012-08-29T16:23:51-00:00

Re: A simple DLM question
type: item
description: On Wednesday, August 29, 2012 6:23:51 PM UTC+2, Xin Tao wrote: > That's very clear explanation, thanks. But I would still say that it's not very intuitive to me that 3 is a constant but -3 is not. A '-' can be both unary (-3) and binary (a-3). Including the '-' in the constant would be erroneous in the binary case and you would get a syntax error. There is a similar feature (or bug?) in parsing the exponent of floating point literals. IDL accepts 1e- as a valid float number: IDL> help, 1e- <Expression> FLOAT = 1.00000 But this results in a syntax error for expressions like 1e-a: IDL> a=0 & help, 1e-a a=0 & help, 1e-a ^ % Syntax error. (I think 1e- should be invalid and 1e-a should be valid.) regards, Lajos
creator: Lajos Foldy
date: 2012-08-29T17:31:38-00:00

Re: A simple DLM question
type: item
description: On Wednesday, August 29, 2012 11:31:39 AM UTC-6, fawltyl...@gmail.com wrote: > > A '-' can be both unary (-3) and binary (a-3). Including the '-' in the constant would be erroneous in the binary case and you would get a syntax error. > > There is a similar feature (or bug?) in parsing the exponent of floating point literals. IDL accepts 1e- as a valid float number: > > IDL> help, 1e- > <Expression> FLOAT = 1.00000 > > But this results in a syntax error for expressions like 1e-a: > > IDL> a=0 & help, 1e-a > > a=0 & help, 1e-a > ^ > % Syntax error. > > (I think 1e- should be invalid and 1e-a should be valid.) > > regards, > Lajos This is the one that always drives me nuts: IDL> a = 3 IDL> help,1d+a % Syntax error. IDL> help,1d + a <Expression> DOUBLE = 4.0000000 What kind of crazy language requires spaces to work properly?! [Three cheers for whoever answers this question first! And IDL doesn't count...] -Chris
creator: chris_torrence@NOSPAM
date: 2012-08-29T17:50:33-00:00

Re: A simple DLM question
type: item
description: On 8/29/12 11:50 AM, Chris Torrence wrote: > On Wednesday, August 29, 2012 11:31:39 AM UTC-6, fawltyl...@gmail.com wrote: >> >> A '-' can be both unary (-3) and binary (a-3). Including the '-' in the constant would be erroneous in the binary case and you would get a syntax error. >> >> There is a similar feature (or bug?) in parsing the exponent of floating point literals. IDL accepts 1e- as a valid float number: >> >> IDL> help, 1e- >> <Expression> FLOAT = 1.00000 >> >> But this results in a syntax error for expressions like 1e-a: >> >> IDL> a=0 & help, 1e-a >> >> a=0 & help, 1e-a >> ^ >> % Syntax error. >> >> (I think 1e- should be invalid and 1e-a should be valid.) >> >> regards, >> Lajos > > This is the one that always drives me nuts: > IDL> a = 3 > IDL> help,1d+a > % Syntax error. > IDL> help,1d + a > <Expression> DOUBLE = 4.0000000 > > What kind of crazy language requires spaces to work properly?! > [Three cheers for whoever answers this question first! And IDL doesn't count...] > > -Chris Python! (Although you can use tabs as long as you are consistent.) Mike -- Michael Galloy www.michaelgalloy.com Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com) Research Mathematician Tech-X Corporation
creator: Michael Galloy
date: 2012-08-29T18:16:41-00:00