Pointer ofNull method naming
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Nov 14 00:01:36 UTC 2019
Sorry, still not getting what you are trying to say. Let's pop back; you
have this function:
int foo(Pointer<Pointer<Byte>> array, Pointer<Integer> size);
Can you please explain what this function is expected to do? What are
the inputs and what are the outputs? How is 'size' connected 'array'?
What is that 'int' return value?
I vaguely understand (from your previous emails) that the 'array' is
expected to have a certain encoding where first element is 'size' (of
what?) then you have some element bitmasks. But it's not clear whether
the 'array' is provided as input by the user, or is expected to be
filled by the function (same for 'size').
Maurizio
On 13/11/2019 23:01, Ty Young wrote:
>
> On 11/13/19 4:28 PM, Maurizio Cimadamore wrote:
>>
>> On 13/11/2019 22:15, Ty Young wrote:
>>>
>>> On 11/13/19 3:19 PM, Maurizio Cimadamore wrote:
>>>>
>>>> On 13/11/2019 12:43, Ty Young wrote:
>>>>>
>>>>> On 11/13/19 2:28 AM, Maurizio Cimadamore wrote:
>>>>>> I'm ok with making the documentation more precise (I'm not sure I
>>>>>> like ofTyped()). Can you please clarify a bit what you mean by
>>>>>> 'filler' ? Like passing null ptr to a struct setter?
>>>>>
>>>>>
>>>>> Not struct types but more primitive native types like
>>>>> Pointer<Byte> or Pointer<Integer>.
>>>>>
>>>>>
>>>>> As an example, you have a function like this:
>>>>>
>>>>>
>>>>> int foo(Pointer<Pointer<Byte>> array, Pointer<Integer> size);
>>>>>
>>>>>
>>>>> But what you're actually interested in is at index 0 of the array,
>>>>> so "size" isn't needed and allocating a new Pointer would be a waste.
>>>>
>>>> Not sure I follow - if you are interested in index 0, doesn't that
>>>> mean that the array would need to have at least _one_ element (e.g.
>>>> size >= 1) ?
>>>
>>>
>>> It does. It's just that the data that is actually desired is located
>>> at index 0, so doing:
>>>
>>>
>>> array.get().get()
>>>
>>>
>>> returns index 0 anyway.
>>>
>>>
>>> For context, the function in question returns a Pointer to an array
>>> in the format:
>>>
>>>
>>> Index 0 = number of items
>>>
>>> index 4 * number of item = bitmask of a given item
>>
>> Really confused by this example - if the size is always at position 0
>> of the array, then what is the second argument Pointer<Integer> used
>> for?
>
>
> "size" is the amount of something connected to the system, not the
> Pointer<Integer> size.
>
>
> So the bitmask of item 1 is located at index 4, item 2 at 8, etc. in
> the array.
>
>
>>
>> I'm trying to understand whether this is really a 'new' use for
>> Pointer.ofNull, or whether you are just exploiting the fact that the
>> underlying function you are using happens to work even if the second
>> parameter is null.
>
>
> It does exploit the lack of null checks *technically* although you
> could just as easily lazily allocate a non null Pointer of the desired
> type to do the same thing. Would providing something like that be out
> of API scope?
>
>
> Although, it's never explained(nor have I tried it) whether a Pointer
> allocated from a different scope can be used in another one so maybe
> that isn't even possible? If it is, then what's the point of Scope
> class anyway?
>
>
>> in other words, I'm having problems understand what you mean by this
>> 'filler' capability of Pointer.ofNull.
>
>
> The function requires a pointer be passed even if you aren't
> interested in what's inside that pointer after calling the function,
> therefor it's "filler".
>
>
>>
>> Maurizio
>>
>>>
>>>
>>> However, one might only be interested in index 0 or in this case,
>>> the number of items, so allocating another Pointer just to make the
>>> function call seems like a waste.
>>>
>>>
>>> It seems like *some* functions check whether a given Pointer is null
>>> or not but not all do such as the functions I'm working with. It
>>> just fills the array Pointer regardless.
>>>
>>>
>>>>
>>>> Maurizio
>>>>
>>>>
>>>>>
>>>>>
>>>>>>
>>>>>> (p.s. in these cases we have been also discussing bringing back
>>>>>> special treatment for Java null, so that null is re-interpreted
>>>>>> to Pointer.ofNull)
>>>>>
>>>>>
>>>>> I haven't gone too deep down the rabbit hole, but I see
>>>>> "LayoutTypeImpl.nullType" in BoundedPointer. Isn't that the null
>>>>> interpretation for a Pointer?
>>>>>
>>>>>
>>>>>
>>>>>>
>>>>>> Maurizio
>>>>>>
More information about the panama-dev
mailing list