Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

fix(parity-clib): grumbles that were not addressed in #9920 #10154

Merged
merged 5 commits into from
Feb 11, 2019

Conversation

niklasad1
Copy link
Collaborator

This PR introduces the following:

  • remove a couple of needless unsafe functions
  • some style nits
  • eliminate repetitive event loops for lib and java (introduces a trait Callback to pass instead of the concrete type)

@niklasad1 niklasad1 added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Jan 8, 2019
@niklasad1 niklasad1 changed the title parity-clib: fix grumbles that were not addressed in #9920 fix(parity-clib): grumbles that were not addressed in #9920 Jan 8, 2019
@5chdn 5chdn added this to the 2.3 milestone Jan 9, 2019
parity-clib/src/java.rs Outdated Show resolved Hide resolved
parity-clib/src/java.rs Outdated Show resolved Hide resolved
@5chdn 5chdn modified the milestones: 2.3, 2.4 Jan 10, 2019
@sorpaas sorpaas added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 11, 2019
@5chdn 5chdn requested review from tomaka and ordian February 7, 2019 11:41
@5chdn
Copy link
Contributor

5chdn commented Feb 7, 2019

Needs a 2nd review

parity-clib/src/lib.rs Outdated Show resolved Hide resolved
unsafe impl<'a> Sync for Callback<'a> {}
impl<'a> Callback<'a> {
unsafe impl<'a> Send for JavaCallback<'a> {}
unsafe impl<'a> Sync for JavaCallback<'a> {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't introduced by this PR, but could you explain why it's safe for GlobalRef?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean. Can you elaborate a bit?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant why is it safe to impl Sync and Send for JavaCallback?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good question I have to admit I'm not completely sure (I more or less copy-pasted it from the lib.rs) but I argue that JavaVM and GlobalRef is never mutated and the Java code is thread-safe!

Also both JavaVM GlobalRef have unsafe Send + Sync impls but an inner-type GlobalRefGuard doesn't with the unsafe impls I get the following error:

53 | impl<'a> Callback for JavaCallback<'a> {
   |          ^^^^^^^^ `*mut jni::sys::_jobject` cannot be shared between threads safely
   |
   = help: within `jni::objects::global_ref::GlobalRefGuard`, the trait `std::marker::Sync` is not implemented for `*mut jni::sys::_jobject`
   = note: required because it appears within the type `jni::objects::JObject<'static>`
   = note: required because it appears within the type `jni::objects::global_ref::GlobalRefGuard`
   = note: required because of the requirements on the impl of `std::marker::Sync` for `std::sync::Arc<jni::objects::global_ref::GlobalRefGuard>`
   = note: required because it appears within the type `jni::objects::GlobalRef`
   = note: required because it appears within the type `java::JavaCallback<'a>`

Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I asked, is because the docs for GlobalRef 0.10.2 showed

impl !Sync for GlobalRef 

It seems like Sync was added later (jni-rs/jni-rs#145), and the implementation hasn't changed for GlobalRef.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks good point let’s ask them to bump the version so we can get rid of the unsafe part then :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @DarkEld3r

parity-clib/src/lib.rs Show resolved Hide resolved
parity-clib/src/java.rs Show resolved Hide resolved
unsafe impl<'a> Sync for Callback<'a> {}
impl<'a> Callback<'a> {
unsafe impl<'a> Send for JavaCallback<'a> {}
unsafe impl<'a> Sync for JavaCallback<'a> {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I asked, is because the docs for GlobalRef 0.10.2 showed

impl !Sync for GlobalRef 

It seems like Sync was added later (jni-rs/jni-rs#145), and the implementation hasn't changed for GlobalRef.

@5chdn 5chdn merged commit c84e574 into master Feb 11, 2019
@5chdn 5chdn deleted the parity-clib/grumbles branch February 11, 2019 14:27
ordian added a commit that referenced this pull request Apr 5, 2019
* master:
  no volumes are needed, just run -v volume:/path/in/the/container (#10345)
  Fixed misstype (#10351)
  snap: prefix version and populate candidate channel (#10343)
  Bundle protocol and packet_id together in chain sync (#10315)
  role back docker build image and docker deploy image to ubuntu:xenial based (#10338)
  change docker image based on debian instead of ubuntu due to the chan… (#10336)
  Don't add discovery initiators to the node table (#10305)
  fix(docker): fix not receives SIGINT (#10059)
  snap: official image / test (#10168)
  fix(add helper for timestamp overflows) (#10330)
  Additional error for invalid gas (#10327)
  Revive parity_setMinGasPrice RPC call (#10294)
  Add Statetest support for Constantinople Fix (#10323)
  fix(parity-clib): grumbles that were not addressed in #9920 (#10154)
  fix(light-rpc): Make `light_sync` generic (#10238)
  fix publish job (#10317)
  Secure WS-RPC: grant access to all apis (#10246)
  Make specification of protocol in SyncRequester::send_request explicit (#10295)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants