Closed
Bug 560002
Opened 14 years ago
Closed 14 years ago
Opaque struct and definition support in ctypes
Categories
(Core :: js-ctypes, defect)
Core
js-ctypes
Tracking
()
RESOLVED
FIXED
People
(Reporter: dwitte, Assigned: dwitte)
References
Details
(Keywords: dev-doc-complete, Whiteboard: fixed-in-tracemonkey)
Attachments
(2 files)
29.97 KB,
patch
|
mozilla+ben
:
review+
|
Details | Diff | Splinter Review |
25.03 KB,
patch
|
mozilla+ben
:
review+
|
Details | Diff | Splinter Review |
On 04/16/2010 12:35 PM, Daniel Witte wrote:
On Fri, Apr 16, 2010 at 10:23 AM, Eric Shepherd<eshepherd@mozilla.com> wrote:
If I have two declarations that need to be able to reference each other
circularly using pointers, is there a way to define that without resorting
to using a voidptr_t in the one declared first? This may be more of a
general JavaScript question than a ctypes-specific one. :)
Sadly, no. In C, a forward-declaration of a struct will get replaced
by the full definition when it's provided. In ctypes, the first
declaration must be opaque (as with C) but then remains that way.
jorendorff: maybe we could solve this by allowing opaque structs, and
making them mutable to a fully declared flavor? Like so:
let opaque = ctypes.StructType("opaque");
let struct1 = ctypes.StructType("struct1", [ { a : opaque.ptr } ]);
opaque.redeclare([ { b: struct1.ptr } ]);
(Note that I want to implement opaque structs anyway.)
Yes. Python's ctypes supports something similar, via assigning to _fields_, but a method is better.
Opaque structs are called "incomplete types", or (especially in C++) "declared" but not "defined". So maybe opaque.complete() or opaque.define()?
Assignee | ||
Comment 1•14 years ago
|
||
Adds a 't.define()' function to StructTypes, and refactors the resulting code.
Assignee | ||
Comment 2•14 years ago
|
||
Kills off 'ctypes.PointerType("foo")'.
Attachment #440392 -
Flags: review?(bnewman)
Updated•14 years ago
|
Keywords: dev-doc-needed
Comment 3•14 years ago
|
||
Comment on attachment 440390 [details] [diff] [review]
part 1: opaque structs
>@@ -2481,18 +2501,17 @@ CType::ConstructBasic(JSContext* cx,
> JSObject*
> CType::Create(JSContext* cx,
> JSObject* typeProto,
> JSObject* dataProto,
> TypeCode type,
> JSString* name,
> jsval size,
> jsval align,
>- ffi_type* ffiType,
>- PropertySpec* ps)
>+ ffi_type* ffiType)
Now that you're passing in the ffi_type*, it seems you could avoid passing in the size, and use ffiType->size (when defined) instead.
Comment 4•14 years ago
|
||
Comment on attachment 440392 [details] [diff] [review]
part 2: remove opaque pointers
Looks good.
Attachment #440392 -
Flags: review?(mozilla+ben) → review+
Comment 5•14 years ago
|
||
Comment on attachment 440390 [details] [diff] [review]
part 1: opaque structs
Sorry for letting this sit for so long.
Attachment #440390 -
Flags: review?(mozilla+ben) → review+
Assignee | ||
Comment 6•14 years ago
|
||
Comment on attachment 440390 [details] [diff] [review]
part 1: opaque structs
http://hg.mozilla.org/tracemonkey/rev/6303a12e08fd
Assignee | ||
Comment 7•14 years ago
|
||
Comment on attachment 440392 [details] [diff] [review]
part 2: remove opaque pointers
http://hg.mozilla.org/tracemonkey/rev/b041894a2ff3
Assignee | ||
Updated•14 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Whiteboard: fixed-in-tracemonkey
You need to log in
before you can comment on or make changes to this bug.
Description
•