[Vm-dev] VM Maker: VMMaker-dtl.432.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Jan 17 23:39:15 UTC 2022


David T. Lewis uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker-dtl.432.mcz

==================== Summary ====================

Name: VMMaker-dtl.432
Author: dtl
Time: 17 January 2022, 6:29:43.114 pm
UUID: 89fa5bee-431a-474e-96da-dd7640dd7227
Ancestors: VMMaker-dtl.431

Clean up type declarations in RePlugin, motivated by Debian package quality checker. Adopt Eliot's changes from oscog, then fix declarations for pcrePtr and extraPtr. Remove type casts that are no longer needed. No compiler warnings on gcc now.

=============== Diff against VMMaker-dtl.431 ===============

Item was changed:
  ----- Method: RePlugin class>>declareCVarsIn: (in category 'plugin code generation') -----
  declareCVarsIn: cg
  
  	cg addHeaderFile:'"rePlugin.h"'.
  
  	"Memory Management Error Checking"
  	cg var: 'netMemory' 	declareC: 'int netMemory = 0'.
+ 	cg var: 'numAllocs' 		declareC: 'int numAllocs = 0'.
- 	cg var: 'numAllocs' 	declareC: 'int numAllocs = 0'.
  	cg var: 'numFrees' 		declareC: 'int numFrees = 0'.
  	cg var: 'lastAlloc'		declareC: 'int lastAlloc = 0'.
  
  	"Support Variables for Access to Receiver Instance Variables"
+ 	cg var: 'patternStrPtr'	type: 'const char *'.
+ 	cg var: 'errorStrBuffer'	type: 'const char *'.
+ 	cg var: 'errorOffset'	type: 'int'.
+ 	cg var: 'pcrePtr' 		type: 'pcre *'.
+ 	cg var: 'extraPtr'		type: 'pcre_extra *'.!
- 	cg var: 'patternStrPtr' type: 'const char * '.
- 	cg var: 'errorStrBuffer'	type: 'const char * '.!

Item was changed:
  ----- Method: RePlugin>>allocateByteArrayAndSetRcvrExtraPtrFrom: (in category 'rcvr linkage') -----
  allocateByteArrayAndSetRcvrExtraPtrFrom: anExtraPtr
  
  	| extraObject extraByteArrayPtr |
+ 	<var: #anExtraPtr type: 'pcre_extra *'>
  	<var: #extraByteArrayPtr type: 'void *'>
  
  	anExtraPtr
  		ifFalse: [extraObject := interpreterProxy nilObject]
  		ifTrue: [
  			"Allocate a Smalltalk ByteArray -- lastAlloc contains the length"
  			extraObject := interpreterProxy
  						instantiateClass: (interpreterProxy classByteArray) 
  						indexableSize: (self cCode: 'sizeof(real_pcre_extra)').
  			self loadRcvrFromStackAt: 0. "Assume garbage collection after instantiation"
  
  			"Copy from the C bytecode buffer to the Smalltalk ByteArray"
  			extraByteArrayPtr := interpreterProxy arrayValueOf: extraObject.	
+ 			self cCode:'memcpy(extraByteArrayPtr, anExtraPtr, sizeof(real_pcre_extra))'].
- 			self cCode:'memcpy(extraByteArrayPtr, (void *) anExtraPtr, sizeof(real_pcre_extra))'].
   
  	"Set rcvrErrorStr from errorStr and Return"
  	self rcvrExtraPtrFrom: extraObject.
  	self touch: extraByteArrayPtr.	
  	^extraObject.
  !

Item was changed:
  ----- Method: RePlugin>>allocateByteArrayAndSetRcvrPCREPtrFromPCRE: (in category 'rcvr linkage') -----
  allocateByteArrayAndSetRcvrPCREPtrFromPCRE: aPCREPtr
  
  	| patObject patByteArrayPtr |
+ 	<var: #aPCREPtr type: 'pcre *'>
  	<var: #patByteArrayPtr type: 'void *'>
  
  	"Allocate a Smalltalk ByteArray -- lastAlloc contains the length"
  	patObject := interpreterProxy
  				instantiateClass: (interpreterProxy classByteArray) 
  				indexableSize: lastAlloc.
  	self loadRcvrFromStackAt: 0. "Assume garbage collection after instantiation"
  
  	"Copy from the C bytecode buffer to the Smalltalk ByteArray"
  	patByteArrayPtr := interpreterProxy arrayValueOf: patObject.	
+ 	self cCode:'memcpy(patByteArrayPtr, aPCREPtr, lastAlloc)'.
- 	self cCode:'memcpy(patByteArrayPtr, (void *) aPCREPtr, lastAlloc)'.
   
  	"Set rcvrErrorStr from errorStr and Return"
  	self rcvrPCREBufferFrom: patObject.
  	self touch: patByteArrayPtr.	
  	^patObject.
  !

