Coder Social home page Coder Social logo

Comments (7)

starwing avatar starwing commented on June 8, 2024

You could try compiling proto file to .pb file (using the official protoc executable and -o flag) first.

Then, try use protoc.new(), it doesn't need global state.

Thirdly, try pb.state(). Use separate state in one thread.

Other parts of lua-protobuf do not modify global state.

from lua-protobuf.

ewmailing avatar ewmailing commented on June 8, 2024

Thank you for the response. I am confused by the relationship of protoc and pb because the APIs never directly connect to each other (e.g. protoc doesn't return any parameters that you pass to pb functions).

If I compile a proto file to .pb (e.g. protoc --descriptor_set_out MyFoo.pb MyFoo.proto), does that let me avoid needing to use protoc?

	local fh, err = io.open("MyFoo.pb", "rb")
	local file_data = fh:read("*all")
	local pb = require("pb")
	pb.load(file_data)

Is this what you were suggesting with your first sentence?
Then I wouldn't need to use protoc at all, right? And so I wouldn't need protoc.new(), right?

FYI, each LuaLane creates a new lua_State to run in. So each pb probably gets its own state already, so I don't think I need pb.state() in my case.

Thank you

from lua-protobuf.

starwing avatar starwing commented on June 8, 2024

If I compile a proto file to .pb (e.g. protoc --descriptor_set_out MyFoo.pb MyFoo.proto), does that let me avoid needing to use protoc?

Yes.

Is this what you were suggesting with your first sentence?
Then I wouldn't need to use protoc at all, right? And so I wouldn't need protoc.new(), right?

Yes.

FYI, each LuaLane creates a new lua_State to run in. So each pb probably gets its own state already, so I don't think I need pb.state() in my case.

Okk, that make sense.

from lua-protobuf.

ewmailing avatar ewmailing commented on June 8, 2024

I haven't gotten any crashes since I made the change to load the .pb and avoid protoc. 👍

I'm just curious, what happens if I pb.load the same descriptor multiple times in the same state? Is this harmless? Is there a reloading cost or does the system know it is already loaded and returns early?

from lua-protobuf.

ewmailing avatar ewmailing commented on June 8, 2024

I spoke too soon. My crashes came back :(

I was looking at the source code in pb.c. There is a global variable called global_state:

static const pb_State *global_state = NULL;

My current hunch is that this may be related to my crashes while using Lanes. I'm thinking I want to try changing this to not use a global variable, to see if it will make my crashes go away. Can you give me any hints on what is involved to change this?

Thanks

from lua-protobuf.

starwing avatar starwing commented on June 8, 2024

this global just used in pb.state() routines, you could delete it (and relate codes) and see whether it works.

from lua-protobuf.

ewmailing avatar ewmailing commented on June 8, 2024

My crashes disappeared for a couple of weeks, but just came back.
I tried deleting global_state (and related code), but it didn't fix the problem. So that was a red herring for me.
So now, I think my problem might be caused by something unrelated (I hate threading bugs). But I think this part of lua-protobuf is fine and not the problem. Thanks for your help and time.

from lua-protobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.