# Module argument to jl\_new\_datatype

**URL:** <https://discourse.julialang.org/t/module-argument-to-jl-new-datatype/4316>\
**Category:** Internals & Design\
**Tags:** embedding\
**Created:** [June 16, 2017, 8:52pm UTC](https://discourse.julialang.org/t/module-argument-to-jl-new-datatype/4316 "2017-06-16T20:52:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [June 16, 2017, 8:52pm UTC](https://discourse.julialang.org/t/module-argument-to-jl-new-datatype/4316/1 "2017-06-16T20:52:44Z")

</div>

The `jl_new_datatype` function appears to have gained a `module` argument since this commit:  
[https://github.com/JuliaLang/julia/commit/3c3ced4153cdc2c75319b41155c38ad1f2545fc2#diff-67021262df1246d0b5756f73b92eb69f](https://github.com/JuliaLang/julia/commit/3c3ced4153cdc2c75319b41155c38ad1f2545fc2#diff-67021262df1246d0b5756f73b92eb69f)

Does this module have to be the module where the type is defined? I’m asking this because in CxxWrap.jl types are added to a specific module using `jl_set_const`, but `jl_new_datatype` is called earlier, before the module exists.

CC @jameson

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [June 16, 2017, 9:52pm UTC](https://discourse.julialang.org/t/module-argument-to-jl-new-datatype/4316/2 "2017-06-16T21:52:48Z")

</div>

`jl_init_types` does something like that too. It’s supposed to be the new module, so that the method table and type name can set the module and compute a hash. But it’ll generally manage alright if you pass NULL and set it later.

---

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [June 19, 2017, 7:10am UTC](https://discourse.julialang.org/t/module-argument-to-jl-new-datatype/4316/3 "2017-06-19T07:10:46Z")

</div>

Thanks, I found the relevant code in init.c. I should be able to mimic this, but I’ll first see if I can adapt CxxWrap to supply the module from the start, since I don’t like hacking into the internals this much.
