Giter VIP home page Giter VIP logo

Comments (4)

PengZheng avatar PengZheng commented on June 30, 2024

Is text pre-allocatable? I guess not, since the caller can not predict how long a string will be.

The current implementation of jsonRpc_handleReply is confusing in this regard.

			if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
				void *tmp = NULL;
				void **out = (void **) args[i];
				size_t size = 0;

                if (dynType_descriptorType(argType) == 't') {
					status = jsonSerializer_deserializeJson(argType, result, &tmp);
					if (tmp != NULL) {
						size = strnlen(((char *) *(char**) tmp), 1024 * 1024);
						memcpy(*out, *(void**) tmp, size);
					}
				} else {
					dynType_typedPointer_getTypedType(argType, &argType);
					status = jsonSerializer_deserializeJson(argType, result, &tmp);
					if (tmp != NULL) {
						size = dynType_size(argType);
						memcpy(*out, tmp, size);
					}
				}

How could the caller of the remote method to know the resulting strnlen so that he/she can allocate buffer large enough?

I feel that the precise definitions of these types are needed at the moment to have a solid RSA implementation. @pnoltes

from celix.

PengZheng avatar PengZheng commented on June 30, 2024

I try to give the following definitions:

Standard argument should be serializable. All types except types involving untyped pointer or double pointer (pointer to pointer) are serializable. For example, complex types consisting of non-pointer fields are serializable while complex type containing a untyped pointer field is not serializable; [I is serializable while [P and [**D are not serializable.

am=out parameter should be pointer to text or double pointer to serializable types.

am=pre parameter should be pointer to trivially copyable type. It's safe to apply memcpy rivially copyable type without the usual danger of shallow copy. However, this definition is only meant to make the following code work:

			if (meta == DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT) {
				void *tmp = NULL;
				void **out = (void **) args[i];
				size_t size = 0;

 
			dynType_typedPointer_getTypedType(argType, &argType);
			status = jsonSerializer_deserializeJson(argType, result, &tmp);
			if (tmp != NULL) {
				size = dynType_size(argType);
				memcpy(*out, tmp, size);
			}
		        dynType_free(argType, tmp);
				

By this definition, [D can not be used as am=pre, because dynType_free(argType, tmp) will free the embedded buffer, which has been copied to *out (thus lead to use-after-free). I think the main usage of SequenceType is to be used as pre-allocated output paramter and let the callee to fill in actual content. Thus this definition will make SequenceType useless.

Any ideas to make am=pre work? @pnoltes

The above reflects my understanding of the current code base, which may deviate from the original intention. Please shed light on this, any help will be appreciated.

PS: Maybe SequenceType does not qualify as am=pre, because it is essentially a inout parameter (currently unsupported), whose capacity must be serialized and sent to the provider end.

from celix.

pnoltes avatar pnoltes commented on June 30, 2024

Sorry for the late reaction.

Any ideas to make am=pre work? @pnoltes

The above reflects my understanding of the current code base, which may deviate from the original intention. Please shed light on this, any help will be appreciated.

My original idea for the am=pre was to support primitive types (double, bool, ec) and indeed trivially trivially copyable type.
I agree that this should be made more explicit and the parse of dfi can test if the am=pre argument fits the requirements. If needed this can be extended in the future.

So IMO no am=pre support for pointer in structs, double pointers, strings or sequences.

from celix.

pnoltes avatar pnoltes commented on June 30, 2024

Is like the dynType_isPreallocatable approach :)

from celix.

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.