Item was changed:
  ----- Method: RePlugin>>primPCRECompile (in category 're primitives') -----
  primPCRECompile
  
  "<rcvr primPCRECompile>, where rcvr is an object with instance variables:
  
  	'patternStr compileFlags pcrePtr extraPtr errorStr errorOffset matchFlags'	
  
  Compile the regular expression in patternStr, and if the compilation is successful, attempt to optimize the compiled expression.  Store the results in <pcrePtr> and <extratr>, or fill errorStr with a meaningful errorString and errorOffset with an indicator where the error was found, applying compileFlags throughout.  Answer nil with a clean compile (regardless of whether an optimization is possible, and answer with the string otherwise."
  
  
  	<export: true>
  	self loadRcvrFromStackAt: 0.
  	patternStrPtr := self rcvrPatternStrPtr.
  	compileFlags := self rcvrCompileFlags.
  	interpreterProxy failed ifTrue:[^ nil].
  
+ 	pcrePtr := self cCode: 'pcre_compile(patternStrPtr, compileFlags, &errorStrBuffer, &errorOffset, NULL)'.
- 	pcrePtr := self cCode: '(int) pcre_compile(patternStrPtr, compileFlags, 
- 					&errorStrBuffer, &errorOffset, NULL)'.
  	pcrePtr
  		ifTrue: [
  			self allocateByteArrayAndSetRcvrPCREPtrFromPCRE: pcrePtr.
+ 			extraPtr := self cCode: 'pcre_study(pcrePtr, compileFlags, &errorStrBuffer)'.
- 			extraPtr := self cCode: '(int) pcre_study((pcre *)pcrePtr, compileFlags, &errorStrBuffer)'.
  			self allocateByteArrayAndSetRcvrExtraPtrFrom: extraPtr.
+ 			self rePluginFree: pcrePtr.
+ 			extraPtr ifTrue: [self rePluginFree: extraPtr asVoidPointer].
- 			self rePluginFree: (self cCoerce: pcrePtr to: 'void *').
- 			extraPtr ifTrue: [self rePluginFree: (self cCoerce: extraPtr to: 'void *')].
  			interpreterProxy failed ifTrue:[^ nil].
  			interpreterProxy pop: 1 thenPush: interpreterProxy nilObject]
  		ifFalse: [
  			errorStr := self allocateStringAndSetRcvrErrorStrFromCStr: errorStrBuffer.
  			self rcvrErrorOffsetFrom: errorOffset.
  			interpreterProxy failed ifTrue:[^ nil].
  			interpreterProxy pop: 1 thenPush: errorStr].!

Item was changed:
  ----- Method: RePlugin>>primPCREExec (in category 're primitives') -----
  primPCREExec
  
  "<rcvr primPCREExec: searchObject>, where rcvr is an object with instance variables:
  
  	'patternStr compileFlags pcrePtr extraPtr errorStr errorOffset matchFlags'	
  
  Apply the regular expression (stored in <pcrePtr> and <extratr>, generated from calls to primPCRECompile), to smalltalk String searchObject using <matchOptions>.  If there is no match, answer nil.  Otherwise answer a ByteArray of offsets representing the results of the match."
  
  	| searchObject searchBuffer length  result matchSpacePtr matchSpaceSize |
  	<export: true>
  	<var:#searchBuffer	type: 'char *'>
  	<var:#matchSpacePtr	type: 'int *'>
  	
  	"Load Parameters"
  	searchObject := interpreterProxy stackObjectValue: 0.	
  	searchBuffer := interpreterProxy arrayValueOf: searchObject.
  	length := interpreterProxy byteSizeOf: searchObject.
  	self loadRcvrFromStackAt: 1.
  	"Load Instance Variables"
  	pcrePtr := self rcvrPCREBufferPtr.
  	extraPtr := self rcvrExtraPtr.
  	matchFlags := self rcvrMatchFlags.
  	matchSpacePtr := self rcvrMatchSpacePtr.
  	matchSpaceSize := self rcvrMatchSpaceSize.
  
  	interpreterProxy failed ifTrue:[^ nil].
  	
  	result := self 
+ 		cCode: 'pcre_exec(pcrePtr, extraPtr, 
- 		cCode: 'pcre_exec((pcre *)pcrePtr, (pcre_extra *)extraPtr, 
  				searchBuffer, length, 0, matchFlags, matchSpacePtr, matchSpaceSize)'.
  
  	interpreterProxy pop: 2; pushInteger: result.
  
  	"empty call so compiler doesn't bug me about variables not used"
  	self touch: searchBuffer; touch: matchSpacePtr; touch: matchSpaceSize; touch: length
  !

Item was changed:
  ----- Method: RePlugin>>primPCREExecfromto (in category 're primitives') -----
  primPCREExecfromto
  
  "<rcvr primPCREExec: searchObject from: fromInteger to: toInteger>, where rcvr is an object with instance variables:
  
  	'patternStr compileFlags pcrePtr extraPtr errorStr errorOffset matchFlags'	
  
  Apply the regular expression (stored in <pcrePtr> and <extratr>, generated from calls to primPCRECompile), to smalltalk String searchObject using <matchOptions>, beginning at offset <fromInteger> and continuing until offset <toInteger>.  If there is no match, answer nil.  Otherwise answer a ByteArray of offsets representing the results of the match."
  
  	| searchObject searchBuffer length  result matchSpacePtr matchSpaceSize fromInteger toInteger |
  	<export: true>
  	<var:#searchBuffer	type: 'char *'>
  	<var:#matchSpacePtr	type: 'int *'>
  	
  	"Load Parameters"
  	toInteger := interpreterProxy stackIntegerValue: 0.
  	fromInteger := interpreterProxy stackIntegerValue: 1.
  	searchObject := interpreterProxy stackObjectValue: 2.	
  	searchBuffer := interpreterProxy arrayValueOf: searchObject.
  	length := interpreterProxy byteSizeOf: searchObject.
  	self loadRcvrFromStackAt: 3.
  
  	"Validate parameters"
  	interpreterProxy success: (1 <= fromInteger).
  	interpreterProxy success: (toInteger<=length).
  	fromInteger := fromInteger - 1. "Smalltalk offsets are 1-based"
  	interpreterProxy success: (fromInteger<=toInteger).
  
  	"adjust length, searchBuffer"
  	length := toInteger - fromInteger.
  	searchBuffer := searchBuffer + fromInteger.
  
  	"Load Instance Variables"
  	pcrePtr := self rcvrPCREBufferPtr.
  	extraPtr := self rcvrExtraPtr.
  	matchFlags := self rcvrMatchFlags.
  	matchSpacePtr := self rcvrMatchSpacePtr.
  	matchSpaceSize := self rcvrMatchSpaceSize.
  	interpreterProxy failed ifTrue:[^ nil].
  	
  	result := self 
+ 		cCode: 'pcre_exec(pcrePtr, extraPtr, 
- 		cCode: 'pcre_exec((pcre *)pcrePtr, (pcre_extra *)extraPtr, 
  				searchBuffer, length, 0, matchFlags, matchSpacePtr, matchSpaceSize)'.
  	interpreterProxy pop: 4; pushInteger: result.
  
  	"empty call so compiler doesn't bug me about variables not used"
  	self touch: searchBuffer; touch: matchSpacePtr; touch: matchSpaceSize; touch: length
  !

Item was changed:
  ----- Method: RePlugin>>primPCRENumSubPatterns (in category 're primitives') -----
  primPCRENumSubPatterns
  
  "<rcvr primPCRENumSubPatterns>, where rcvr is an object with instance variables:
  
  	'patternStr compileFlags pcrePtr extraPtr errorStr errorOffset matchFlags'	
  
  Return the number of subpatterns captured by the compiled pattern."
  
  	<export: true>
  	| ncap |
  	"Load Parameters"
  	self loadRcvrFromStackAt: 0.
  	"Load Instance Variables"
  	pcrePtr := self rcvrPCREBufferPtr.
+ 	self cCode: 'pcre_fullinfo(pcrePtr, NULL, PCRE_INFO_CAPTURECOUNT, &ncap)'
- 	self cCode: 'pcre_fullinfo((const pcre *)pcrePtr, NULL, PCRE_INFO_CAPTURECOUNT, &ncap)'
  		inSmalltalk: [ncap := -1].
  	interpreterProxy pop: 1; pushInteger: ncap.
  !

Item was changed:
  ----- Method: RePlugin>>rcvrExtraPtr (in category 'rcvr linkage') -----
  rcvrExtraPtr
  
  	|extraObj|
  	<inline: true>
+ 	<returnTypeC: 'pcre_extra'>
  	extraObj := interpreterProxy fetchPointer: 3 ofObject: rcvr.
  	^self 
  		cCoerce: (extraObj = interpreterProxy nilObject
  					ifTrue: [nil]
  					ifFalse: [interpreterProxy arrayValueOf: extraObj])
+ 		to: 'pcre_extra *'!
- 		to: 'int'!

Item was changed:
  ----- Method: RePlugin>>rcvrPCREBufferPtr (in category 'rcvr linkage') -----
  rcvrPCREBufferPtr
- 
  	<inline: true>
+ 	<returnTypeC: 'pcre *'>
  	^self
  		cCoerce: (interpreterProxy fetchArray: 2 ofObject: rcvr)
+ 		to: 'pcre *'!
- 		to: 'int'.!

Item was changed:
  ----- Method: VMMaker class>>versionString (in category 'version testing') -----
  versionString
  
  	"VMMaker versionString"
  
+ 	^'4.19.13'!
- 	^'4.19.12'!



More information about the Vm-dev mailing list