Skip to content
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

Provide %-primitives for operations on raw pointers #7252

Closed
vicuna opened this issue May 8, 2016 · 7 comments
Closed

Provide %-primitives for operations on raw pointers #7252

vicuna opened this issue May 8, 2016 · 7 comments

Comments

@vicuna
Copy link

vicuna commented May 8, 2016

Original bug ID: 7252
Reporter: dobenour
Status: acknowledged (set by @damiendoligez on 2016-11-08T10:54:20Z)
Resolution: open
Priority: normal
Severity: feature
Target version: later
Category: standard library

Bug description

I am writing an FFI module for OCaml and have noticed a lack of %-primitives to operate on raw pointers represented as nativeints

@vicuna
Copy link
Author

vicuna commented May 9, 2016

Comment author: @diml

dobenour, what operations are you thinking about? If your pointers are represented as [Nativeint.t] values, can't you use functions from the [Nativeint] module?

@vicuna
Copy link
Author

vicuna commented May 17, 2016

Comment author: dobenour

I am talking about operations that dereference the pointers. This could be achieved by the following C external (for machine words, with [@@unboxed]):

  CAMLprim intptr_t dereference_pointer8(intptr_t ptr) {
    return *(uint8_t*)ptr;
  }

but that would be very slow for what should be a single instruction.

Both versions that require alignment and do not require alignment should be provided.

@vicuna
Copy link
Author

vicuna commented Nov 11, 2016

Comment author: @xavierleroy

The return of PEEK and POKE... (https://en.wikipedia.org/wiki/PEEK_and_POKE)

I spent my computing life fleeing away from BASIC, either towards lower-level languages (C, assembly) where low-level stuff can be done properly, or towards higher-level languages (Pascal, Lisp, Caml, Coq) where all that low-level crap disappears. Because of that I feel sad when people insist on doing low-level crap in Caml.

@vicuna
Copy link
Author

vicuna commented Nov 12, 2016

Comment author: dobenour

The popularity of ctypes shows that people want to be able to interface with C using pure OCaml. That means pointers. Furthermore, Jane Street can use this feature (per a GPR), and I am certain that MirageOS can as well.

@vicuna
Copy link
Author

vicuna commented Nov 12, 2016

Comment author: dobenour

Can you explain why low-level work cannot be done in OCaml? C lacks a lot of features that OCaml has. Not all low-level code must run without allocation.

@mshinwell
Copy link
Contributor

We have discussed this before and I think it is clear that the proposals in their existing form are unsatisfactory.

@gasche
Copy link
Member

gasche commented Apr 17, 2020

Cross-link: this was proposed (and rejected) in #724.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants